From 456ac1761bc2428602d9c19fc341f28415d5cc1b Mon Sep 17 00:00:00 2001 From: John Haverlack Date: Wed, 4 Feb 2026 20:40:39 -0900 Subject: [PATCH] Fixing Wkr Start / Stop --- sdl-mgr/scripts/start-sdl-mgr.sh | 22 ++++++------- sdl-mgr/scripts/status-sdl-mgr.sh | 7 ++++- sdl-mgr/scripts/stop-sdl-mgr.sh | 51 ++++++++++++++++--------------- 3 files changed, 43 insertions(+), 37 deletions(-) diff --git a/sdl-mgr/scripts/start-sdl-mgr.sh b/sdl-mgr/scripts/start-sdl-mgr.sh index 511b098..5903030 100755 --- a/sdl-mgr/scripts/start-sdl-mgr.sh +++ b/sdl-mgr/scripts/start-sdl-mgr.sh @@ -17,6 +17,14 @@ use_systemd() { SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SDL_HOME="$(cd "$SCRIPT_DIR/.." && pwd)" +if use_systemd; then + # Systemd mode - let systemd handle it + echo "Starting SDL Manager (systemd)..." + systemctl --user start sdl-mgr + exit 0 +fi + +# Manual mode - continue with checks NODE_BIN_DIR="${SDL_HOME}/nodejs/current/bin" NODE_BIN="${NODE_BIN_DIR}/node" NPM_BIN="${NODE_BIN_DIR}/npm" @@ -35,7 +43,7 @@ done if [[ -n "$SDL_MGR_PID" ]]; then echo "ERROR: SDL Manager is already running with PID ${SDL_MGR_PID}" - echo " Stop it first: kill ${SDL_MGR_PID}" + echo " Stop it first: ${SDL_HOME}/scripts/stop-sdl-mgr.sh" exit 1 fi @@ -54,14 +62,4 @@ fi echo "Starting SDL Manager..." echo " App Dir: ${SDL_MGR_APP_DIR}" -echo " Node: ${NODE_BIN}" - -export PATH="${NODE_BIN_DIR}:${PATH}" -cd "${SDL_MGR_APP_DIR}" - -if use_systemd; then - systemctl --user start sdl-mgr -else - # Manual background start logic - "${NPM_BIN}" start & -fi \ No newline at end of file +echo " Node: \ No newline at end of file diff --git a/sdl-mgr/scripts/status-sdl-mgr.sh b/sdl-mgr/scripts/status-sdl-mgr.sh index 54c156c..a69a4cf 100755 --- a/sdl-mgr/scripts/status-sdl-mgr.sh +++ b/sdl-mgr/scripts/status-sdl-mgr.sh @@ -31,6 +31,11 @@ else exit 0 fi - echo "SDL Manager is running with PID: ${SDL_MGR_PID}" + # Get process uptime + PROCESS_START=$(ps -p "$SDL_MGR_PID" -o lstart= 2>/dev/null || echo "unknown") + + echo "SDL Manager is running" + echo " PID: ${SDL_MGR_PID}" + echo " Started: ${PROCESS_START}" exit 0 fi \ No newline at end of file diff --git a/sdl-mgr/scripts/stop-sdl-mgr.sh b/sdl-mgr/scripts/stop-sdl-mgr.sh index 1e09ac8..454f4d8 100755 --- a/sdl-mgr/scripts/stop-sdl-mgr.sh +++ b/sdl-mgr/scripts/stop-sdl-mgr.sh @@ -13,7 +13,15 @@ use_systemd() { return 1 # Use manual scripts } -# Get sdl-mgr PID +if use_systemd; then + # Systemd mode - let systemd handle it + echo "Stopping SDL Manager (systemd)..." + systemctl --user stop sdl-mgr --quiet 2>/dev/null || true + echo "SDL Manager stopped" + exit 0 +fi + +# Manual mode - find and kill process SDL_MGR_PID="" for pid in $(pgrep -f 'node' 2>/dev/null || true); do cwd=$(readlink /proc/$pid/cwd 2>/dev/null || true) @@ -30,32 +38,27 @@ 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" +# Send SIGTERM for graceful shutdown +kill "$SDL_MGR_PID" - # Wait up to 10 seconds for process to exit - for i in {1..10}; do - if ! kill -0 "$SDL_MGR_PID" 2>/dev/null; then - echo "SDL Manager stopped successfully" - exit 0 - fi - sleep 1 - done +# Wait up to 10 seconds for process to exit +for i in {1..10}; do + if ! kill -0 "$SDL_MGR_PID" 2>/dev/null; then + echo "SDL Manager stopped successfully" + exit 0 + fi + sleep 1 +done - # If still running after 10 seconds, force kill +# If still running after 10 seconds, force kill +if kill -0 "$SDL_MGR_PID" 2>/dev/null; then + echo "WARNING: Graceful shutdown failed, forcing kill..." + kill -9 "$SDL_MGR_PID" + sleep 1 + if kill -0 "$SDL_MGR_PID" 2>/dev/null; then - echo "WARNING: Graceful shutdown failed, forcing kill..." - kill -9 "$SDL_MGR_PID" - sleep 1 - - if kill -0 "$SDL_MGR_PID" 2>/dev/null; then - echo "ERROR: Failed to stop SDL Manager" - exit 1 - fi + echo "ERROR: Failed to stop SDL Manager" + exit 1 fi fi