修复otelcol无限重启

This commit is contained in:
2026-06-12 23:39:29 +08:00
parent fe30396544
commit cd49cb0106
3 changed files with 55 additions and 3 deletions

View File

@@ -242,6 +242,47 @@ sync_otelcol_install() {
fi
}
ensure_otelcol_runtime() {
if [[ "${ENABLE_OTELCOL:-true}" != "true" ]]; then
return
fi
if [[ "${DRY_RUN}" == "true" ]]; then
echo "+ ensure system user/group otelcol"
echo "+ install -d -m 0755 -o otelcol -g otelcol /var/lib/otelcol"
echo "+ install -d -m 0755 -o root -g root /etc/otelcol"
echo "+ install -d -m 0755 -o genarrative -g genarrative /var/log/genarrative"
echo "+ install -m 0644 deploy/otelcol/genarrative-debug.yaml /etc/otelcol/genarrative-debug.yaml"
return
fi
if ! getent group otelcol >/dev/null 2>&1; then
groupadd --system otelcol
fi
if ! id otelcol >/dev/null 2>&1; then
useradd --system --gid otelcol --home-dir /var/lib/otelcol --shell /usr/sbin/nologin otelcol
fi
install -d -m 0755 -o otelcol -g otelcol /var/lib/otelcol
install -d -m 0755 -o root -g root /etc/otelcol
install -d -m 0755 -o genarrative -g genarrative /var/log/genarrative
install -m 0644 deploy/otelcol/genarrative-debug.yaml /etc/otelcol/genarrative-debug.yaml
chown root:root /etc/otelcol/genarrative-debug.yaml
}
stamp_database_backup_timer_now() {
if [[ "${DRY_RUN}" == "true" ]]; then
echo "+ install -d -m 0755 /var/lib/systemd/timers"
echo "+ touch /var/lib/systemd/timers/stamp-genarrative-database-backup.timer"
return
fi
install -d -m 0755 /var/lib/systemd/timers
# 避免 provision 在当天 03:20 之后启动 timer 时因 Persistent=true 立刻补跑冷备份、
# 进而在初始化/发布窗口中意外停止 spacetimedb.service。
touch /var/lib/systemd/timers/stamp-genarrative-database-backup.timer
}
sync_spacetime_install() {
local root_dir="$1"
local target_bin_dir="${root_dir}/bin/current"
@@ -823,6 +864,7 @@ ensure_api_runtime_env_defaults
if [[ "${ENABLE_OTELCOL:-true}" == "true" ]]; then
sync_otelcol_install
ensure_otelcol_runtime
otelcol_service="$(mktemp)"
render_otelcol_service >"${otelcol_service}"
install_file "${otelcol_service}" /etc/systemd/system/otelcol-contrib.service 0644
@@ -842,7 +884,9 @@ if [[ "${ENABLE_SERVICES}" == "true" ]]; then
if [[ "${ENABLE_OTELCOL:-true}" == "true" ]]; then
run_cmd systemctl enable otelcol-contrib.service
fi
stamp_database_backup_timer_now
run_cmd systemctl enable spacetimedb.service genarrative-api.service genarrative-database-backup.timer genarrative-health-patrol.timer
run_cmd systemctl start genarrative-database-backup.timer
if [[ "${ENABLE_OTELCOL:-true}" == "true" ]]; then
run_cmd systemctl restart otelcol-contrib.service
fi
@@ -856,4 +900,4 @@ if [[ "${ENABLE_SERVICES}" == "true" ]]; then
fi
fi
echo "[server-provision] 完成。若是首次初始化,请补齐 ${API_ENV_FILE} 的真实密钥后再启动 api-server。"
echo "[server-provision] 完成。若是首次初始化,请补齐 ${API_ENV_FILE} 的真实密钥后再启动 api-server。"