52 lines
1.6 KiB
Bash
Executable File
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
|