fix(deploy): install_ops_cron 自动安装 cron 包
生产 Azure 主机默认无 crontab,安装脚本现会 apt install cron 并启用服务。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -26,6 +26,29 @@ if [[ "$(id -u)" -ne 0 ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
ensure_crontab() {
|
||||||
|
if command -v crontab >/dev/null 2>&1; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
warn "未检测到 crontab,尝试安装 cron 包…"
|
||||||
|
if command -v apt-get >/dev/null 2>&1; then
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
apt-get update -qq
|
||||||
|
apt-get install -y -qq cron
|
||||||
|
systemctl enable --now cron 2>/dev/null || systemctl enable --now crond 2>/dev/null || true
|
||||||
|
elif command -v yum >/dev/null 2>&1; then
|
||||||
|
yum install -y cronie
|
||||||
|
systemctl enable --now crond 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
if ! command -v crontab >/dev/null 2>&1; then
|
||||||
|
error "无法安装 crontab(请手动: apt install cron)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
info "cron 已安装"
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_crontab
|
||||||
|
|
||||||
for f in "${DEPLOY_DIR}/health_monitor.sh" "${DEPLOY_DIR}/db_backup.sh"; do
|
for f in "${DEPLOY_DIR}/health_monitor.sh" "${DEPLOY_DIR}/db_backup.sh"; do
|
||||||
if [[ ! -f "$f" ]]; then
|
if [[ ! -f "$f" ]]; then
|
||||||
error "缺少脚本: $f"
|
error "缺少脚本: $f"
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
3. **db_backup.sh**:Docker 生产路径,从 Nexus 容器/volume 解析 `NEXUS_DATABASE_URL`,默认 `/var/backups/nexus`。
|
3. **db_backup.sh**:Docker 生产路径,从 Nexus 容器/volume 解析 `NEXUS_DATABASE_URL`,默认 `/var/backups/nexus`。
|
||||||
4. **install_ops_cron.sh**(新):幂等写入 `health_monitor`(每分钟)与 `db_backup`(每日 03:00)crontab。
|
4. **install_ops_cron.sh**(新):幂等写入 `health_monitor`(每分钟)与 `db_backup`(每日 03:00)crontab。
|
||||||
5. **nx**:菜单 `[e]` / 子命令 `nx cron` 安装上述 cron。
|
5. **nx**:菜单 `[e]` / 子命令 `nx cron` 安装上述 cron。
|
||||||
|
6. **install_ops_cron**:宿主机无 `crontab` 时自动 `apt install cron` 并启用服务。
|
||||||
|
|
||||||
## 涉及文件
|
## 涉及文件
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user