Commit 299eed2b authored by nextime's avatar nextime

Fix init scripts to handle existing watchdog processes

- Stop existing watchdog before starting new one
- Use pgrep to detect running watchdog processes
- Prevent 'watchdog already running' conflicts
- Ensure clean watchdog startup in init scripts
- Fixed both wssshd and wssshc init scripts
parent 844a88ba
...@@ -164,6 +164,13 @@ start() { ...@@ -164,6 +164,13 @@ start() {
local pid=$(cat "$PIDFILE") local pid=$(cat "$PIDFILE")
echo "Daemon is running (PID: $pid)" echo "Daemon is running (PID: $pid)"
# Stop any existing watchdog before starting a new one
if [ -f "$WATCHDOG_PIDFILE" ] || pgrep -f "wssshc-watchdog" >/dev/null 2>&1; then
echo "Stopping existing watchdog..."
$WATCHDOG stop >/dev/null 2>&1
sleep 2
fi
# Now start the watchdog to monitor the running daemon # Now start the watchdog to monitor the running daemon
echo "Starting watchdog..." echo "Starting watchdog..."
if [ -x "$WATCHDOG" ]; then if [ -x "$WATCHDOG" ]; then
...@@ -174,11 +181,11 @@ start() { ...@@ -174,11 +181,11 @@ start() {
echo "OK" echo "OK"
return 0 return 0
else else
echo "OK (daemon running, watchdog failed)" echo "OK (daemon running, watchdog failed to start)"
return 0 return 0
fi fi
else else
echo "OK (daemon running, no watchdog)" echo "OK (daemon running, no watchdog available)"
return 0 return 0
fi fi
else else
......
...@@ -114,6 +114,13 @@ start() { ...@@ -114,6 +114,13 @@ start() {
local pid=$(cat "$PIDFILE") local pid=$(cat "$PIDFILE")
echo "Daemon is running (PID: $pid)" echo "Daemon is running (PID: $pid)"
# Stop any existing watchdog before starting a new one
if [ -f "$WATCHDOG_PIDFILE" ] || pgrep -f "wssshd-watchdog" >/dev/null 2>&1; then
echo "Stopping existing watchdog..."
$WATCHDOG stop >/dev/null 2>&1
sleep 2
fi
# Now start the watchdog to monitor the running daemon # Now start the watchdog to monitor the running daemon
echo "Starting watchdog..." echo "Starting watchdog..."
if [ -x "$WATCHDOG" ]; then if [ -x "$WATCHDOG" ]; then
...@@ -124,11 +131,11 @@ start() { ...@@ -124,11 +131,11 @@ start() {
echo "OK" echo "OK"
return 0 return 0
else else
echo "OK (daemon running, watchdog failed)" echo "OK (daemon running, watchdog failed to start)"
return 0 return 0
fi fi
else else
echo "OK (daemon running, no watchdog)" echo "OK (daemon running, no watchdog available)"
return 0 return 0
fi fi
else else
......
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