Skip to content

Commit f2576b2

Browse files
committed
Satellite Install/Upgrade: Redesign Linux install/upgrade scripts to be first-class systemd citizens.
1 parent 53ec3a8 commit f2576b2

2 files changed

Lines changed: 54 additions & 5 deletions

File tree

internal/sat-install.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,24 @@ chmod 775 *.sh bin/*
8282
./bin/node main.js install
8383

8484
# start satellite in background
85-
./bin/node main.js start
85+
# Prefer systemd when present so systemctl keeps accurate state.
86+
USE_SYSTEMD=0
87+
if command -v systemctl >/dev/null 2>&1; then
88+
# Avoid false-positives (e.g. systemctl installed but systemd isn't PID 1)
89+
if [ -d /run/systemd/system ]; then
90+
# Ask systemd first; fall back to unit-file existence checks.
91+
if systemctl list-unit-files 2>/dev/null | grep -q '^xysat\.service'; then
92+
USE_SYSTEMD=1
93+
elif [ -f /etc/systemd/system/xysat.service ] || [ -f /lib/systemd/system/xysat.service ] || [ -f /usr/lib/systemd/system/xysat.service ]; then
94+
USE_SYSTEMD=1
95+
fi
96+
fi
97+
fi
98+
99+
if [ "$USE_SYSTEMD" -eq 1 ]; then
100+
echo "Linux systemd detected -- starting xySat via systemctl..."
101+
systemctl start xysat.service
102+
else
103+
echo "Starting xySat service..."
104+
./bin/node main.js start
105+
fi

internal/sat-upgrade.sh

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,39 @@ chmod 775 *.sh bin/*
9090
echo "Upgrade complete."
9191
echo "Restarting service."
9292

93-
# Stop running service
94-
./bin/node main.js stop
93+
# If running in a container / foreground mode, stop ONLY and exit.
94+
if [ -n "${SATELLITE_foreground+x}" ]; then
95+
echo "SATELLITE_foreground is set -- stopping service only."
96+
./bin/node main.js stop
97+
exit 0
98+
fi
99+
100+
# Prefer systemd when present so systemctl keeps accurate state.
101+
USE_SYSTEMD=0
102+
if command -v systemctl >/dev/null 2>&1 && command -v systemd-run >/dev/null 2>&1; then
103+
# Avoid false-positives (e.g. systemctl installed but systemd isn't PID 1)
104+
if [ -d /run/systemd/system ]; then
105+
# Ask systemd first; fall back to unit-file existence checks.
106+
if systemctl list-unit-files 2>/dev/null | grep -q '^xysat\.service'; then
107+
USE_SYSTEMD=1
108+
elif [ -f /etc/systemd/system/xysat.service ] || [ -f /lib/systemd/system/xysat.service ] || [ -f /usr/lib/systemd/system/xysat.service ]; then
109+
USE_SYSTEMD=1
110+
fi
111+
fi
112+
fi
95113

96-
# start satellite in background
97-
if [ -z "${SATELLITE_foreground+x}" ]; then
114+
if [ "$USE_SYSTEMD" -eq 1 ]; then
115+
echo "Linux systemd detected -- restarting via systemctl."
116+
if systemctl is-active --quiet xysat.service 2>/dev/null; then
117+
echo "xySat is active under systemd -- restarting via systemd-run handoff."
118+
systemd-run --quiet --collect --unit=xysat-upgrade-restart --property=StandardOutput=append:"$LOG_FILE" --property=StandardError=append:"$LOG_FILE" /bin/sh -c '/bin/systemctl restart xysat.service'
119+
exit 0;
120+
fi
121+
echo "xySat is NOT active under systemd -- stopping manually, then starting under systemd."
122+
./bin/node main.js stop
123+
systemctl start xysat.service
124+
else
125+
echo "Linux systemd not detected -- restarting via direct commands."
126+
./bin/node main.js stop
98127
./bin/node main.js start
99128
fi

0 commit comments

Comments
 (0)