Systemd Service timers

Aus xinux.net
Zur Navigation springen Zur Suche springen

List Timers

  • systemctl list-timers
NEXT                         LEFT        LAST                         PASSED        UNIT                         ACTIVATES
n/a                          n/a         Di 2017-10-24 17:02:48 CEST  2 days ago    ureadahead-stop.timer        ureadahead-stop.service
Fr 2017-10-27 18:18:28 CEST  8h left     Fr 2017-10-27 09:14:16 CEST  24min ago     apt-daily.timer              apt-daily.service
Fr 2017-10-27 22:41:17 CEST  13h left    Mi 2017-10-25 14:51:49 CEST  1 day 18h ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Mo 2017-10-30 04:07:40 CET   2 days left Di 2017-10-24 14:36:05 CEST  2 days ago    snapd.refresh.timer          snapd.refresh.service

4 timers listed.
Pass --all to see loaded but inactive timers, too.

Monotonic timer

Example

A timer which will start 15 minutes after boot and again every week while the system is running.

  • cat /etc/systemd/system/foo.timer
[Unit]
Description=Run foo weekly and on boot

[Timer]
OnBootSec=15min
OnUnitActiveSec=1w 

[Install]
WantedBy=timers.target
  • Wenn systemctl status foo.timer "trigger: n/a" ausgibt, muss man den service neustarten
  • systemctl restart foo.service

Realtime timer

Example

When activated, it triggers the service immediately if it missed the last start time (option Persistent=true), for example due to the system being powered off:

Links