![为什么我已启用 systemd 计时器,但它仍显示在非活动计时器中?](https://linux22.com/image/1693202/%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E5%B7%B2%E5%90%AF%E7%94%A8%20systemd%20%E8%AE%A1%E6%97%B6%E5%99%A8%EF%BC%8C%E4%BD%86%E5%AE%83%E4%BB%8D%E6%98%BE%E7%A4%BA%E5%9C%A8%E9%9D%9E%E6%B4%BB%E5%8A%A8%E8%AE%A1%E6%97%B6%E5%99%A8%E4%B8%AD%EF%BC%9F.png)
我创建了以下 SystemD 计时器和服务并启用了该计时器:
$ sudo install -vpm 644 ncc-record.* /usr/local/lib/systemd/system/
'ncc-record.service' -> '/usr/local/lib/systemd/system/ncc-record.service'
'ncc-record.timer' -> '/usr/local/lib/systemd/system/ncc-record.timer'
$ sudo systemctl daemon-reload
$ systemctl cat ncc-record.*
# /usr/local/lib/systemd/system/ncc-record.service
[Unit]
Description=Record the New Creation Church Live sermon
After=network-online.target
[Service]
Type=oneshot
User=sebastien
Group=sebastien
#UMask=026
ExecStart=/home/sebastien/myScripts/shl/record_NCC_Live_Then_Suspend.sh
# /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
$ sudo systemctl enable ncc-record.timer
Created symlink /etc/systemd/system/timers.target.wants/ncc-record.timer → /usr/local/lib/systemd/system/ncc-record.timer.
$
我的计时器没有显示在活动计时器中:
$ systemctl list-timers | grep ncc
$
但它在非活动计时器中显示没有关于 NEXT、LEFT、LAST 和 PASSED 时间的信息:
$ systemctl list-timers --state=inactive | grep ncc
n/a n/a n/a n/a ncc-record.timer ncc-record.service
$
我怎样才能解决这个问题 ?
答案1
systemctl enable
永远不会立即激活一个单元 –systemctl start
这样做。这同样适用于计时器、服务和任何其他单元类型。
唯一要做systemctl enable
的就是根据[Install]
部分创建符号链接,以便该单元变为活动状态下次启动时(或者,更确切地说,每当下次启动“timers.target”时)。
systemctl enable --now
如果您想通过一个命令启用并启动一个单元,请使用。