Systemd/timers: Difference between revisions
imported>Papanito m add missing space |
imported>Skylark Copyedit, don't like to potentially out-of-date copy of manpage |
||
| Line 1: | Line 1: | ||
Timers are systemd unit files whose name ends in .timer that control .service files or events. Timers can be used as an alternative to cron. Timers have built-in support for calendar | Timers are systemd unit files whose name ends in .timer that control .service files or events. Timers can be used as an alternative to <code>cron</code>. Timers have built-in support for calendar-based events and monotonic time events, and can be run asynchronously. | ||
== Configuration == | == Configuration == | ||
The following example timer runs a systemd unit every 5 minutes which invokes a bash script. | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 27: | Line 27: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
The following example | The following example starts once a day (at 12:00am). When activated, it triggers the service immediately if it missed the last start time (option Persistent=true), for example due to the system being powered off. | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 38: | Line 38: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
More examples can be found at the [https://wiki.archlinux.org/title/Systemd/Timers Arch Wiki] and at the <code>systemd.timer</code> manpage. | |||
== Usage == | == Usage == | ||
List active timers and their current state | List active timers and their current state: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
| Line 48: | Line 48: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Manually run service once for testing | Manually run a service once for testing purposes: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
systemctl start hello-world | systemctl start hello-world | ||
</syntaxhighlight> | </syntaxhighlight> | ||