feat: 添加极简版进程监控脚本 simple_monitor.sh
- 只需修改3处配置:检测间隔、检查命令、执行命令 - 代码简洁,易于理解和修改 - 适合快速部署使用
This commit is contained in:
@@ -28,7 +28,8 @@ tools/
|
|||||||
|
|
||||||
| 名称 | 路径 | 说明 |
|
| 名称 | 路径 | 说明 |
|
||||||
|------|------|------|
|
|------|------|------|
|
||||||
| proc_monitor.sh | scripts/proc_monitor.sh | 进程监控脚本,进程消失时执行指定命令 |
|
| proc_monitor.sh | scripts/proc_monitor.sh | 进程监控脚本(功能完整版) |
|
||||||
|
| simple_monitor.sh | scripts/simple_monitor.sh | 进程监控脚本(极简版,只需改3行配置) |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
18
scripts/simple_monitor.sh
Executable file
18
scripts/simple_monitor.sh
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# 简单进程监控脚本
|
||||||
|
# 每隔几秒检查一次进程,进程消失则执行命令
|
||||||
|
|
||||||
|
# ==================== 配置区域(只需改这里) ====================
|
||||||
|
CHECK_INTERVAL=10 # 每隔多少秒检查一次
|
||||||
|
CHECK_CMD="pgrep myapp" # 检查命令(进程存在应返回0)
|
||||||
|
EXEC_CMD="echo 'Process died'" # 进程消失后执行的命令
|
||||||
|
# ===============================================================
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
if ! eval "$CHECK_CMD" >/dev/null 2>&1; then
|
||||||
|
echo "[$(date '+%H:%M:%S')] Process not found, executing: $EXEC_CMD"
|
||||||
|
eval "$EXEC_CMD"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep "$CHECK_INTERVAL"
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user