Skip to content

Instantly share code, notes, and snippets.

@dnegi-dev
Last active April 1, 2023 19:33
Show Gist options
  • Save dnegi-dev/7c6ed0611cb8f85e3f7545e44a6c0d67 to your computer and use it in GitHub Desktop.
Save dnegi-dev/7c6ed0611cb8f85e3f7545e44a6c0d67 to your computer and use it in GitHub Desktop.
Systemd Timers

Systemd Timer Example

Create systemd timer file

$ vi /etc/systemd/system/<TIMER_NAME>.timer
[Unit]
Description=<Describe your Timer>

[Timer]
OnCalendar=*-*-* *:00:00 # Runs every Year-Month-Day Hour:Minute:Second
Persistent=true          # Run service after boot when time has been missed

[Install]
WantedBy=timers.target

Create systemd service file

If timer and service file have the same name, the activated timer will automatically trigger the service file.

$ vi /etc/systemd/system/<SERVICE_NAME>.service
[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/usr/local/bin/example.sh

If names of the service and timer file don`t match, use following part in the service file

[Timer]
Unit=example.timer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment