Ale*_*lke 25 systemd systemd-timer
我正在测试一个 systemd 计时器并尝试覆盖其默认超时,但没有成功。我想知道是否有办法让 systemd 告诉我们接下来要运行该服务的时间。
普通文件 ( /lib/systemd/system/snapbackend.timer
):
# Documentation available at:
# https://www.freedesktop.org/software/systemd/man/systemd.timer.html
[Unit]
Description=Run the snapbackend service once every 5 minutes.
[Timer]
# You must have an OnBootSec (or OnStartupSec) otherwise it does not auto-start
OnBootSec=5min
OnUnitActiveSec=5min
# The default accuracy is 1 minute. I'm not too sure that either way
# will affect us. I am thinking that since our computers will be
# permanently running, it probably won't be that inaccurate anyway.
# See also:
# http://stackoverflow.com/questions/39176514/is-it-correct-that-systemd-timer-accuracysec-parameter-make-the-ticks-slip
#AccuracySec=1
[Install]
WantedBy=timers.target
# vim: syntax=dosini
Run Code Online (Sandbox Code Playgroud)
覆盖文件 ( /etc/systemd/system/snapbackend.timer.d/override.conf
):
# This file was auto-generated by snapmanager.cgi
# Feel free to do additional modifications here as
# snapmanager.cgi will be aware of them as expected.
[Timer]
OnUnitActiveSec=30min
Run Code Online (Sandbox Code Playgroud)
我运行了以下命令,计时器仍然每 5 分钟滴答一次。systemd 可能有错误吗?
sudo systemctl stop snapbackend.timer
sudo systemctl daemon-reload
sudo systemctl start snapbackend.timer
Run Code Online (Sandbox Code Playgroud)
所以我也想知道,我怎么知道下一个计时器会在什么时候打勾?因为那会立即告诉我是否在 5 分钟内。或 30 分钟。但从systemctl status snapbackend.timer
没说什么。只是想知道是否有一个命令可以告诉我当前使用的延迟。
对于那些感兴趣的人,也有服务文件 ( /lib/systemd/system/snapbackend.service
),虽然我认为这应该对计时器滴答没有影响......
# Documentation available at:
# https://www.freedesktop.org/software/systemd/man/systemd.service.html
[Unit]
Description=Snap! Websites snapbackend CRON daemon
After=snapbase.service snapcommunicator.service snapfirewall.service snaplock.service snapdbproxy.service
[Service]
# See also the snapbackend.timer file
Type=simple
WorkingDirectory=~
ProtectHome=true
NoNewPrivileges=true
ExecStart=/usr/bin/snapbackend
ExecStop=/usr/bin/snapstop --timeout 300 $MAINPID
User=snapwebsites
Group=snapwebsites
# No auto-restart, we use the timer to start once in a while
# We also want to make systemd think that exit(1) is fine
SuccessExitStatus=1
Nice=5
LimitNPROC=1000
# For developers and administrators to get console output
#StandardOutput=tty
#StandardError=tty
#TTYPath=/dev/console
# Enter a size to get a core dump in case of a crash
#LimitCORE=10G
[Install]
WantedBy=multi-user.target
# vim: syntax=dosini
Run Code Online (Sandbox Code Playgroud)
phg*_*phg 34
可以使用systemctl list-timers
以下方式显示当前活动计时器的状态
:
$ systemctl list-timers --all
NEXT LEFT LAST PASSED UNIT ACTIVATES
Wed 2016-12-14 08:06:15 CET 21h left Tue 2016-12-13 08:06:15 CET 2h 18min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
1 timers listed.
Run Code Online (Sandbox Code Playgroud)
从@phg 评论和答案中,我找到了一个包含答案的页面。计时器是累积的,您需要先重置它们,否则之前的条目会保留。这对日历很有用,但它对所有计时器都一样。
有一个在将计时器更改为新值之前重置计时器的条目按预期工作:
# This file was auto-generated by snapmanager.cgi
# Feel free to do additional modifications here as
# snapmanager.cgi will be aware of them as expected.
[Timer]
OnUnitActiveSec=
OnUnitActiveSec=30min
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
18725 次 |
最近记录: |