我已经创建了一个 SystemD 计时器来触发服务,但是虽然已启用,但在 PC 重启或恢复后,计时器并未启动:
$ sudo reboot
....AFTER reboot...
$ systemctl is-enabled ncc-record.timer
enabled
$ systemctl is-active ncc-record.timer
inactive
$ systemctl cat ncc-record.timer
# /usr/local/lib/systemd/system/ncc-record.timer
[Unit]
Description=Trigger the service record.service
[Timer]
OnCalendar=Sun *-*-* 11:29:30
[Install]
WantedBy=timers.target
$ systemctl status ncc-record.timer
○ ncc-record.timer - Trigger the service record.service
Loaded: loaded (/usr/local/lib/systemd/system/ncc-record.timer; enabled; vendor preset: enabled)
Active: inactive (dead)
Trigger: n/a
Triggers: ● ncc-record.service
$
EDIT0:我在计时器每个部分的最后一条指令后添加了一个换行符,并将计时器移入/lib/systemd/system/
:
$ sudo mv -v /usr/local/lib/systemd/system/ncc-record.timer /lib/systemd/system/ncc-record.timer
copied '/usr/local/lib/systemd/system/ncc-record.timer' -> '/lib/systemd/system/ncc-record.timer'
removed '/usr/local/lib/systemd/system/ncc-record.timer'
$ sudo systemctl daemon-reload
$ systemctl cat ncc-record.timer
# /lib/systemd/system/ncc-record.timer
[Unit]
Description=Trigger the service record.service
[Timer]
OnCalendar=Sun 8:29:30
[Install]
WantedBy=timers.target
$ sudo systemctl disable ncc-record.timer;sudo systemctl enable ncc-record.timer
Removed /etc/systemd/system/timers.target.wants/ncc-record.timer.
Created symlink /etc/systemd/system/timers.target.wants/ncc-record.timer → /lib/systemd/system/ncc-record.timer.
$ sudo systemctl start ncc-record.timer
$ sudo reboot
.........AFTER REBOOT
$ systemctl is-active ncc-record.timer
inactive
$ journalctl -u ncc-record.timer -b
sept. 04 20:47:49 seb-EB1501P systemd[1]: ncc-record.timer: Refusing to start, unit ncc-record.service to trigger not loaded.
sept. 04 20:47:49 seb-EB1501P systemd[1]: Failed to start Trigger the service record.service.
$ last reboot -1
reboot system boot 6.2.0-31-generic Mon Sep 4 20:47 still running
wtmp begins Thu Jun 8 19:31:53 2023
$ systemd-analyze verify /etc/systemd/system/timers.target.wants/ncc-record.timer
$ systemd-analyze calendar "Sun 8:29:30"
Original form: Sun 8:29:30
Normalized form: Sun *-*-* 08:29:30
Next elapse: Sun 2023-09-10 08:29:30 CEST
(in UTC): Sun 2023-09-10 06:29:30 UTC
From now: 5 days left
$ sudo systemctl start ncc-record.timer
Job failed. See "journalctl -xe" for details.
$ journalctl -xe -u ncc-record.timer | tail -9
sept. 04 21:23:46 seb-EB1501P systemd[1]: ncc-record.timer: Refusing to start, unit ncc-record.service to trigger not loaded.
sept. 04 21:23:46 seb-EB1501P systemd[1]: Failed to start Trigger the service record.service.
░░ Subject: A start job for unit ncc-record.timer has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A start job for unit ncc-record.timer has finished with a failure.
░░
░░ The job identifier is 3152 and the job result is failed.
$
EDIT1:我还添加了将服务移动到/lib/systemd/system/
计时器的同一目录中(),问题解决了:)