forked from linux/documentation
44 lines
1.6 KiB
Markdown
44 lines
1.6 KiB
Markdown
# Systemd Timers for Regular Tasks
|
|
|
|
|
|
## Create New Timer
|
|
|
|
To have custom executables run regularly on given time/interval, you may use the `base::timers` Hiera key:
|
|
|
|
```
|
|
base::timers:
|
|
'timer_test':
|
|
description: 'test timers'
|
|
command: '/usr/bin/logger foo'
|
|
on_calendar: '*:*:10'
|
|
timer_options:
|
|
persistence: false
|
|
service_options:
|
|
Environment: 'SOME_ENV=some_value'
|
|
User: 'svcusr-logger'
|
|
service_unit_options:
|
|
OnSuccess: 'dnf-automatic'
|
|
OnFailure: 'send-failure-email'
|
|
```
|
|
|
|
This then creates both the required timer and service unit files for systemd.
|
|
|
|
For each timer following keys are mandatory
|
|
|
|
- `description` for a short explanation what it is about
|
|
- `command` for the command to run
|
|
- `on_calendar` defining when it should run using the [`systemd` calendar event format](https://www.freedesktop.org/software/systemd/man/systemd.time.html#Calendar%20Events), (alternatively see also chapter "CALENDAR EVENTS" of `man systemd.date`)
|
|
|
|
Optional is
|
|
|
|
- `timer_options` for additional configuration in the `Timer` section of the timer unit. In the example it is `persistence` which signals if the timer should run immediately after boot when the node was switched of on the last scheduled run time (default is `false`).
|
|
- `service_options` for additional configuration in the `Service` section of the service unit.
|
|
- `service_unit_options` for additional options in the `Unit` section of the service unit.
|
|
|
|
## Enable/Disable Existing Timer
|
|
```
|
|
base::timers:
|
|
'certbot':
|
|
enable: true
|
|
```
|