Commit cab9eefd authored by nextime's avatar nextime

Fix watchdog daemonization issue

- Watchdog now properly daemonizes by running main() in background
- Removed complex PID file waiting logic that was causing issues
- Simplified start case to just run main() and check for PID file
- Fixed both wssshd and wssshc watchdogs
- Watchdog processes should now persist after script exits
parent 81f5c328
...@@ -259,27 +259,19 @@ case "$1" in ...@@ -259,27 +259,19 @@ case "$1" in
exit 1 exit 1
fi fi
echo "Calling main() function..." echo "Calling main() function..."
# Run main() in background and don't wait for it
main & main &
main_pid=$!
echo "main() started with PID: $main_pid" # Give it a moment to start
# Wait for PID file to be created (max 5 seconds) sleep 1
count=0
while [ $count -lt 10 ] && [ ! -f "$WATCHDOG_PID_FILE" ]; do # Check if PID file was created
echo "Waiting for PID file... (attempt $count)"
sleep 0.5
count=$((count + 1))
done
if [ -f "$WATCHDOG_PID_FILE" ]; then if [ -f "$WATCHDOG_PID_FILE" ]; then
watchdog_pid=$(cat "$WATCHDOG_PID_FILE") watchdog_pid=$(cat "$WATCHDOG_PID_FILE")
echo "Watchdog started successfully (PID: $watchdog_pid)" echo "Watchdog started successfully (PID: $watchdog_pid)"
else else
echo "Watchdog failed to create PID file" echo "Watchdog failed to create PID file"
echo "Checking if main() process is still running..."
if kill -0 "$main_pid" 2>/dev/null; then
echo "main() process $main_pid is still running"
else
echo "main() process $main_pid has exited"
fi
exit 1 exit 1
fi fi
;; ;;
......
...@@ -254,27 +254,19 @@ case "$1" in ...@@ -254,27 +254,19 @@ case "$1" in
exit 1 exit 1
fi fi
echo "Calling main() function..." echo "Calling main() function..."
# Run main() in background and don't wait for it
main & main &
main_pid=$!
echo "main() started with PID: $main_pid" # Give it a moment to start
# Wait for PID file to be created (max 5 seconds) sleep 1
count=0
while [ $count -lt 10 ] && [ ! -f "$WATCHDOG_PID_FILE" ]; do # Check if PID file was created
echo "Waiting for PID file... (attempt $count)"
sleep 0.5
count=$((count + 1))
done
if [ -f "$WATCHDOG_PID_FILE" ]; then if [ -f "$WATCHDOG_PID_FILE" ]; then
watchdog_pid=$(cat "$WATCHDOG_PID_FILE") watchdog_pid=$(cat "$WATCHDOG_PID_FILE")
echo "Watchdog started successfully (PID: $watchdog_pid)" echo "Watchdog started successfully (PID: $watchdog_pid)"
else else
echo "Watchdog failed to create PID file" echo "Watchdog failed to create PID file"
echo "Checking if main() process is still running..."
if kill -0 "$main_pid" 2>/dev/null; then
echo "main() process $main_pid is still running"
else
echo "main() process $main_pid has exited"
fi
exit 1 exit 1
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