SystemD - Timer

About

To start a service at a scheduled time

Doc: systemd.timer

Management

Start

The matching .service is:

  • by default the name of the timer (e.g. foo.service for foo.timer)
  • or is specified in the [Timer] section by the Unit= option

Example:

  • Realtime timer (Timer units with at least one OnCalendar= directive will have an additional After= dependency on time-sync.target to avoid being started before the system clock has been correctly set.)
[Unit]
Description=Hourly rotation of log files
Documentation=man:logrotate(8) man:logrotate.conf(5)

[Install]
WantedBy=timers.target

[Timer]
OnCalendar=hourly
Persistent=true
AccuracySec=1min
  • for a Monotonic timer the timer section should be someting like that
[Timer]
OnBootSec=5min
OnUnitActiveSec=30min
  • Copy the unit file and reload the daemon
cp logrotate.timer /lib/systemd/system/
sudo systemctl daemon-reload
  • Enable
sudo systemctl enable logrotate.timer
Created symlink from /etc/systemd/system/timers.target.wants/logrotate.timer to /usr/lib/systemd/system/logrotate.timer.

  • Start
sudo systemctl start logrotate.timer

Status

sudo systemctl status logrotate.timer

List

  • Only active
sudo systemctl list-timers
NEXT                         LEFT       LAST                         PASSED       UNIT                         ACTIVATES
Thu 2019-03-07 13:47:23 UTC  29min left Thu 2019-03-07 13:17:23 UTC  21s ago      logrotate.timer              logrotate.service

  • all timers (including inactive)
sudo systemctl list-timers --all

Log

sudo journalctl -u logrotate.timer







Share this page:
Follow us:
Task Runner