我正在尝试systemd
向 Debian 10 机器添加定期服务。基本上我希望它每周清理一次数据库。我可以确认服务文件在运行时有效:
# systemctl start cleanup-service
即:
[Unit]
Description=Remove old entries from database
Requires=mysql.service
After=mysql.service
OnFailure=unit-status-mail@%n.service
[Service]
Type=oneshot
EnvironmentFile=/etc/environment
ExecStart=<some command>
我从另一个正常运行的计时器复制而来,
[Unit]
Description=Run cleanup-service periodically
[Timer]
OnCalendar=*-*-* 14:08:00
[Install]
WantedBy=timers.target
但是,当我运行时:
# systemctl enable cleanup-service.timer
$ systemctl --all
相关内容如下:
backup-service.timer loaded active waiting Run backup-service service periodically
cleanup-service.timer loaded inactive dead Run cleanup-service service periodically
我不知道该如何诊断这个问题。所有权限都一样。服务器可能需要重新启动,但必须在其他时间进行。除了重新启动之外,我不知道还能尝试什么。
我是否忽略了其中的一些微妙之处systemd
?
您没有
systemctl start
(或enable --now
)计时器。启动一个单元就是激活它。