Systemd Detectiion in Start/Stop/Status

This commit is contained in:
John Haverlack 2026-02-04 19:52:45 -09:00
parent b84f4475e0
commit ee3b315a98
8 changed files with 170 additions and 68 deletions

View File

@ -53,6 +53,16 @@ resolve_dirs() {
done
}
use_systemd() {
# Check if systemd user mode is available and service exists
if systemctl --user status >/dev/null 2>&1; then
# Check if our service file exists
if systemctl --user list-unit-files | grep -q "^sdl-mgr.service"; then
return 0 # Use systemd
fi
fi
return 1 # Use manual scripts
}
# ------------------------------------------------------------
# Main

View File

View File

@ -2,6 +2,17 @@
# start-sdl-mgr.sh - Script to start SDL Manager
set -euo pipefail
use_systemd() {
# Check if systemd user mode is available and service exists
if systemctl --user status >/dev/null 2>&1; then
# Check if our service file exists
if systemctl --user list-unit-files | grep -q "^sdl-mgr.service"; then
return 0 # Use systemd
fi
fi
return 1 # Use manual scripts
}
# Get $SDL_HOME directory from SCRIPT PATH
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SDL_HOME="$(cd "$SCRIPT_DIR/.." && pwd)"
@ -48,5 +59,9 @@ echo " Node: ${NODE_BIN}"
export PATH="${NODE_BIN_DIR}:${PATH}"
cd "${SDL_MGR_APP_DIR}"
# Start in foreground
if use_systemd; then
systemctl --user start sdl-mgr
else
# Manual background start logic
"${NPM_BIN}" start &
fi

View File

@ -2,6 +2,20 @@
# status-sdl-mgr.sh - Script to show status of SDL Manager
set -euo pipefail
use_systemd() {
# Check if systemd user mode is available and service exists
if systemctl --user status >/dev/null 2>&1; then
# Check if our service file exists
if systemctl --user list-unit-files | grep -q "^sdl-mgr.service"; then
return 0 # Use systemd
fi
fi
return 1 # Use manual scripts
}
if use_systemd; then
systemctl --user status sdl-mgr
else
# Get sdl-mgr PID
SDL_MGR_PID=""
for pid in $(pgrep -f 'node' 2>/dev/null || true); do
@ -19,3 +33,4 @@ fi
echo "SDL Manager is running with PID: ${SDL_MGR_PID}"
exit 0
fi

View File

@ -2,6 +2,17 @@
# stop-sdl-mgr.sh - Script to stop SDL Manager
set -euo pipefail
use_systemd() {
# Check if systemd user mode is available and service exists
if systemctl --user status >/dev/null 2>&1; then
# Check if our service file exists
if systemctl --user list-unit-files | grep -q "^sdl-mgr.service"; then
return 0 # Use systemd
fi
fi
return 1 # Use manual scripts
}
# Get sdl-mgr PID
SDL_MGR_PID=""
for pid in $(pgrep -f 'node' 2>/dev/null || true); do
@ -19,6 +30,10 @@ fi
echo "Stopping SDL Manager (PID: ${SDL_MGR_PID})..."
if use_systemd; then
systemctl --user stop sdl-mgr
else
# Manual PID-based stop logic
# Send SIGTERM for graceful shutdown
kill "$SDL_MGR_PID"
@ -42,5 +57,6 @@ if kill -0 "$SDL_MGR_PID" 2>/dev/null; then
exit 1
fi
fi
fi
echo "SDL Manager stopped"

View File

@ -2,6 +2,17 @@
# start-sdl-wkr.sh - Script to start SDL Worker
set -euo pipefail
use_systemd() {
# Check if systemd user mode is available and service exists
if systemctl --user status >/dev/null 2>&1; then
# Check if our service file exists
if systemctl --user list-unit-files | grep -q "^sdl-mgr.service"; then
return 0 # Use systemd
fi
fi
return 1 # Use manual scripts
}
# Get $SDL_HOME directory from SCRIPT PATH
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SDL_HOME="$(cd "$SCRIPT_DIR/.." && pwd)"
@ -47,5 +58,9 @@ echo " Node: ${NODE_BIN}"
export PATH="${NODE_BIN_DIR}:${PATH}"
cd "${SDL_WKR_APP_DIR}"
# Start in foreground (use nohup or systemd for background)
exec "${NPM_BIN}" start
if use_systemd; then
systemctl --user start sdl-wkr
else
# Manual background start logic
"${NPM_BIN}" start &
fi

View File

@ -2,6 +2,20 @@
# status-sdl-mgr.sh - Script to show status of SDL Manager
set -euo pipefail
use_systemd() {
# Check if systemd user mode is available and service exists
if systemctl --user status >/dev/null 2>&1; then
# Check if our service file exists
if systemctl --user list-unit-files | grep -q "^sdl-mgr.service"; then
return 0 # Use systemd
fi
fi
return 1 # Use manual scripts
}
if use_systemd; then
systemctl --user status sdl-wkr
else
# Get sdl-mgr PID
SDL_MGR_PID=""
for pid in $(pgrep -f 'node' 2>/dev/null || true); do
@ -19,3 +33,4 @@ fi
echo "SDL Manager is running with PID: ${SDL_MGR_PID}"
exit 0
fi

View File

@ -2,6 +2,17 @@
# stop-sdl-wkr.sh - Script to stop SDL Worker
set -euo pipefail
use_systemd() {
# Check if systemd user mode is available and service exists
if systemctl --user status >/dev/null 2>&1; then
# Check if our service file exists
if systemctl --user list-unit-files | grep -q "^sdl-mgr.service"; then
return 0 # Use systemd
fi
fi
return 1 # Use manual scripts
}
# Get sdl-wkr PID
SDL_WKR_PID=""
for pid in $(pgrep -f 'node' 2>/dev/null || true); do
@ -19,6 +30,10 @@ fi
echo "Stopping SDL Worker (PID: ${SDL_WKR_PID})..."
if use_systemd; then
systemctl --user stop sdl-wkr
else
# Manual PID-based stop logic
# Send SIGTERM for graceful shutdown
kill "$SDL_WKR_PID"
@ -42,5 +57,6 @@ if kill -0 "$SDL_WKR_PID" 2>/dev/null; then
exit 1
fi
fi
fi
echo "SDL Worker stopped"