Commit 1c1a2538 authored by nextime's avatar nextime

Add debug logging to watchdog scripts

- Log START configuration values and validation
- Add detailed startup debugging in start case
- Track main() function PID and PID file creation
- Help identify why watchdog fails to start properly
- Applied to both wssshd and wssshc watchdogs
parent 646ff942
......@@ -199,13 +199,20 @@ trap cleanup SIGTERM SIGINT
# Main watchdog function (continuous monitoring)
main() {
# Debug: Log the START value
log_message "START configuration value: '$START'"
# Check if START is enabled (accept various forms: yes, YES, Y, 1, true, TRUE)
START_LOWER=$(echo "$START" | tr '[:upper:]' '[:lower:]')
log_message "START_LOWER: '$START_LOWER'"
if [ "$START_LOWER" != "yes" ] && [ "$START_LOWER" != "y" ] && [ "$START_LOWER" != "1" ] && [ "$START_LOWER" != "true" ]; then
log_message "START is not set to a valid enabled value in /etc/default/wssshd. Exiting."
exit 0
fi
log_message "START validation passed, proceeding with watchdog initialization"
# Store watchdog PID
echo $$ > "$WATCHDOG_PID_FILE"
......@@ -241,21 +248,33 @@ main() {
# Handle command line arguments
case "$1" in
start)
echo "Starting watchdog..."
if [ -f "$WATCHDOG_PID_FILE" ]; then
echo "Watchdog is already running"
exit 1
fi
echo "Calling main() function..."
main &
main_pid=$!
echo "main() started with PID: $main_pid"
# Wait for PID file to be created (max 5 seconds)
count=0
while [ $count -lt 10 ] && [ ! -f "$WATCHDOG_PID_FILE" ]; do
echo "Waiting for PID file... (attempt $count)"
sleep 0.5
count=$((count + 1))
done
if [ -f "$WATCHDOG_PID_FILE" ]; then
echo "Watchdog started"
watchdog_pid=$(cat "$WATCHDOG_PID_FILE")
echo "Watchdog started successfully (PID: $watchdog_pid)"
else
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
fi
;;
......
......@@ -199,13 +199,20 @@ trap cleanup SIGTERM SIGINT
# Main watchdog function (continuous monitoring)
main() {
# Debug: Log the START value
log_message "START configuration value: '$START'"
# Check if START is enabled (accept various forms: yes, YES, Y, 1, true, TRUE)
START_LOWER=$(echo "$START" | tr '[:upper:]' '[:lower:]')
log_message "START_LOWER: '$START_LOWER'"
if [ "$START_LOWER" != "yes" ] && [ "$START_LOWER" != "y" ] && [ "$START_LOWER" != "1" ] && [ "$START_LOWER" != "true" ]; then
log_message "START is not set to a valid enabled value in /etc/default/wssshc. Exiting."
exit 0
fi
log_message "START validation passed, proceeding with watchdog initialization"
# Store watchdog PID
echo $$ > "$WATCHDOG_PID_FILE"
......@@ -241,21 +248,33 @@ main() {
# Handle command line arguments
case "$1" in
start)
echo "Starting watchdog..."
if [ -f "$WATCHDOG_PID_FILE" ]; then
echo "Watchdog is already running"
exit 1
fi
echo "Calling main() function..."
main &
main_pid=$!
echo "main() started with PID: $main_pid"
# Wait for PID file to be created (max 5 seconds)
count=0
while [ $count -lt 10 ] && [ ! -f "$WATCHDOG_PID_FILE" ]; do
echo "Waiting for PID file... (attempt $count)"
sleep 0.5
count=$((count + 1))
done
if [ -f "$WATCHDOG_PID_FILE" ]; then
echo "Watchdog started"
watchdog_pid=$(cat "$WATCHDOG_PID_FILE")
echo "Watchdog started successfully (PID: $watchdog_pid)"
else
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
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