Skip to content

Commit dc94a10

Browse files
committed
quadlet: Add documentation about template use to manpage
Signed-off-by: Alexander Larsson <[email protected]>
1 parent 01dccba commit dc94a10

File tree

1 file changed

+74
-4
lines changed

1 file changed

+74
-4
lines changed

docs/source/markdown/podman-systemd.unit.5.md

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,86 @@ WantedBy=default.target
109109

110110
Currently, only the `Alias`, `WantedBy` and `RequiredBy` keys are supported.
111111

112+
The Install section can be part of the main file, or it can be in a
113+
separate drop-in file as described above. The latter allows you to
114+
install an non-enabled unit and then later enabling it by installing
115+
the drop-in.
116+
117+
112118
**NOTE:** To express dependencies between containers, use the generated names of the service. In other
113119
words `WantedBy=other.service`, not `WantedBy=other.container`. The same is
114120
true for other kinds of dependencies, too, like `After=other.service`.
115121

122+
### Template files
123+
124+
Systemd supports a concept of [template files](https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Service%20Templates).
125+
They are units with names of the form "[email protected]"
126+
when they are running, but that can be instantiated multiple times
127+
from a single "[email protected]" file. The individual instances can
128+
also be different by using drop-in files with the full instance name.
129+
130+
Quadlets support these in two ways. First of all, a quadlet unit with
131+
a template form will generate a systemd service with a template form,
132+
and the template systemd service can be used as a regular template.
133+
For example, "[email protected]" will generate "[email protected]" and you can
134+
then "systemctl start [email protected]".
135+
136+
Secondly, if you make a symlink like "[email protected]", that
137+
will generate an instantiated template file. When generating this file
138+
quadlet will read drop-in files both from the instanced directory
139+
([email protected]) and the template directory
140+
([email protected]). This allows customization of individual instances.
141+
142+
Instanced template files (like `[email protected]`) can be enabled
143+
just like non-templated ones. However, templated ones
144+
(`[email protected]`) are different, because they need to be
145+
instantiated. If the `[Install]` section contains a `DefaultInstance=`
146+
key, then that instance will be enabled, but if not, nothing will
147+
happen and the options will only be used as the default for units
148+
that are instantiated using symlinks.
149+
150+
An example template file `[email protected]` might look like this:
151+
152+
```
153+
[Unit]
154+
Description=A templated sleepy container
155+
156+
[Container]
157+
Image=quay.io/fedora/fedora
158+
Exec=sleep %i
159+
160+
[Service]
161+
# Restart service when sleep finishes
162+
Restart=always
163+
164+
[Install]
165+
WantedBy=multi-user.target
166+
DefaultInstance=100
167+
```
168+
169+
If this is installed, then on boot there will be a `[email protected]`
170+
running that sleeps for 100 seconds. You can then do something like
171+
`systemctl start [email protected]` to start another instance that
172+
sleeps 50 seconds, or alternatively another service can start it via a
173+
dependency like `[email protected]`.
174+
175+
In addition, if you do `ln -s [email protected] [email protected]` you
176+
will also have a 10 second sleep running at boot. And, if you want
177+
that particular instance to be running with another image, you can
178+
create a drop-in file like `[email protected]/10-image.conf`:
179+
```
180+
[Container]
181+
Image=quay.io/centos/centos
182+
```
183+
116184
### Debugging unit files
117185

118-
After placing the unit file in one of the unit search paths (mentioned above), you can start it with
119-
`systemctl start {--user}`. If it fails with "Failed to start example.service: Unit example.service not found.",
120-
then it is possible that you used incorrect syntax or you used an option from a newer version of Podman
121-
Quadlet and the generator failed to create a service file.
186+
After placing the unit file in one of the unit search paths (mentioned
187+
above), you can start it with `systemctl start {--user}`. If it fails
188+
with "Failed to start example.service: Unit example.service not
189+
found.", then it is possible that you used incorrect syntax or you
190+
used an option from a newer version of Podman Quadlet and the
191+
generator failed to create a service file.
122192

123193
View the generated files and/or error messages with:
124194
```

0 commit comments

Comments
 (0)