Commit 9c51519e authored by nextime's avatar nextime

Fix init scripts to stop daemons directly when watchdog not running

- Init scripts now stop daemons directly even if watchdog PID file doesn't exist
- Added graceful termination (TERM) followed by force kill (KILL) if needed
- Added pkill fallback to catch any remaining daemon processes
- Fixed both wssshd and wssshc init scripts
- Ensures complete daemon shutdown regardless of watchdog status
parent f8f89d64
...@@ -179,29 +179,42 @@ start() { ...@@ -179,29 +179,42 @@ start() {
stop() { stop() {
echo -n "Stopping $NAME: " echo -n "Stopping $NAME: "
# Check if watchdog is running # First, try to stop the watchdog if it's running
if [ ! -f "$WATCHDOG_PIDFILE" ]; then if [ -f "$WATCHDOG_PIDFILE" ]; then
echo "not running" echo "Stopping watchdog..."
return 0 $WATCHDOG stop >/dev/null 2>&1
sleep 2
fi fi
# Stop the watchdog (which will stop the daemon) # Now check if the daemon is still running and stop it directly if needed
$WATCHDOG stop >/dev/null 2>&1 if is_running; then
echo "Stopping daemon directly..."
local pid=$(cat "$PIDFILE")
# Try to stop gracefully first
kill -TERM "$pid" 2>/dev/null
sleep 2
local retval=$? # Check if it's still running
if kill -0 "$pid" 2>/dev/null; then
# Force kill if still running
kill -KILL "$pid" 2>/dev/null
sleep 1
fi
if [ $retval -eq 0 ]; then # Also kill any other wssshc processes that might be running
# Wait a moment for everything to stop pkill -f "^/usr/bin/wssshc" 2>/dev/null || true
sleep 3 fi
# Clean up PID files # Clean up PID files
rm -f "$PIDFILE" "$WATCHDOG_PIDFILE" rm -f "$PIDFILE" "$WATCHDOG_PIDFILE"
# Final check
if is_running; then
echo "FAILED"
return 1
else
echo "OK" echo "OK"
return 0 return 0
else
echo "FAILED"
return $retval
fi fi
} }
......
...@@ -122,29 +122,42 @@ start() { ...@@ -122,29 +122,42 @@ start() {
stop() { stop() {
echo -n "Stopping $NAME: " echo -n "Stopping $NAME: "
# Check if watchdog is running # First, try to stop the watchdog if it's running
if [ ! -f "$WATCHDOG_PIDFILE" ]; then if [ -f "$WATCHDOG_PIDFILE" ]; then
echo "not running" echo "Stopping watchdog..."
return 0 $WATCHDOG stop >/dev/null 2>&1
sleep 2
fi fi
# Stop the watchdog (which will stop the daemon) # Now check if the daemon is still running and stop it directly if needed
$WATCHDOG stop >/dev/null 2>&1 if is_running; then
echo "Stopping daemon directly..."
local pid=$(cat "$PIDFILE")
# Try to stop gracefully first
kill -TERM "$pid" 2>/dev/null
sleep 2
local retval=$? # Check if it's still running
if kill -0 "$pid" 2>/dev/null; then
# Force kill if still running
kill -KILL "$pid" 2>/dev/null
sleep 1
fi
if [ $retval -eq 0 ]; then # Also kill any other wssshd processes that might be running
# Wait a moment for everything to stop pkill -f "^/usr/bin/wssshd" 2>/dev/null || true
sleep 3 fi
# Clean up PID files # Clean up PID files
rm -f "$PIDFILE" "$WATCHDOG_PIDFILE" rm -f "$PIDFILE" "$WATCHDOG_PIDFILE"
# Final check
if is_running; then
echo "FAILED"
return 1
else
echo "OK" echo "OK"
return 0 return 0
else
echo "FAILED"
return $retval
fi fi
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment