Commit 51f99873 authored by nextime's avatar nextime

Fix PID file creation in watchdog start case

- Create PID file in start case with correct background process PID
- Remove PID file creation from main() function to avoid empty files
- Validate background process is running before reporting success
- Clean up PID file if process fails to start
- Fix both wssshd and wssshc watchdogs
parent 5ee95a9f
...@@ -198,10 +198,6 @@ main() { ...@@ -198,10 +198,6 @@ main() {
log_message "START validation passed, proceeding with watchdog initialization" log_message "START validation passed, proceeding with watchdog initialization"
# Store watchdog PID (use the background process PID captured by parent)
echo $MAIN_PID > "$WATCHDOG_PID_FILE"
log_message "Created PID file with PID: $MAIN_PID"
log_message "Watchdog started for $DAEMON_NAME" log_message "Watchdog started for $DAEMON_NAME"
log_message "Check interval: $CHECK_INTERVAL seconds" log_message "Check interval: $CHECK_INTERVAL seconds"
log_message "Max restarts: $MAX_RESTARTS per $RESTART_WINDOW seconds" log_message "Max restarts: $MAX_RESTARTS per $RESTART_WINDOW seconds"
...@@ -259,16 +255,19 @@ case "$1" in ...@@ -259,16 +255,19 @@ case "$1" in
main & main &
MAIN_PID=$! MAIN_PID=$!
# Create PID file with the background process PID
echo $MAIN_PID > "$WATCHDOG_PID_FILE"
# Give it a moment to start # Give it a moment to start
sleep 1 sleep 1
# Check if PID file was created # Check if the process is still running
if [ -f "$WATCHDOG_PID_FILE" ]; then if kill -0 $MAIN_PID 2>/dev/null; then
watchdog_pid=$(cat "$WATCHDOG_PID_FILE") echo "Watchdog started successfully (PID: $MAIN_PID)"
echo "Watchdog started successfully (PID: $watchdog_pid)"
exit 0 # Exit immediately to avoid killing background main process exit 0 # Exit immediately to avoid killing background main process
else else
echo "Watchdog failed to create PID file" echo "Watchdog failed to start"
rm -f "$WATCHDOG_PID_FILE"
exit 1 exit 1
fi fi
;; ;;
......
...@@ -193,10 +193,6 @@ main() { ...@@ -193,10 +193,6 @@ main() {
log_message "START validation passed, proceeding with watchdog initialization" log_message "START validation passed, proceeding with watchdog initialization"
# Store watchdog PID (use the background process PID captured by parent)
echo $MAIN_PID > "$WATCHDOG_PID_FILE"
log_message "Created PID file with PID: $MAIN_PID"
log_message "Watchdog started for $DAEMON_NAME" log_message "Watchdog started for $DAEMON_NAME"
log_message "Check interval: $CHECK_INTERVAL seconds" log_message "Check interval: $CHECK_INTERVAL seconds"
log_message "Max restarts: $MAX_RESTARTS per $RESTART_WINDOW seconds" log_message "Max restarts: $MAX_RESTARTS per $RESTART_WINDOW seconds"
...@@ -254,16 +250,19 @@ case "$1" in ...@@ -254,16 +250,19 @@ case "$1" in
main & main &
MAIN_PID=$! MAIN_PID=$!
# Create PID file with the background process PID
echo $MAIN_PID > "$WATCHDOG_PID_FILE"
# Give it a moment to start # Give it a moment to start
sleep 1 sleep 1
# Check if PID file was created # Check if the process is still running
if [ -f "$WATCHDOG_PID_FILE" ]; then if kill -0 $MAIN_PID 2>/dev/null; then
watchdog_pid=$(cat "$WATCHDOG_PID_FILE") echo "Watchdog started successfully (PID: $MAIN_PID)"
echo "Watchdog started successfully (PID: $watchdog_pid)"
exit 0 # Exit immediately to avoid killing background main process exit 0 # Exit immediately to avoid killing background main process
else else
echo "Watchdog failed to create PID file" echo "Watchdog failed to start"
rm -f "$WATCHDOG_PID_FILE"
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