我希望apt-update计时器在星期日晚上4:30到5:30之间运行,然后立即运行apt-upgrade计时器。以下是我的设置:
cat << 'EOF' > /etc/systemd/system/apt-daily.timer
[Unit]
Description=Daily apt download activities
[Timer]
OnCalendar=Sun *-*-* 4:30:00
RandomizedDelaySec=60m
Persistent=true
[Install]
WantedBy=timers.target
EOF
cat << 'EOF' > /etc/systemd/system/apt-daily-upgrade.timer
[Unit]
Description=Daily apt upgrade and clean activities
After=apt-daily.timer
[Timer]
OnCalendar=Sun *-*-* 4:30:00
RandomizedDelaySec=60m
Persistent=true
[Install]
WantedBy=timers.target
EOF
systemctl daemon-reload
但有时会发生这种情况:
# systemctl list-timers
NEXT LEFT LAST PASSED UNIT ACTIVATES
Sun 2022-01-16 04:43:35 CET 6 days left Sun 2022-01-09 21:52:31 CET 7min ago apt-daily-upgrade.timer apt-daily-upgrade.service
Sun 2022-01-16 04:53:48 CET 6 days left Sun 2022-01-09 21:52:31 CET 7min ago apt-daily.timer apt-daily.service
systemd忽略了选项After=apt-daily.timer
。我该怎么解决?
Requires
表示依赖于另一个单元,After
/Before
则指定顺序。我编辑了答案以改善服务和定时器单元之间的清晰度。 - qq4