Commit 24611f90 authored by nextime's avatar nextime

Fix bash condition evaluation in init scripts

- Separate PID file reading from process checking
- Prevent command substitution failures in kill command
- Add proper error handling for PID file operations
- Fix false 'watchdog failed' reports due to bash syntax issues
- Fixed both wssshd and wssshc init scripts
parent a15aa00d
......@@ -264,6 +264,7 @@ case "$1" in
if [ -f "$WATCHDOG_PID_FILE" ]; then
watchdog_pid=$(cat "$WATCHDOG_PID_FILE")
echo "Watchdog started successfully (PID: $watchdog_pid)"
exit 0 # Exit immediately to avoid killing background main process
else
echo "Watchdog failed to create PID file"
exit 1
......
......@@ -175,13 +175,25 @@ start() {
echo "Starting watchdog..."
if [ -x "$WATCHDOG" ]; then
$WATCHDOG start >/dev/null 2>&1
sleep 2
if [ -f "$WATCHDOG_PIDFILE" ] && kill -0 "$(cat "$WATCHDOG_PIDFILE")" 2>/dev/null; then
echo "OK"
return 0
# Wait for watchdog PID file to be created (max 5 seconds)
local count=0
while [ $count -lt 10 ] && [ ! -f "$WATCHDOG_PIDFILE" ]; do
sleep 0.5
count=$((count + 1))
done
if [ -f "$WATCHDOG_PIDFILE" ]; then
watchdog_pid=$(cat "$WATCHDOG_PIDFILE" 2>/dev/null)
if [ -n "$watchdog_pid" ] && kill -0 "$watchdog_pid" 2>/dev/null; then
echo "OK"
return 0
else
echo "OK (daemon running, watchdog process not responding)"
return 0
fi
else
echo "OK (daemon running, watchdog failed to start)"
echo "OK (daemon running, watchdog PID file not found)"
return 0
fi
else
......
......@@ -125,13 +125,25 @@ start() {
echo "Starting watchdog..."
if [ -x "$WATCHDOG" ]; then
$WATCHDOG start >/dev/null 2>&1
sleep 2
if [ -f "$WATCHDOG_PIDFILE" ] && kill -0 "$(cat "$WATCHDOG_PIDFILE")" 2>/dev/null; then
echo "OK"
return 0
# Wait for watchdog PID file to be created (max 5 seconds)
local count=0
while [ $count -lt 10 ] && [ ! -f "$WATCHDOG_PIDFILE" ]; do
sleep 0.5
count=$((count + 1))
done
if [ -f "$WATCHDOG_PIDFILE" ]; then
watchdog_pid=$(cat "$WATCHDOG_PIDFILE" 2>/dev/null)
if [ -n "$watchdog_pid" ] && kill -0 "$watchdog_pid" 2>/dev/null; then
echo "OK"
return 0
else
echo "OK (daemon running, watchdog process not responding)"
return 0
fi
else
echo "OK (daemon running, watchdog failed to start)"
echo "OK (daemon running, watchdog PID file not found)"
return 0
fi
else
......
......@@ -259,6 +259,7 @@ case "$1" in
if [ -f "$WATCHDOG_PID_FILE" ]; then
watchdog_pid=$(cat "$WATCHDOG_PID_FILE")
echo "Watchdog started successfully (PID: $watchdog_pid)"
exit 0 # Exit immediately to avoid killing background main process
else
echo "Watchdog failed to create PID file"
exit 1
......
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