cheatsheet:systemdtimer

Timers

Create a service

[Unit]
Description=IPv6 monitoring

[Service]
User=root
ExecStart=/usr/local/bin/test-ip6

[Install]
WantedBy=basic.target

Create a timer with the same name but suffixed with .timer

[Unit]
Description=Run test-ip6 every 10 minutes

[Timer]
OnBootSec=10min
OnUnitActiveSec=10min
Unit=test.service

[Install]
WantedBy=timers.target

Timer options:

  • OnBootSec: duration after boot before starting the service
  • OnUnitActiveSec: duration between two executions
  • Unit: define unit to use but by default look for the same name .service file
  • OnCalendar:Control the timer like a cron task
  • AccuracySec: define execution window
  • Persistent (Default is false): If true, it will do as anacron and store last execution to be detect if run is needed after inactivity (like when the device is powered off)

Enable the timer:

systemctl enable --now test.timer
  • cheatsheet/systemdtimer.txt
  • Last modified: 2024/10/14 20:59
  • by 127.0.0.1