1podman-generate-systemd(1)()                      podman-generate-systemd(1)()
2
3
4

NAME

6       podman-generate-systemd - Generate systemd unit file(s) for a container
7       or pod. Not supported for the remote client
8
9

SYNOPSIS

11       podman generate systemd [options] container|pod
12
13

DESCRIPTION

15       podman generate systemd will create a systemd unit  file  that  can  be
16       used to control a container or pod.  By default, the command will print
17       the content of the unit files to stdout.
18
19
20       Note: If you use this command with the remote client, you  would  still
21       have to place the generated units on the remote system.
22
23

OPTIONS

25   --files, -f
26       Generate  files instead of printing to stdout.  The generated files are
27       named {container,pod}-{ID,name}.service and will be placed in the  cur‐
28       rent working directory.
29
30
31       Note:  On  a  system  with  SELinux  enabled,  the generated files will
32       inherit contexts from the current working directory. Depending  on  the
33       SELinux  setup, changes to the generated files using restorecon, chcon,
34       or semanage may be required to allow systemd  to  access  these  files.
35       Alternatively, use the -Z option when running mv or cp.
36
37
38   --format=format
39       Print the created units in specified format (json). If --files is spec‐
40       ified the paths to the created files will be  printed  instead  of  the
41       unit content.
42
43
44   --name, -n
45       Use  the  name of the container for the start, stop, and description in
46       the unit file
47
48
49   --new
50       Using this flag will yield unit files that do not expect containers and
51       pods  to  exist.  Instead, new containers and pods are created based on
52       their configuration files.  The unit files are created best effort  and
53       may  need to be further edited; please review the generated files care‐
54       fully before using them in production.
55
56
57   --time, -t=value
58       Override the default stop timeout for  the  container  with  the  given
59       value.
60
61
62   --restart-policy=policy
63       Set  the  systemd  restart  policy.  The restart-policy must be one of:
64       "no",   "on-success",   "on-failure",   "on-abnormal",   "on-watchdog",
65       "on-abort", or "always".  The default policy is on-failure.
66
67
68   --container-prefix=prefix
69       Set  the  systemd  unit name prefix for containers. The default is con‐
70       tainer.
71
72
73   --pod-prefix=prefix
74       Set the systemd unit name prefix for pods. The default is pod.
75
76
77   --separator=separator
78       Set the systemd unit name separator  between  the  name/id  of  a  con‐
79       tainer/pod and the prefix. The default is -.
80
81

EXAMPLES

83   Generate and print a systemd unit file for a container
84       Generate  a  systemd  unit  file  for a container running nginx with an
85       always restart policy and 1-second timeout to stdout.
86
87
88              $ podman create --name nginx nginx:latest
89              $ podman generate systemd --restart-policy=always -t 1 nginx
90              # container-de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6.service
91              # autogenerated by Podman 1.8.0
92              # Wed Mar 09 09:46:45 CEST 2020
93
94              [Unit]
95              Description=Podman container-de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6.service
96              Documentation=man:podman-generate-systemd(1)
97
98              [Service]
99              Restart=always
100              ExecStart=/usr/bin/podman start de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6
101              ExecStop=/usr/bin/podman stop -t 1 de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6
102              KillMode=none
103              Type=forking
104              PIDFile=/run/user/1000/overlay-containers/de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6/userdata/conmon.pid
105
106              [Install]
107              WantedBy=multi-user.target default.target
108
109
110
111   Generate systemd unit file for a container with --new flag
112       The --new flag generates systemd unit files that create and remove con‐
113       tainers  at service start and stop commands (see ExecStartPre and Exec‐
114       StopPost service actions). Such unit files are not  tied  to  a  single
115       machine and can easily be shared and used on other machines.
116
117
118              $ sudo podman generate systemd --new --files --name bb310a0780ae
119              # container-busy_moser.service
120              # autogenerated by Podman 1.8.3
121              # Fri Apr  3 09:40:47 EDT 2020
122
123              [Unit]
124              Description=Podman container-busy_moser.service
125              Documentation=man:podman-generate-systemd(1)
126              Wants=network.target
127              After=network-online.target
128
129              [Service]
130              Environment=PODMAN_SYSTEMD_UNIT=%n
131              Restart=on-failure
132              ExecStartPre=/bin/rm -f %t/%n-pid %t/%n-cid
133              ExecStart=/usr/local/bin/podman run --conmon-pidfile %t/%n-pid --cidfile %t/%n-cid --cgroups=no-conmon -d -dit alpine
134              ExecStop=/usr/local/bin/podman stop --ignore --cidfile %t/%n-cid -t 10
135              ExecStopPost=/usr/local/bin/podman rm --ignore -f --cidfile %t/%n-cid
136              PIDFile=%t/%n-pid
137              KillMode=none
138              Type=forking
139
140              [Install]
141              WantedBy=multi-user.target default.target
142
143
144
145   Generate systemd unit files for a pod with two simple alpine containers
146       Note  systemctl  should only be used on the pod unit and one should not
147       start or stop containers individually via systemctl, as they  are  man‐
148       aged by the pod service along with the internal infra-container.
149
150
151       You  can  still use systemctl status or journalctl to examine container
152       or pod unit files.
153
154
155              $ podman pod create --name systemd-pod
156              $ podman create --pod systemd-pod alpine top
157              $ podman create --pod systemd-pod alpine top
158              $ podman generate systemd --files --name systemd-pod
159              /home/user/pod-systemd-pod.service
160              /home/user/container-amazing_chandrasekhar.service
161              /home/user/container-jolly_shtern.service
162              $ cat pod-systemd-pod.service
163              # pod-systemd-pod.service
164              # autogenerated by Podman 1.8.0
165              # Wed Mar 09 09:52:37 CEST 2020
166
167              [Unit]
168              Description=Podman pod-systemd-pod.service
169              Documentation=man:podman-generate-systemd(1)
170              Requires=container-amazing_chandrasekhar.service container-jolly_shtern.service
171              Before=container-amazing_chandrasekhar.service container-jolly_shtern.service
172
173              [Service]
174              Restart=on-failure
175              ExecStart=/usr/bin/podman start 77a818221650-infra
176              ExecStop=/usr/bin/podman stop -t 10 77a818221650-infra
177              KillMode=none
178              Type=forking
179              PIDFile=/run/user/1000/overlay-containers/ccfd5c71a088768774ca7bd05888d55cc287698dde06f475c8b02f696a25adcd/userdata/conmon.pid
180
181              [Install]
182              WantedBy=multi-user.target default.target
183
184
185
186   Installation of generated systemd unit files.
187       Podman-generated unit files include an [Install] section, which carries
188       installation  information  for  the  unit. It is used by the enable and
189       disable commands of systemctl(1) during installation.
190
191
192       Once you have generated the systemd unit file, you can copy the  gener‐
193       ated  systemd file to /etc/systemd/system for installing as a root user
194       and to $HOME/.config/systemd/user for installing it as a non-root user.
195       Enable the copied unit file or files using systemctl enable.
196
197
198       Note:  Copying  unit files to /etc/systemd/system and enabling it marks
199       the unit file to be automatically started at boot. And similarly, copy‐
200       ing a unit file to $HOME/.config/systemd/user and enabling it marks the
201       unit file to be automatically started on user login.
202
203
204              # Generated systemd files.
205              $ podman pod create --name systemd-pod
206              $ podman create --pod systemd-pod alpine top
207              $ podman generate systemd --files --name systemd-pod
208
209              # Copy all the generated files.
210
211              $ sudo cp pod-systemd-pod.service container-great_payne.service /etc/systemd/system
212              $ systemctl enable pod-systemd-pod.service
213              Created symlink /etc/systemd/system/multi-user.target.wants/pod-systemd-pod.service → /etc/systemd/system/pod-systemd-pod.service.
214              Created symlink /etc/systemd/system/default.target.wants/pod-systemd-pod.service → /etc/systemd/system/pod-systemd-pod.service.
215              $ systemctl is-enabled pod-systemd-pod.service
216              enabled
217
218
219
220       To run the user services placed in $HOME/.config/systemd/user on  first
221       login of that user, enable the service with --user flag.
222
223
224              $ systemctl --user enable <.service>
225
226
227
228       The systemd user instance is killed after the last session for the user
229       is closed. The systemd user instance can be kept running ever after the
230       user logs out by enabling lingering using
231
232
233              $ loginctl enable-linger <username>
234
235
236
237   Use systemctl to perform operations on generated installed unit files.
238       Create and enable systemd unit files for a pod using the above examples
239       as reference and use systemctl to perform operations.
240
241
242       Since systemctl defaults to using the root user, all the changes  using
243       the systemctl can be seen by appending sudo to the podman cli commands.
244       To perform systemctl actions as a non-root user  use  the  --user  flag
245       when interacting with systemctl.
246
247
248              $ systemctl --user start pod-systemd-pod.service
249              $ podman pod ps
250              POD ID         NAME          STATUS    CREATED          # OF CONTAINERS   INFRA ID
251              0815c7b8e7f5   systemd-pod   Running   29 minutes ago   2                 6c5d116f4bbe
252              $ sudo podman ps # 0 Number of pods on root.
253              CONTAINER ID  IMAGE  COMMAND  CREATED  STATUS  PORTS  NAMES
254              $ systemctl stop pod-systemd-pod.service
255              $ podman pod ps
256              POD ID         NAME          STATUS   CREATED          # OF CONTAINERS   INFRA ID
257              272d2813c798   systemd-pod   Exited   29 minutes ago   2                 6c5d116f4bbe
258
259
260
261       Create  a  simple  alpine  container and generate the systemd unit file
262       with --new flag.  Enable the service and control operations  using  the
263       systemctl commands.
264
265
266       Note:  When  starting  the  container using systemctl start rather than
267       altering the already running container it spins up  a  "new"  container
268       with similar configuration.
269
270
271              # Enable the service.
272
273              $ sudo podman ps -a
274              CONTAINER ID  IMAGE                            COMMAND  CREATED        STATUS     PORTS  NAMES
275              bb310a0780ae  docker.io/library/alpine:latest  /bin/sh  2 minutes ago  Created           busy_moser
276              $ sudo systemctl start container-busy_moser.service
277              $ sudo podman ps -a
278              CONTAINER ID  IMAGE                            COMMAND  CREATED        STATUS            PORTS      NAMES
279              772df2f8cf3b  docker.io/library/alpine:latest  /bin/sh  1 second ago   Up 1 second ago              distracted_albattani
280              bb310a0780ae  docker.io/library/alpine:latest  /bin/sh  3 minutes ago  Created                      busy_moser
281
282
283

SEE ALSO

285       podman(1), systemctl(1), systemd.unit(5), systemd.service(5)
286
287

HISTORY

289       April 2020, Updated details and added usecase to use generated .service
290       files as root and non-root, by Sujil Shah (sushah at redhat dot com)
291
292
293       August 2019, Updated with pod support by Valentin Rothberg (rothberg at
294       redhat dot com)
295
296
297       April  2019,  Originally  compiled by Brent Baude (bbaude at redhat dot
298       com)
299
300
301
302                                                  podman-generate-systemd(1)()
Impressum