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() {
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 "Check interval: $CHECK_INTERVAL seconds"
log_message "Max restarts: $MAX_RESTARTS per $RESTART_WINDOW seconds"
......@@ -259,16 +255,19 @@ case "$1" in
main &
MAIN_PID=$!
# Create PID file with the background process PID
echo $MAIN_PID > "$WATCHDOG_PID_FILE"
# Give it a moment to start
sleep 1
# Check if PID file was created
if [ -f "$WATCHDOG_PID_FILE" ]; then
watchdog_pid=$(cat "$WATCHDOG_PID_FILE")
echo "Watchdog started successfully (PID: $watchdog_pid)"
# Check if the process is still running
if kill -0 $MAIN_PID 2>/dev/null; then
echo "Watchdog started successfully (PID: $MAIN_PID)"
exit 0 # Exit immediately to avoid killing background main process
else
echo "Watchdog failed to create PID file"
echo "Watchdog failed to start"
rm -f "$WATCHDOG_PID_FILE"
exit 1
fi
;;
......
......@@ -193,10 +193,6 @@ main() {
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 "Check interval: $CHECK_INTERVAL seconds"
log_message "Max restarts: $MAX_RESTARTS per $RESTART_WINDOW seconds"
......@@ -254,16 +250,19 @@ case "$1" in
main &
MAIN_PID=$!
# Create PID file with the background process PID
echo $MAIN_PID > "$WATCHDOG_PID_FILE"
# Give it a moment to start
sleep 1
# Check if PID file was created
if [ -f "$WATCHDOG_PID_FILE" ]; then
watchdog_pid=$(cat "$WATCHDOG_PID_FILE")
echo "Watchdog started successfully (PID: $watchdog_pid)"
# Check if the process is still running
if kill -0 $MAIN_PID 2>/dev/null; then
echo "Watchdog started successfully (PID: $MAIN_PID)"
exit 0 # Exit immediately to avoid killing background main process
else
echo "Watchdog failed to create PID file"
echo "Watchdog failed to start"
rm -f "$WATCHDOG_PID_FILE"
exit 1
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