systemctl 因未知部分失败 'Timer'

systemctl failing with unknown section 'Timer'

我有一个 systemctl 作业,它执行到 s3 的 vertica 备份,我想添加一个每天凌晨 3 点运行的计时器。我试图用计时器部分创建一个覆盖文件,但是当我重新加载守护进程时,出现错误“未知部分计时器”,我无法找到问题所在。

/etc/systemd/system/vertica-backup.service.d/Override.conf

[Timer]
OnCalendar=*-*-* 03:00:00
Unit=vertica-backup.service

/etc/systemd/system/vertica-backup.服务:

[Unit]
Description = Vertica Backup Service
After = network.target

[Service]
User= dbadmin
ExecStart= /usr/local/bin/vertica-backup.sh

错误

May 15 15:19:47 ip-10-150-4-42.ec2.internal systemd[1]: [/etc/systemd/system/vertica-backup.service.d/override.conf:1] Unknown section 'Timer'. Ignoring.
May 15 15:19:50 ip-10-150-4-42.ec2.internal systemd[1]: [/etc/systemd/system/vertica-backup.service.d/override.conf:1] Unknown section 'Timer'. Ignoring.

[Timer] 部分不在服务文件中,它们在自己的 .timer 文件中。创建 /etc/systemd/system/vertica-backup.timer 并将 [Timer] 部分放在那里。

参考man systemd.timer

创建定时器文件/etc/systemd/system/vertica-backup.timer

[Timer]
OnCalendar=*-*-* 03:00:00
Unit=vertica-backup.service

验证一下

sudo systemd-analyze verify /etc/systemd/system/vertica-backup.timer

启动计时器

sudo systemctl start vertica-backup.timer

# check it
systemctl list-timers --all