diff --git a/scripts/reset-data.sh b/scripts/reset-data.sh index a3870c0..6dae53c 100755 --- a/scripts/reset-data.sh +++ b/scripts/reset-data.sh @@ -53,6 +53,14 @@ fi echo "🛑 Stopping $PM2_NAME..." pm2 stop "$PM2_NAME" 2>/dev/null || true +# 确保 trap 恢复服务 +cleanup() { + echo "" + echo "▶️ Ensuring $PM2_NAME is running..." + pm2 restart "$PM2_NAME" 2>/dev/null || pm2 start "$PM2_NAME" 2>/dev/null || true +} +trap cleanup EXIT + # ── 清数据 ── echo "" if [ -n "$PROJECT_FILTER" ]; then @@ -81,10 +89,11 @@ echo "🗑️ Cleaning inbox and logs..." rm -f "$TARGET_DIR/inbox/"*.jsonl 2>/dev/null || true rm -f "$TARGET_DIR/logs/"* 2>/dev/null || true -# ── 重启服务 ── +# ── 重启服务 ──(trap EXIT 也会执行,但这里显式做一次) echo "" echo "▶️ Starting $PM2_NAME..." pm2 start "$PM2_NAME" +trap - EXIT # 清除 trap,避免重复执行 # ── 完成 ── echo ""