Link to this headingTimers

wiki.archlinux.org/title/Systemd/Timers
https://systemd-by-example.com/

Link to this headingMaking a Timer with a Service

Run 15mins after boot and then every week

Monotonic timer from a Service:

>>> cat /etc/systemd/system/acme_update.service # This service unit is for testing timer units # By David Both # Licensed under GPL V2 # [Unit] Description=Logs system statistics to the systemd journal Wants=myMonitor.timer [Service] Type=oneshot ExecStart=/usr/bin/free [Install] WantedBy=multi-user.target >>> cat /etc/systemd/system/acme_update.timer [Unit] Description=Logs some system statistics to the systemd journal Requires=myMonitor.service [Timer] Unit=myMonitor.service OnCalendar=*-*-* *:*:00 [Install] WantedBy=timers.target

Still run the command immediately after boot if the computer was turned off during that time.

Realtime timer:

>>> cat /etc/systemd/system/acme_letsencrypt.timer [Unit] Description=Weekly renewal of Let's Encrypt's certificates [Timer] OnCalendar=weekly RandomizedDelaySec=3h Persistent=true [Install] WantedBy=timers.target

Link to this headingRunning a Timer

Run a Timer:

sudo systemctl start <timer-unit-name>.timer

Testing that the Timer ran:

sudo systemctl status <timer-unit-name>.timer

Link to this headingMake Timer without service

Run in 30 seconds:

systemd-run --on-active=30 /bin/touch /tmp/foo

Run in 30 seconds after boot:

systemd-run --on-boot=30 /bin/touch /tmp/foo

Run every week:

systemd-run --on-calendar=weekly /bin/touch /tmp/foo

Link to this headingCheck Timers

systemctl list-timers

Link to this headingMake a User Timer

  1. Make a service for a user at ~/.config/systemd/user/SERVICE_NAME.service
  2. Make a timer for the service at ~/.config/systemd/user/SERVICE_NAME.timer
  3. Reload systemd systemctl --user daemon-reload
  4. Start timer systemctl --user enable --now SERVICE_NAME.timer
  5. Check timer is enabled systemctl --user list-timers

Example Timer:

[Unit] Description=Run myscript.sh daily at 10:30 AM [Timer] OnCalendar=10:30 Persistent=true [Install] WantedBy=timers.target