init: NAS 进程监控面板 (backend + frontend + 开机自启脚本)

This commit is contained in:
2026-08-15 08:27:54 +08:00
commit 3e7cdcef62
4 changed files with 677 additions and 0 deletions

39
S99nas-monitor.sh Normal file
View File

@@ -0,0 +1,39 @@
#!/bin/sh
# NAS 进程监控 开机自启脚本(以 root 运行,以便读取所有进程的网络连接信息)
APP=/volume1/web/nas-monitor/app.py
LOG=/volume1/web/nas-monitor/app.log
PIDFILE=/volume1/web/nas-monitor/app.pid
PY=$(command -v python3 || echo /usr/bin/python3)
start() {
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then
echo "nas-monitor 已在运行 (PID $(cat "$PIDFILE"))"; return 0
fi
# 等待数据卷 volume1 挂载就绪(最多 90 秒),避免开机时脚本早于卷挂载而静默失败
n=0
while [ ! -f "$APP" ] && [ $n -lt 90 ]; do
sleep 1; n=$((n+1))
done
if [ ! -f "$APP" ]; then
echo "等待 $APP 超时(数据卷可能未挂载),启动放弃"; return 1
fi
setsid nohup "$PY" "$APP" > "$LOG" 2>&1 < /dev/null &
echo $! > "$PIDFILE"
sleep 2
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then
echo "nas-monitor 已启动 (PID $(cat "$PIDFILE"))"
else
echo "启动失败,请查看 $LOG"; return 1
fi
}
stop() {
if [ -f "$PIDFILE" ]; then kill "$(cat "$PIDFILE")" 2>/dev/null; rm -f "$PIDFILE"; fi
pkill -f "nas-monitor/app.py" 2>/dev/null
echo "nas-monitor 已停止"
}
case "$1" in
start) start ;;
stop) stop ;;
restart) stop; sleep 1; start ;;
*) echo "用法: $0 {start|stop|restart}"; exit 1 ;;
esac