我正在运行sync.timer
和sync.service
单元文件systemd 245 (245.4-4ubuntu3.13)
。该服务运行一个简单的 curl 脚本 ( /bin/sync.sh
),并计划在美国东部标准时间凌晨 1 点至凌晨 3 点之间的某个时间通过计时器每晚运行。
这些已在过去几天设置如下:
# sync.service
[Unit]
Description=Run sync
Requires=another.service
[Service]
TimeoutStartSec=1200
Type=oneshot
ExecStart=/bin/sync.sh
User=auto
RemainAfterExit=yes
# sync.timer
[Unit]
Description=Run sync daily between 1am - 3am EST
[Timer]
OnCalendar=*-*-* 01:00:00 America/New_York
Unit=sync.service
RandomizedDelaySec=2hr
[Install]
WantedBy=timers.target
当我最初创建这些单元文件时,它按预期在第二天07:45:14 UTC(美国东部标准时间 02:45 AM)运行。但是,该服务从第 2 天开始以某种方式在 00:02:xx UTC 运行,而不是在指定的时间范围内(请注意计时器LAST
在06:42:14 UTC
( 01:42 AM EST
)的位置是正确journalctl
的,但服务单元表示它在00:02:26 UTC
最近一次运行时运行)
# systemctl list-timers
NEXT LEFT LAST PASSED UNIT ACTIVATES
...
n/a n/a Tue 2021-11-16 06:42:14 UTC 17h ago sync.timer sync.service
# journalctl -u sync.service
-- Logs begin at Thu 2021-11-11 21:02:16 UTC, end at Wed 2021-11-17 00:06:30 UTC. --
Nov 13 07:45:14 host-16core systemd[1]: Starting sync
...
Nov 16 00:02:26 host-16core systemd[1]: Starting sync
...
Nov 17 00:02:03 host-16core systemd[1]: Starting sync
# timer status
sync.timer - Run sync daily between 1am - 3am EST
Loaded: loaded (/etc/systemd/system/sync.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Fri 2021-11-12 18:20:23 UTC; 4 days ago
Trigger: n/a
Triggers: ● sync.service
Nov 12 18:20:23 host-16core systemd[1]: Started Run sync daily between 1am - 3am EST.
# service status
● sync.service - Run sync
Loaded: loaded (/etc/systemd/system/sync.service; static; vendor preset: enabled)
Active: active (exited) since Wed 2021-11-17 00:02:04 UTC; 15min ago
TriggeredBy: ● sync.timer
Process: 440319 ExecStart=/bin/sync.sh (code=exited, status=0/SUCCESS)
Main PID: 440319 (code=exited, status=0/SUCCESS)
Nov 17 00:02:03 host-16core systemd[1]: Starting Run sync
我有几个问题:
- 当计时器仍按计划运行时,为什么
ACTIVATE
和LEFT
列具有价值?n/a
- 为什么同步服务日志的时间戳 (00:02 AM UTC) 与计时器的
LAST
列 (06:42 AM UTC) 不匹配? - 为什么同步服务在 2AM UTC 重复运行?
编辑:将计时器的配置更新为以下但仍然看到相同的行为:
[Timer]
OnCalendar=
OnCalendar=*-*-* 06:00:00
Unit=sync.service
RandomizedDelaySec=7200