Systemd Detectiion in Start/Stop/Status
This commit is contained in:
parent
b84f4475e0
commit
ee3b315a98
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
"${NPM_BIN}" start &
|
||||
if use_systemd; then
|
||||
systemctl --user start sdl-mgr
|
||||
else
|
||||
# Manual background start logic
|
||||
"${NPM_BIN}" start &
|
||||
fi
|
||||
|
|
@ -2,20 +2,35 @@
|
|||
# status-sdl-mgr.sh - Script to show status of SDL Manager
|
||||
set -euo pipefail
|
||||
|
||||
# Get sdl-mgr PID
|
||||
SDL_MGR_PID=""
|
||||
for pid in $(pgrep -f 'node' 2>/dev/null || true); do
|
||||
cwd=$(readlink /proc/$pid/cwd 2>/dev/null || true)
|
||||
if [[ "$cwd" == *"sdl-mgr"* ]]; then
|
||||
SDL_MGR_PID="$pid"
|
||||
break
|
||||
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
|
||||
done
|
||||
return 1 # Use manual scripts
|
||||
}
|
||||
|
||||
if [[ -z "$SDL_MGR_PID" ]]; then
|
||||
echo "SDL Manager is not running"
|
||||
exit 0
|
||||
fi
|
||||
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
|
||||
cwd=$(readlink /proc/$pid/cwd 2>/dev/null || true)
|
||||
if [[ "$cwd" == *"sdl-mgr"* ]]; then
|
||||
SDL_MGR_PID="$pid"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
echo "SDL Manager is running with PID: ${SDL_MGR_PID}"
|
||||
exit 0
|
||||
if [[ -z "$SDL_MGR_PID" ]]; then
|
||||
echo "SDL Manager is not running"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "SDL Manager is running with PID: ${SDL_MGR_PID}"
|
||||
exit 0
|
||||
fi
|
||||
|
|
@ -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,27 +30,32 @@ fi
|
|||
|
||||
echo "Stopping SDL Manager (PID: ${SDL_MGR_PID})..."
|
||||
|
||||
# Send SIGTERM for graceful shutdown
|
||||
kill "$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"
|
||||
|
||||
# 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 kill -0 "$SDL_MGR_PID" 2>/dev/null; then
|
||||
echo "WARNING: Graceful shutdown failed, forcing kill..."
|
||||
kill -9 "$SDL_MGR_PID"
|
||||
sleep 1
|
||||
|
||||
# If still running after 10 seconds, force kill
|
||||
if kill -0 "$SDL_MGR_PID" 2>/dev/null; then
|
||||
echo "ERROR: Failed to stop SDL Manager"
|
||||
exit 1
|
||||
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
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -2,20 +2,35 @@
|
|||
# status-sdl-mgr.sh - Script to show status of SDL Manager
|
||||
set -euo pipefail
|
||||
|
||||
# Get sdl-mgr PID
|
||||
SDL_MGR_PID=""
|
||||
for pid in $(pgrep -f 'node' 2>/dev/null || true); do
|
||||
cwd=$(readlink /proc/$pid/cwd 2>/dev/null || true)
|
||||
if [[ "$cwd" == *"sdl-mgr"* ]]; then
|
||||
SDL_MGR_PID="$pid"
|
||||
break
|
||||
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
|
||||
done
|
||||
return 1 # Use manual scripts
|
||||
}
|
||||
|
||||
if [[ -z "$SDL_MGR_PID" ]]; then
|
||||
echo "SDL Manager is not running"
|
||||
exit 0
|
||||
fi
|
||||
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
|
||||
cwd=$(readlink /proc/$pid/cwd 2>/dev/null || true)
|
||||
if [[ "$cwd" == *"sdl-mgr"* ]]; then
|
||||
SDL_MGR_PID="$pid"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
echo "SDL Manager is running with PID: ${SDL_MGR_PID}"
|
||||
exit 0
|
||||
if [[ -z "$SDL_MGR_PID" ]]; then
|
||||
echo "SDL Manager is not running"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "SDL Manager is running with PID: ${SDL_MGR_PID}"
|
||||
exit 0
|
||||
fi
|
||||
|
|
@ -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,27 +30,32 @@ fi
|
|||
|
||||
echo "Stopping SDL Worker (PID: ${SDL_WKR_PID})..."
|
||||
|
||||
# Send SIGTERM for graceful shutdown
|
||||
kill "$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"
|
||||
|
||||
# Wait up to 10 seconds for process to exit
|
||||
for i in {1..10}; do
|
||||
if ! kill -0 "$SDL_WKR_PID" 2>/dev/null; then
|
||||
echo "SDL Worker 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_WKR_PID" 2>/dev/null; then
|
||||
echo "SDL Worker stopped successfully"
|
||||
exit 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# If still running after 10 seconds, force kill
|
||||
if kill -0 "$SDL_WKR_PID" 2>/dev/null; then
|
||||
echo "WARNING: Graceful shutdown failed, forcing kill..."
|
||||
kill -9 "$SDL_WKR_PID"
|
||||
sleep 1
|
||||
|
||||
# If still running after 10 seconds, force kill
|
||||
if kill -0 "$SDL_WKR_PID" 2>/dev/null; then
|
||||
echo "ERROR: Failed to stop SDL Worker"
|
||||
exit 1
|
||||
echo "WARNING: Graceful shutdown failed, forcing kill..."
|
||||
kill -9 "$SDL_WKR_PID"
|
||||
sleep 1
|
||||
|
||||
if kill -0 "$SDL_WKR_PID" 2>/dev/null; then
|
||||
echo "ERROR: Failed to stop SDL Worker"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue