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() {
stop() {
echo -n "Stopping $NAME: "
# Check if watchdog is running
if [ ! -f "$WATCHDOG_PIDFILE" ]; then
echo "not running"
return 0
# First, try to stop the watchdog if it's running
if [ -f "$WATCHDOG_PIDFILE" ]; then
echo "Stopping watchdog..."
$WATCHDOG stop >/dev/null 2>&1
sleep 2
fi
# Stop the watchdog (which will stop the daemon)
$WATCHDOG stop >/dev/null 2>&1
# Now check if the daemon is still running and stop it directly if needed
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
# Wait a moment for everything to stop
sleep 3
# Also kill any other wssshc processes that might be running
pkill -f "^/usr/bin/wssshc" 2>/dev/null || true
fi
# Clean up PID files
rm -f "$PIDFILE" "$WATCHDOG_PIDFILE"
# Final check
if is_running; then
echo "FAILED"
return 1
else
echo "OK"
return 0
else
echo "FAILED"
return $retval
fi
}
......
......@@ -122,29 +122,42 @@ start() {
stop() {
echo -n "Stopping $NAME: "
# Check if watchdog is running
if [ ! -f "$WATCHDOG_PIDFILE" ]; then
echo "not running"
return 0
# First, try to stop the watchdog if it's running
if [ -f "$WATCHDOG_PIDFILE" ]; then
echo "Stopping watchdog..."
$WATCHDOG stop >/dev/null 2>&1
sleep 2
fi
# Stop the watchdog (which will stop the daemon)
$WATCHDOG stop >/dev/null 2>&1
# Now check if the daemon is still running and stop it directly if needed
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
# Wait a moment for everything to stop
sleep 3
# Also kill any other wssshd processes that might be running
pkill -f "^/usr/bin/wssshd" 2>/dev/null || true
fi
# Clean up PID files
rm -f "$PIDFILE" "$WATCHDOG_PIDFILE"
# Final check
if is_running; then
echo "FAILED"
return 1
else
echo "OK"
return 0
else
echo "FAILED"
return $retval
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