|
| 1 | +# ansible-systemd-timer |
| 2 | + |
| 3 | +## About |
| 4 | +This roles enables you to create systemd timers which call scripts or execute commands. |
| 5 | + |
| 6 | +## Usage |
| 7 | + |
| 8 | +Define a variable ```timers```. This variable is a dictionary. Every key is a new timer. |
| 9 | + |
| 10 | +### Example |
| 11 | + |
| 12 | +Here is an example for my 1337 Telegram Bot. The Timer "calls" a script which sends the message "It's now 13:37" in one of my Telegram chats every day at 13:37 GMT o'Clock. |
| 13 | + |
| 14 | +``` |
| 15 | +timers: |
| 16 | + 1337TelegramBot: |
| 17 | + timer_command: /home/telegrambot/sendMessage.pl |
| 18 | + timer_user: telegrambot |
| 19 | + timer_OnCalendar: "*-*-* 13:37:00 CET" |
| 20 | + timer_AccuracySec: 5s |
| 21 | +``` |
| 22 | + |
| 23 | +That's all the magic. |
| 24 | + |
| 25 | +### Existing variables |
| 26 | + |
| 27 | +| Variable | Required | Default value / Explanation | |
| 28 | +|----------|----------|------------------------------| |
| 29 | +| timer_command | yes | Which command or script to execute | |
| 30 | +| timer_user | no | Under which users the timer_command is executed. Default: root | |
| 31 | +| timer_persistent | no | Takes a boolean argument. If true, the time when the service unit was last triggered is stored on disk. When the timer is activated, the service unit is triggered immediately if it would have been triggered at least once during the time when the timer was inactive. This is useful to catch up on missed runs of the service when the machine was off. Note that this setting only has an effect on timers configured with OnCalendar=. Defaults to false. [Source](https://www.freedesktop.org/software/systemd/man/systemd.timer.html) | |
| 32 | +| timer_OnActiveSec | no | Relative time after the timer unit was last activated | |
| 33 | +| timer_OnBootSec | no | Relative time after the computer was booted | |
| 34 | +| timer_OnStartupSec | no | Relative time after systemd was started | |
| 35 | +| timer_OnUnitActiveSec | no | Relative time after the service unit was last activated | |
| 36 | +| timer_OnUnitInactiveSec | no | Relative time after the service unit was last deactivated | |
| 37 | +| timer_OnCalendar | no | Absolute time when to call activate the unit | |
| 38 | +| timer_AccuracySec | no | Timer have a default accuracy of round about one minute. You can set the accuracy with this var. Default: 15s | |
| 39 | + |
| 40 | +You can chain every timer_On* variable. Example: |
| 41 | + |
| 42 | +``` |
| 43 | +timers: |
| 44 | + updateDNS: |
| 45 | + timer_command: /home/dnsupdate/updateMe.pl |
| 46 | + timer_user: dnsupdate |
| 47 | + timer_OnStartupSec: 20s |
| 48 | + timer_OnUnitActiveSec: 5m |
| 49 | +``` |
| 50 | + |
| 51 | +The timer unit will be triggered 20 seconds after systemd was started and then every 5 minutes. |
| 52 | + |
| 53 | +More about timers: https://www.freedesktop.org/software/systemd/man/systemd.timer.html |
| 54 | + |
| 55 | +More about timespans: https://www.freedesktop.org/software/systemd/man/systemd.time.html |
0 commit comments