furniture-3d-system-Wu/furniture-3d-system/scripts/install-modular-processing-generation-health-timer.sh
apple ad3d572813 feat(modular-processing): 完善生成监控、异常预警与主表冻结
部件缺口不再阻断整批生成;持久化生成状态并向系统管理员预警;页面展示失败原因与净缺口;冻结条码及之前字段;补充迁移和回归测试。
2026-11-07 11:11:23 +08:00

52 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
BASE="${FURNITURE_PROD_BASE:-/opt/furniture-3d-system-prod}"
APP_ROOT="$BASE/current/furniture-3d-system"
SERVICE_NAME="${MODULAR_PROCESSING_HEALTH_SERVICE_NAME:-furniture-modular-processing-generation-health}"
CALENDAR="${MODULAR_PROCESSING_HEALTH_CALENDAR:-*-*-* *:0/5:00}"
if [ "$(id -u)" -ne 0 ]; then
echo "This installer requires root." >&2
exit 1
fi
if [ ! -f "$APP_ROOT/scripts/check-modular-processing-generation-health.ts" ]; then
echo "Missing deployed health-check script: $APP_ROOT/scripts/check-modular-processing-generation-health.ts" >&2
exit 1
fi
if [ ! -f "$BASE/shared/.env" ]; then
echo "Missing production env file: $BASE/shared/.env" >&2
exit 1
fi
cat >"/etc/systemd/system/$SERVICE_NAME.service" <<EOF
[Unit]
Description=Check modular product processing order generation health
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
WorkingDirectory=$APP_ROOT
Environment=NODE_ENV=production
Environment=TZ=Asia/Shanghai
EnvironmentFile=$BASE/shared/.env
ExecStart=/bin/bash -lc 'exec ./node_modules/.bin/tsx scripts/check-modular-processing-generation-health.ts'
TimeoutStartSec=10min
EOF
cat >"/etc/systemd/system/$SERVICE_NAME.timer" <<EOF
[Unit]
Description=Check modular product processing order generation health every five minutes
[Timer]
OnCalendar=$CALENDAR
Persistent=true
AccuracySec=30s
Unit=$SERVICE_NAME.service
[Install]
WantedBy=timers.target
EOF
systemctl daemon-reload
systemctl enable --now "$SERVICE_NAME.timer"
systemctl list-timers --all "$SERVICE_NAME.timer" --no-pager