23 lines
632 B
Bash
Executable File
23 lines
632 B
Bash
Executable File
#!/bin/bash
|
|
# 7z-encrypt 服务看门狗: 每 30s 检查服务进程, 挂了自动拉起
|
|
# 由 start.sh 启动 (容器唤醒后自动恢复); 日志 /tmp/sz-watchdog.log
|
|
LOGFILE=/tmp/sz-watchdog.log
|
|
|
|
log() {
|
|
echo "$(date '+%F %T') $1" >> "$LOGFILE"
|
|
}
|
|
|
|
# 防重复: 已有 watchdog 实例则退出
|
|
if pgrep -f 'watchdog[.]sh' > /dev/null 2>&1; then
|
|
exit 0
|
|
fi
|
|
|
|
log "[watchdog] 启动, PID $$"
|
|
while true; do
|
|
if ! pgrep -f 'python3 [m]ain\.py' > /dev/null 2>&1; then
|
|
log "[watchdog] 服务挂了, 拉起..."
|
|
/root/server/start.sh >> "$LOGFILE" 2>&1 || log "[watchdog] 拉起失败"
|
|
fi
|
|
sleep 30
|
|
done
|