document how to run a command on boot

This commit is contained in:
2024-12-19 10:51:50 +01:00
parent fe5475e0fb
commit 81e218ddb6
3 changed files with 42 additions and 22 deletions
+1
View File
@@ -73,6 +73,7 @@ chapters:
sections:
- file: admin-guide/configuration/software/packages
- file: admin-guide/configuration/software/services
- file: admin-guide/configuration/software/timers
- file: admin-guide/configuration/software/selinux_configuration
- file: admin-guide/configuration/software/package_updates
- file: admin-guide/configuration/software/package_repositories
+18 -22
View File
@@ -22,28 +22,6 @@ base::services:
enable: false
```
## Systemd Timers
To have custom executables run regulary 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
```
For each timer following keys are mandatory
- `description` for a short explaination 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 options. 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`).
## Manage Services with Custom Unit Files
It is also possible to provide a full systemd unit file if there is none already. For this define the different secions and their content with subkeys below the `options` key as in below example:
@@ -102,4 +80,22 @@ base::services:
If there are multiple dropins, you might also name them individually with the `dropin_name` parameter.
## Run Command on Startup
If a command should run only once at boot time you may create a `oneshot` service with `RemainAfterExit` and have one or more commands ready in `ExecStart`:
```
base::services:
tuned_setup:
enable: true
options:
Unit:
After: 'tuned.service'
Install:
WantedBy: 'multi-user.target'
Service:
Type: 'oneshot'
ExecStart:
- '/usr/sbin/tuned-adm active'
- '/usr/sbin/tuned-adm profile virtual-host'
RemainAfterExit: 'true'
```
@@ -0,0 +1,23 @@
# Systemd Timers for Regular Tasks
To have custom executables run regulary 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
```
For each timer following keys are mandatory
- `description` for a short explaination 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 options. 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`).