tldr

tdrgr: test driven red green refactor

19 February 2023 · tags:

Systemd Timers

Systemd timers

This post is to reflect on systemd timers, replacing cron jobs, monitoring, useful references.

Cron jobs

Cron jobs is easy to understand scheduler standard unix scheduler. Common commands are:

Systemd Timers

Systemd timers is a great replacement of cron jobs, however a tad more complicated.

Timer types

One-off transient timer can be activated as:

Timers live in /var/lib/systemd/timers Timers are designed to work with services. For each .timer file, a matching .service file exists. For example:

Definition

cat ./system/timers.target.wants/test-minute.timer
[Unit]
Description=Test timer: every minute

[Timer]
OnCalendar=*-*-* *:*:00
Persistent=true


[Install]
WantedBy=timers.target

Service

cat /lib/systemd/system/test-minute.service
[Unit]
Description=test minute timer %a %H

[Service]
Type=oneshot
ExecStart=/bin/true
#User=nobody
Group=systemd-journal

Timer Control

Monitoring

journalctl -r |grep  test-minute|head
Feb 19 13:32:01 <host> systemd[1]: test-minute.service: Succeeded.
Feb 19 13:31:01 <host> systemd[1]: test-minute.service: Succeeded.

Nits

References

These are great resources about systemd timers: