@@ -109,16 +109,86 @@ WantedBy=default.target
109109
110110Currently, 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
113119words ` WantedBy=other.service ` , not ` WantedBy=other.container ` . The same is
114120true 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 "basename@instancename.service "
126+ when they are running, but that can be instantiated multiple times
127+ from a single "basename@.service" 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, "foo@.container" will generate "foo@.service" and you can
134+ then "systemctl start foo@bar.service ".
135+
136+ Secondly, if you make a symlink like "foo@instance.container ", 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+ (foo@instance.container.d ) and the template directory
140+ (foo@.container.d). This allows customization of individual instances.
141+
142+ Instanced template files (like ` foo@bar.container ` ) can be enabled
143+ just like non-templated ones. However, templated ones
144+ (` foo@.container ` ) 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 ` sleep@.container ` 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 ` sleep@100.service `
170+ running that sleeps for 100 seconds. You can then do something like
171+ ` systemctl start sleep@50.service ` to start another instance that
172+ sleeps 50 seconds, or alternatively another service can start it via a
173+ dependency like ` Wants=sleep@50.service ` .
174+
175+ In addition, if you do ` ln -s sleep@.container sleep@10.container ` 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 ` sleep@10.container.d/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
123193View the generated files and/or error messages with:
124194```
0 commit comments