Existe uma maneira de saber quando um timer do systemd será executado a seguir?

8

Estou testando um timer do systemd e tentando substituir seu tempo limite padrão, mas sem sucesso. Eu estou querendo saber se existe uma maneira de pedir ao systemd para nos dizer quando o serviço será executado em seguida.

Arquivo normal ( /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

O arquivo de substituição ( /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

Eu executei os seguintes comandos e o timer ainda funciona uma vez a cada 5 minutos. Poderia haver um bug no systemd?

sudo systemctl stop snapbackend.timer
sudo systemctl daemon-reload
sudo systemctl start snapbackend.timer

Então, eu também estava me perguntando: como posso saber quando o cronômetro irá marcar em seguida? Porque isso imediatamente me diria se é em 5 min. ou 30 min. mas do systemctl status snapbackend.timer não diz nada sobre isso. Só estou querendo saber se existe um comando que me diria o atraso usado atualmente.

Para os interessados, existe também o arquivo de serviço ( /lib/systemd/system/snapbackend.service ), embora eu imagino que isso não deve afetar o cronômetro ...

# 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
    
por Alexis Wilke 13.12.2016 / 08:12

2 respostas

13

O estado dos temporizadores atualmente ativos pode ser mostrado usando 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.
    
por 13.12.2016 / 10:24
5

De @phg comentário e resposta, encontrei uma página com a resposta. Os temporizadores são cumulativos e você precisa redefini-los primeiro, caso contrário, a entrada anterior fica por perto. Isso é útil para calendários, mas funciona da mesma maneira com todos os timers.

Ter uma entrada que redefine o cronômetro antes de alterá-lo para um novo valor funciona conforme o esperado:

# 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
    
por 13.12.2016 / 10:25