Files
story/deploy/server/install-monitoring.sh
T

30 lines
1.2 KiB
Bash
Raw Normal View History

2026-08-26 20:41:26 +08:00
#!/usr/bin/env bash
set -Eeuo pipefail
if [[ ${EUID:-$(id -u)} -ne 0 ]]; then
echo "Run this installer as root" >&2
exit 2
fi
project_root=${PLATFORM_ROOT:-/opt/data-terminal-cloud/current}
install -d -m 0700 /etc/data-terminal-cloud
install -d -m 0750 /var/lib/data-terminal-cloud-monitor
if [[ ! -s /etc/data-terminal-cloud/monitor-webhook-secret ]]; then
umask 077
openssl rand -base64 48 >/etc/data-terminal-cloud/monitor-webhook-secret
fi
chmod 0600 /etc/data-terminal-cloud/monitor-webhook-secret
if [[ ! -e /etc/data-terminal-cloud/monitor.env ]]; then
cat >/etc/data-terminal-cloud/monitor.env <<'EOF'
ALERT_WEBHOOK_URL=
ALERT_WEBHOOK_SECRET_FILE=/etc/data-terminal-cloud/monitor-webhook-secret
EOF
fi
chmod 0600 /etc/data-terminal-cloud/monitor.env
install -m 0644 "$project_root/deploy/server/platform-health-monitor.service" /etc/systemd/system/platform-health-monitor.service
install -m 0644 "$project_root/deploy/server/platform-health-monitor.timer" /etc/systemd/system/platform-health-monitor.timer
systemctl daemon-reload
systemctl enable --now platform-health-monitor.timer
systemctl is-active --quiet platform-health-monitor.timer
echo "platform-health-monitor.timer enabled"