timer systemd ogni 8 ore
Sep 08 2020
Sono abbastanza nuovo nell'usare i timer di systemd e sto riscontrando alcuni problemi.
Sto cercando di programmare uno script che venga eseguito ogni giorno, ogni 8 ore, alle 6:00, alle 14:00 e alle 22:00. L'ora si avvia correttamente e mostra l'ora pianificata successiva per l'esecuzione (cosa che fa), ma poi non sembra mai eseguire la terza (o qualsiasi altra) volta. Che cosa sto facendo di sbagliato?
Ho questo nel mio timer:
[Unit]
Description=Run every 8 hours
Requires=script.service
[Timer]
OnCalendar=*-*-* 03,11,19:00:00
Persistent=true
[Install]
WantedBy=timers.target
Ho provato anche questo:
[Unit]
Description=Run every 8 hours
Requires=script.service
[Timer]
OnCalendar=*-*-* 03,11,19:00:00
OnUnitActiveSec=1d
Persistent=true
[Install]
WantedBy=timers.target
E questo:
[Unit]
Description=Run every 8 hours
Requires=script.service
[Timer]
OnCalendar=*-*-* 03:00:00
OnCalendar=*-*-* 11:00:00
OnCalendar=*-*-* 19:00:00
Persistent=true
[Install]
WantedBy=timers.target
Servizio:
[Unit]
Description=Renews Kerberos ticket every 8 hours
After=network-online.target firewalld.service
Wants=network-online.target script.timer
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/usr/bin/kdestroy
ExecStart=/usr/bin/kinit -R -V [email protected] -k -t /etc/krb5.keytab
IOSchedulingClass=best-effort
[Install]
WantedBy=default.target
'''
Risposte
1 ajgringo619 Sep 08 2020 at 06:49
OK, credo che il problema sia con il file script.service . Secondo la systemd.timerpagina man:
DESCRIPTION
Note that in case the unit to activate is already active at the time the timer elapses it is not restarted, but simply left running. There is no concept of spawning new service instances in this case. Due to this, services
with RemainAfterExit= set (which stay around continuously even after the service's main process exited) are usually not suitable for activation via repetitive timers, as they will only be activated once, and then stay
around forever.
Rimuovi la RemainAfterExit=linea e dovresti essere a posto.