我正在测试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
替代文件(/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
我运行了以下命令,计时器仍然每5分钟滴答一次。systemd中可能有错误吗?
sudo systemctl stop snapbackend.timer
sudo systemctl daemon-reload
sudo systemctl start snapbackend.timer
所以我也想知道,我怎么知道下一个计时器何时开始计时?因为那会立即告诉我是否在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
systemctl list-timers
帮助输出吗?