Skip to content

Commit 861c49d

Browse files
committed
chore: replace graphql server
1 parent 38a6f0c commit 861c49d

10 files changed

Lines changed: 199 additions & 144 deletions

File tree

api/src/unraid-api/unraid-file-modifier/modifications/__test__/snapshots/rc.nginx.modified.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ build_locations(){
420420
location /graphql {
421421
allow all;
422422
error_log /dev/null crit;
423-
proxy_pass http://unix:/var/run/unraid-api.sock:/graphql;
423+
proxy_pass http://unix:/var/run/unraid-core.sock:/graphql;
424424
proxy_http_version 1.1;
425425
proxy_set_header Host $host;
426426
proxy_set_header Upgrade $http_upgrade;

api/src/unraid-api/unraid-file-modifier/modifications/patches/rc-nginx.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ Index: /etc/rc.d/rc.nginx
4444
T=' '
4545
if check && [[ $1 == lo ]]; then
4646
if [[ $IPV4 == yes ]]; then
47+
@@ -400,11 +418,11 @@
48+
# my servers proxy
49+
#
50+
location /graphql {
51+
allow all;
52+
error_log /dev/null crit;
53+
- proxy_pass http://unix:/var/run/unraid-api.sock:/graphql;
54+
+ proxy_pass http://unix:/var/run/unraid-core.sock:/graphql;
55+
proxy_http_version 1.1;
56+
proxy_set_header Host $host;
57+
proxy_set_header Upgrade $http_upgrade;
58+
proxy_set_header Connection $connection_upgrade;
59+
proxy_cache_bypass $http_upgrade;
4760
@@ -566,11 +584,11 @@
4861
# extract common name from cert
4962
CERTNAME=$(openssl x509 -noout -subject -nameopt multiline -in $CERTPATH | sed -n 's/ *commonName *= //p')

api/src/unraid-api/unraid-file-modifier/modifications/rc-nginx.modification.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ check_remote_access(){
6868
`if [[ -L /usr/local/sbin/unraid-api ]] && check_remote_access; then`
6969
);
7070

71+
newContent = newContent.replace(
72+
'proxy_pass http://unix:/var/run/unraid-api.sock:/graphql;',
73+
'proxy_pass http://unix:/var/run/unraid-core.sock:/graphql;'
74+
);
75+
7176
newContent = newContent.replace(
7277
'for NET in ${!NET_FQDN6[@]}; do',
7378
'for NET in "${!NET_FQDN6[@]}"; do'
@@ -91,7 +96,7 @@ check_remote_access(){
9196
}
9297

9398
async shouldApply(): Promise<ShouldApplyWithReason> {
94-
const { shouldApply, reason } = await super.shouldApply();
99+
const { shouldApply, reason } = await super.shouldApply({ checkOsVersion: false });
95100
return {
96101
shouldApply,
97102
reason,

plugin/plugins/dynamix.unraid.net.plg

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
<!ENTITY txz_sha256 "">
1010
<!ENTITY txz_url "">
1111
<!ENTITY txz_name "">
12+
<!ENTITY core_source "/boot/config/plugins/dynamix.my.servers/&core_txz_name;">
13+
<!ENTITY core_txz_sha256 "1c1dc2dc6b94f44e33ee4208d98f533184fc248e0a29e8693aa01be4abf86bdd">
14+
<!ENTITY core_txz_url "https://pub-7247242eea6d482488594f04a3d7d4be.r2.dev/unraid-0.1.0-2026.01.14.1.txz">
15+
<!ENTITY core_txz_name "unraid-0.1.0-2026.01.14.1.txz">
1216
<!ENTITY arch "x86_64">
1317
<!ENTITY build "1">
1418
<!ENTITY tag "">
@@ -52,6 +56,12 @@ exit 0
5256
<SHA256>&txz_sha256;</SHA256>
5357
</FILE>
5458

59+
<!-- download unraid core txz -->
60+
<FILE Name="&core_source;">
61+
<URL>&core_txz_url;</URL>
62+
<SHA256>&core_txz_sha256;</SHA256>
63+
</FILE>
64+
5565
<!-- Check for compatible Unraid version -->
5666
<FILE Run="/usr/bin/php" Method="install">
5767
<INLINE>
@@ -320,6 +330,21 @@ exit 0
320330
fi
321331
fi
322332
333+
# Stop and remove Unraid Core package
334+
if [ -x "/etc/rc.d/rc.unraid" ]; then
335+
echo "Stopping Unraid Core..."
336+
/etc/rc.d/rc.unraid stop || echo "Warning: Failed to stop Unraid Core"
337+
fi
338+
339+
core_pkg_installed=$(ls -1 /var/log/packages/unraid-* 2>/dev/null | head -1)
340+
if [ -n "$core_pkg_installed" ]; then
341+
core_pkg_basename=$(basename "$core_pkg_installed")
342+
echo "Removing core package: $core_pkg_basename"
343+
removepkg --terse "$core_pkg_basename"
344+
else
345+
echo "No Unraid Core package found"
346+
fi
347+
323348
# File restoration function
324349
echo "Restoring files..."
325350
@@ -404,6 +429,9 @@ exit 0
404429
PKG_FILE="&source;" # Full path to the package file including .txz extension
405430
PKG_URL="&txz_url;" # URL where package was downloaded from
406431
PKG_NAME="&txz_name;" # Name of the package file
432+
CORE_PKG_FILE="&core_source;"
433+
CORE_PKG_URL="&core_txz_url;"
434+
CORE_PKG_NAME="&core_txz_name;"
407435
CONNECT_API_VERSION="&api_version;" # Version of API included with Connect
408436
<![CDATA[
409437
# Function to compare version numbers using PHP's version_compare
@@ -524,6 +552,37 @@ else
524552
echo "Connect plugin remains installed but API was not modified"
525553
fi
526554
555+
# Install Unraid Core package
556+
if [ -f "$CORE_PKG_FILE" ]; then
557+
echo "Installing Unraid Core package..."
558+
# Clean up any old core package txz files if they don't match our current version
559+
for txz_file in /boot/config/plugins/dynamix.my.servers/unraid-*.txz; do
560+
if [ -f "$txz_file" ] && [ "$txz_file" != "${CORE_PKG_FILE}" ]; then
561+
echo "Removing old core package file: $txz_file"
562+
rm -f "$txz_file"
563+
fi
564+
done
565+
566+
# Stop the core service before mutating /usr/local/unraid
567+
if [ -x "/etc/rc.d/rc.unraid" ]; then
568+
echo "Stopping Unraid Core service before upgrade..."
569+
/etc/rc.d/rc.unraid stop || echo "Warning: Failed to stop Unraid Core service"
570+
fi
571+
572+
upgradepkg --install-new --reinstall "${CORE_PKG_FILE}"
573+
if [ $? -ne 0 ]; then
574+
echo "⚠️ Core package installation failed"
575+
exit 1
576+
fi
577+
578+
if [ -f "/etc/rc.d/rc.unraid" ]; then
579+
chmod +x /etc/rc.d/rc.unraid
580+
fi
581+
else
582+
echo "⚠️ Core package file not found: $CORE_PKG_FILE"
583+
exit 1
584+
fi
585+
527586
exit 0
528587
]]>
529588
</INLINE>
@@ -599,6 +658,13 @@ echo "If no additional messages appear within 30 seconds, it is safe to refresh
599658
/etc/rc.d/rc.unraid-api start
600659
601660
echo "Unraid API service started"
661+
if [ -x "/etc/rc.d/rc.unraid" ]; then
662+
echo "Starting Unraid Core service"
663+
/etc/rc.d/rc.unraid start
664+
echo "Unraid Core service started"
665+
else
666+
echo "Warning: rc.unraid not found; core service not started"
667+
fi
602668
echo "✅ Installation is complete, it is safe to close this window"
603669
echo
604670
exit 0
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
# /etc/rc.d/rc.unraid
3+
# Unraid Phoenix Application Service
4+
5+
APP_DIR="/usr/local/unraid"
6+
RELEASE_BIN="$APP_DIR/_build/prod/rel/unraid/bin/unraid"
7+
CONFIG_DIR="/boot/config/unraid"
8+
SOCKET_PATH="/var/run/unraid-core.sock"
9+
LOG_PATH="${UNRAID_LOG_PATH:-/var/log/unraid-core.log}"
10+
11+
# Load user env if exists
12+
[ -f "$CONFIG_DIR/env" ] && source "$CONFIG_DIR/env"
13+
14+
# Ensure config and log directories exist
15+
mkdir -p "$CONFIG_DIR"
16+
mkdir -p "$(dirname "$LOG_PATH")"
17+
touch "$LOG_PATH"
18+
19+
# Generate secret_key_base if not exists
20+
if [ ! -f "$CONFIG_DIR/secret_key_base" ]; then
21+
head -c 64 /dev/urandom | base64 | tr -d '\n' > "$CONFIG_DIR/secret_key_base"
22+
chmod 600 "$CONFIG_DIR/secret_key_base"
23+
fi
24+
25+
export SECRET_KEY_BASE=$(cat "$CONFIG_DIR/secret_key_base")
26+
export RELEASE_COOKIE=$(cat "$CONFIG_DIR/secret_key_base" | head -c 20)
27+
export UNRAID_CONFIG_DIR="$CONFIG_DIR"
28+
export RUN_ERL_LOG="${RUN_ERL_LOG:-$LOG_PATH}"
29+
export RELEASE_LOG_DIR="${RELEASE_LOG_DIR:-$(dirname "$LOG_PATH")}"
30+
export RELEASE_NODE="${UNRAID_RELEASE_NODE:-unraid}"
31+
export RELEASE_DISTRIBUTION="${UNRAID_RELEASE_DISTRIBUTION:-sname}"
32+
33+
# Import user's runtime.exs if exists
34+
[ -f "$CONFIG_DIR/runtime.exs" ] && export RELEASE_CONFIG_DIR="$CONFIG_DIR"
35+
36+
# Socket/port configuration
37+
if [ -n "${UNRAID_PORT:-}" ]; then
38+
export PHX_PORT="$UNRAID_PORT"
39+
else
40+
export PHX_SOCKET="${UNRAID_SOCKET:-$SOCKET_PATH}"
41+
fi
42+
43+
start() {
44+
echo -n "Starting Unraid... "
45+
[ -S "$SOCKET_PATH" ] && rm -f "$SOCKET_PATH"
46+
"$RELEASE_BIN" daemon
47+
echo "done"
48+
}
49+
50+
stop() {
51+
echo -n "Stopping Unraid... "
52+
"$RELEASE_BIN" stop 2>/dev/null || true
53+
[ -S "$SOCKET_PATH" ] && rm -f "$SOCKET_PATH"
54+
echo "done"
55+
}
56+
57+
restart() {
58+
stop
59+
sleep 2
60+
start
61+
}
62+
63+
status() {
64+
"$RELEASE_BIN" pid >/dev/null 2>&1 && echo "Running" || echo "Stopped"
65+
}
66+
67+
rollback() {
68+
if [ -d "/usr/local/unraid.prev" ]; then
69+
echo "Rolling back to previous version..."
70+
stop
71+
rm -rf /usr/local/unraid
72+
mv /usr/local/unraid.prev /usr/local/unraid
73+
start
74+
echo "Rollback complete"
75+
else
76+
echo "No previous version available"
77+
exit 1
78+
fi
79+
}
80+
81+
case "${1:-}" in
82+
start) start ;;
83+
stop) stop ;;
84+
restart) restart ;;
85+
status) status ;;
86+
rollback) rollback ;;
87+
*) echo "Usage: $0 {start|stop|restart|status|rollback}" ;;
88+
esac
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
# Stop Unraid Core on shutdown/reboot
3+
4+
if [ -x /etc/rc.d/rc.unraid ]; then
5+
echo "Stopping Unraid Core..."
6+
/etc/rc.d/rc.unraid stop
7+
fi

plugin/source/dynamix.unraid.net/install/doinst.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ backup_file_if_exists() {
66
fi
77
}
88

9-
for f in etc/rc.d/rc6.d/K*unraid-api etc/rc.d/rc6.d/K*flash-backup; do
9+
for f in etc/rc.d/rc6.d/K*unraid-api etc/rc.d/rc6.d/K*unraid-core etc/rc.d/rc6.d/K*flash-backup; do
1010
[ -e "$f" ] && chmod 755 "$f"
1111
done
1212

plugin/source/dynamix.unraid.net/usr/local/share/dynamix.unraid.net/install/scripts/verify_install.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ echo "Performing comprehensive installation verification..."
4242
# Define critical files to check (POSIX-compliant, no arrays)
4343
CRITICAL_FILES="/usr/local/bin/unraid-api
4444
/etc/rc.d/rc.unraid-api
45+
/etc/rc.d/rc.unraid
4546
/usr/local/emhttp/plugins/dynamix.my.servers/scripts/gitflash_log"
4647

4748
# Define critical directories to check (POSIX-compliant, no arrays)
4849
CRITICAL_DIRS="/usr/local/unraid-api
50+
/usr/local/unraid
4951
/var/log/unraid-api
5052
/usr/local/emhttp/plugins/dynamix.my.servers
5153
/usr/local/emhttp/plugins/dynamix.unraid.net
@@ -159,6 +161,14 @@ else
159161
SHUTDOWN_ERRORS=$((SHUTDOWN_ERRORS + 1))
160162
fi
161163

164+
# Check for unraid-core shutdown script
165+
if [ -x "/etc/rc.d/rc6.d/K30unraid-core" ]; then
166+
printf '✓ Shutdown script for unraid-core exists and is executable\n'
167+
else
168+
printf '✗ Shutdown script for unraid-core missing or not executable\n'
169+
SHUTDOWN_ERRORS=$((SHUTDOWN_ERRORS + 1))
170+
fi
171+
162172
# Check for rc0.d symlink or directory
163173
if [ -L "/etc/rc.d/rc0.d" ]; then
164174
printf '✓ rc0.d symlink exists\n'
@@ -206,4 +216,4 @@ else
206216
echo "Please review the errors above and contact support if needed."
207217
# We don't exit with error as this is just a verification script
208218
exit 0
209-
fi
219+
fi

0 commit comments

Comments
 (0)