refactor(core): Enable Systemd and upgrade Sentinel service orchestration

The legacy crontabs have been superseded by Systemd to fortify orchestration of our global fleet of Sentinels.

While cron relies on timed, fire-and-forget execution, Systemd elevates our operations into natively integrated, state-aware OS daemons. This paradigm shift unlocks precise lifecycle management, unified logging (inspect all service logs with `journalctl -t ip-sentinel`), and absolute control over module deployment.

- Battle-Hardened: Sentinels now auto-resurrect upon failure, bypassing minute-long cron wait times.
- Zero-Impact Missions: Sentinels now operate under strict `idle` CPU/IO scheduling. This guarantees that automated maintenance cycles yield to high-priority user interactions, and never impact primary server workloads.
- Field Intelligence Auto-Stagger: Service-level `RandomizedDelaySec` natively staggers Agent check-ins to protect the Command Center.
- Legacy Fallback: OS interrogation on deployment ensures a seamless fallback to cron for Sentinels operating in Alpine/OpenRC environments.

The fleet is more resilient than ever, but the architecture is always evolving. I highly welcome any reviews/suggestions from the original Author/Commander to perfect this pull request!
This commit is contained in:
IcySteam
2026-04-20 19:07:20 +10:00
parent e77b7c0319
commit 2d680c5fc7
4 changed files with 264 additions and 47 deletions

View File

@@ -34,19 +34,32 @@ if [[ ! "$CONFIRM_DEL" =~ ^[Yy]$ ]]; then
exit 0
fi
# 1. 停止运行中的 Master 守护进程
echo "[1/3] 正在终止后台中枢调度进程..."
# 1. 停止并删除 Systemd 服务
echo "[1/4] 正在停止并删除 Systemd 服务..."
if command -v systemctl >/dev/null 2>&1; then
echo "[1/4] 💡 检测到 Systemd 环境,正在删除 Systemd 服务单元..."
systemctl disable --now ip-sentinel-master.service >/dev/null 2>&1
rm -f /etc/systemd/system/ip-sentinel-master.service
systemctl daemon-reload
systemctl reset-failed
else
echo "[1/4] 💡 未检测到 Systemd跳过此步骤..."
fi
# 2. 停止运行中的 Master 守护进程
echo "[2/4] 正在终止后台中枢调度进程..."
# [优化] 使用 pkill 替代 pgrep | xargs指令更短、容错率更高
pkill -9 -f "tg_master.sh" >/dev/null 2>&1 || true
# 2. 清除看门狗定时任务 (Cron)
echo "[2/3] 正在清理系统定时任务 (Cron)..."
# 3. 清除看门狗定时任务 (Cron)
echo "[3/4] 正在清理系统定时任务 (Cron)..."
crontab -l 2>/dev/null | grep -v "tg_master.sh" > /tmp/cron_backup
crontab /tmp/cron_backup
rm -f /tmp/cron_backup
# 3. 删除所有文件、配置与数据库
echo "[3/3] 正在抹除核心程序、配置文件与 SQLite 数据库..."
# 4. 删除所有文件、配置与数据库
echo "[4/4] 正在抹除核心程序、配置文件与 SQLite 数据库..."
if [ -d "$MASTER_DIR" ]; then
rm -rf "$MASTER_DIR"
fi