Commit f8f89d64 authored by nextime's avatar nextime

Fix watchdog stop command to kill all running processes

- Stop command now kills processes from PID file AND any other running watchdog processes
- Prevents zombie watchdog processes when PID file doesn't exist
- Added aggressive cleanup of all watchdog processes
- Fixed both wssshd and wssshc watchdogs
- Ensures complete watchdog shutdown even with startup failures
parent 1c1a2538
......@@ -25,8 +25,13 @@ DAEMON_ARGS=""
# Load configuration if available
if [ -f /etc/default/wssshd ]; then
. /etc/default/wssshd
echo "Loaded configuration from /etc/default/wssshd"
else
echo "No configuration file found at /etc/default/wssshd, using defaults"
fi
echo "START value after configuration loading: '$START'"
# Function to log messages
log_message() {
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
......@@ -279,20 +284,36 @@ case "$1" in
fi
;;
stop)
# First, try to stop the process from PID file
if [ -f "$WATCHDOG_PID_FILE" ]; then
watchdog_pid=$(cat "$WATCHDOG_PID_FILE")
# Double-check: verify the process is actually our watchdog
if ps -p "$watchdog_pid" -o comm= 2>/dev/null | grep -q "wssshd-watchdog"; then
kill "$watchdog_pid" 2>/dev/null
rm -f "$WATCHDOG_PID_FILE"
echo "Watchdog stopped"
echo "Watchdog stopped (from PID file)"
else
echo "PID file exists but process is not wssshd-watchdog"
rm -f "$WATCHDOG_PID_FILE"
fi
else
echo "Watchdog is not running"
fi
# Also kill any other watchdog processes that might be running
# Find all bash processes running our watchdog script
watchdog_processes=$(ps aux | grep "/usr/sbin/wssshd-watchdog start" | grep -v grep | awk '{print $2}')
if [ -n "$watchdog_processes" ]; then
echo "Found additional watchdog processes: $watchdog_processes"
for pid in $watchdog_processes; do
if [ "$pid" != "$$" ]; then # Don't kill ourselves
kill "$pid" 2>/dev/null && echo "Killed watchdog process $pid"
fi
done
fi
# Clean up any remaining PID files
rm -f "$WATCHDOG_PID_FILE" 2>/dev/null
echo "Watchdog stop process completed"
;;
status)
if [ -f "$WATCHDOG_PID_FILE" ]; then
......
......@@ -279,20 +279,36 @@ case "$1" in
fi
;;
stop)
# First, try to stop the process from PID file
if [ -f "$WATCHDOG_PID_FILE" ]; then
watchdog_pid=$(cat "$WATCHDOG_PID_FILE")
# Double-check: verify the process is actually our watchdog
if ps -p "$watchdog_pid" -o comm= 2>/dev/null | grep -q "wssshc-watchdog"; then
kill "$watchdog_pid" 2>/dev/null
rm -f "$WATCHDOG_PID_FILE"
echo "Watchdog stopped"
echo "Watchdog stopped (from PID file)"
else
echo "PID file exists but process is not wssshc-watchdog"
rm -f "$WATCHDOG_PID_FILE"
fi
else
echo "Watchdog is not running"
fi
# Also kill any other watchdog processes that might be running
# Find all bash processes running our watchdog script
watchdog_processes=$(ps aux | grep "/usr/sbin/wssshc-watchdog start" | grep -v grep | awk '{print $2}')
if [ -n "$watchdog_processes" ]; then
echo "Found additional watchdog processes: $watchdog_processes"
for pid in $watchdog_processes; do
if [ "$pid" != "$$" ]; then # Don't kill ourselves
kill "$pid" 2>/dev/null && echo "Killed watchdog process $pid"
fi
done
fi
# Clean up any remaining PID files
rm -f "$WATCHDOG_PID_FILE" 2>/dev/null
echo "Watchdog stop process completed"
;;
status)
if [ -f "$WATCHDOG_PID_FILE" ]; then
......
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