我正在尝试将 systemd 计时器设置为在工作周内每天运行两次。一次是早上 7:00,一次是下午 1:00。*.timer 和 *.service 文件如下。
我安装并启用它们,一切正常:
cp callboot-update.service /etc/systemd/system
cp callboot-update.timer /etc/systemd/system
if ! systemctl enable callboot-update.service; then
echo "Failed to enable callboot-update.service"
exit 1
fi
if ! systemctl enable callboot-update.timer; then
echo "Failed to enable callboot-update.timer"
exit 1
fi
并重新加载守护进程。再次一切正常:
if ! systemctl daemon-reload; then
echo "Failed to daemon-reload"
fi
if ! systemctl reset-failed; then
echo "Failed to reset-failed"
fi
但是,检查状态显示计时器处于 n/a 状态,并且未计划运行:
$ systemctl list-timers --all
NEXT LEFT LAST PASSED UNIT ACTIVATES
Wed 2019-12-25 03:02:08 EST 6h left Tue 2019-12-24 03:02:05 EST 17h ago system-update.timer system-update.service
Wed 2019-12-25 04:02:07 EST 7h left Tue 2019-12-24 04:09:05 EST 16h ago auto-update.timer auto-update.service
Wed 2019-12-25 06:46:46 EST 9h left Tue 2019-12-24 06:39:05 EST 14h ago apt-daily-upgrade.timer apt-daily-upgrade.service
Wed 2019-12-25 06:50:27 EST 9h left Tue 2019-12-24 18:30:05 EST 2h 23min ago apt-daily.timer apt-daily.service
Wed 2019-12-25 10:55:43 EST 14h left Tue 2019-12-24 13:22:24 EST 7h ago motd-news.timer motd-news.service
Wed 2019-12-25 16:46:06 EST 19h left Tue 2019-12-24 16:46:06 EST 4h 7min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Mon 2019-12-30 00:00:00 EST 5 days left Mon 2019-12-23 00:00:11 EST 1 day 20h ago fstrim.timer fstrim.service
n/a n/a n/a n/a callboot-update.timer callboot-update.service
如何使计时器脱离 n/a 状态,使其按预期开始运行?
$ ls -Al /etc/systemd/system/callboot-*
-rw-r--r-- 1 root root 234 Dec 24 20:38 /etc/systemd/system/callboot-update.service
-rw-r--r-- 1 root root 222 Dec 24 20:38 /etc/systemd/system/callboot-update.timer
$ cat callboot-update.timer
[Unit]
Description=Run Callboot update.service
[Timer]
OnCalendar=Mon..Fri *-*-* 07:00:00
OnCalendar=Mon..Fri *-*-* 13:00:00
RandomizedDelaySec=3000
Persistent=true
[Install]
WantedBy=timers.target
$ cat callboot-update.service
[Unit]
Description=Update Callboot without user prompts
[Service]
Type=oneshot
ExecStart=/usr/sbin/callboot-update
[Install]
WantedBy=multi-user.target