@@ -90,10 +90,39 @@ chmod 775 *.sh bin/*
9090echo " Upgrade complete."
9191echo " 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
99128fi
0 commit comments