.nh .TH podman-generate-systemd 1 .SH NAME .PP podman-generate-systemd - [DEPRECATED] Generate systemd unit file(s) for a container or pod .SH SYNOPSIS .PP \fBpodman generate systemd\fP [\fIoptions\fP] \fIcontainer|pod\fP .SH DESCRIPTION .PP DEPRECATED: Note: \fBpodman generate systemd\fP is deprecated. We recommend using [Quadlet] files when running Podman containers or pods under systemd. There are no plans to remove the command. It will receive urgent bug fixes but no new features. .PP \fBpodman generate systemd\fP creates a systemd unit file that can be used to control a container or pod. By default, the command prints the content of the unit files to stdout. .PP Generating unit files for a pod requires the pod to be created with an infra container (see \fB--infra=true\fR). An infra container runs across the entire lifespan of a pod and is hence required for systemd to manage the life cycle of the pod's main unit. .RS .IP \(bu 2 Note: When using this command with the remote client, including Mac and Windows (excluding WSL2) machines, place the generated units on the remote system. Moreover, make sure that the \fBXDG_RUNTIME_DIR\fR environment variable is set. If unset, set it via \fBexport XDG_RUNTIME_DIR=/run/user/$(id -u)\fR\&._ .IP \(bu 2 Note: The generated \fBpodman run\fR command contains an \fB--sdnotify\fR option with the value taken from the container. If the container does not have any explicitly set value or the value is set to \fBignore\fP, the value \fBconmon\fP is used. The reason for overriding the default value \fBcontainer\fP is that almost no container workloads send notify messages. Systemd waits for a ready message that never comes, if the value \fBcontainer\fP is used for a container that does not send notify messages. The use of the default value might have been unintentional by the user, therefore the overridden default value._ .RE .SS Kubernetes Integration .PP A Kubernetes YAML can be executed in systemd via the \fBpodman-kube@.service\fR systemd template. The template's argument is the path to the YAML file. Given a \fBworkload.yaml\fR file in the home directory, it can be executed as follows: .EX $ escaped=$(systemd-escape ~/workload.yaml) $ systemctl --user start podman-kube@$escaped.service $ systemctl --user is-active podman-kube@$escaped.service active .EE .SH OPTIONS .SS \fB--after\fP=\fIdependency_name\fP .PP Add the systemd unit after (\fBAfter=\fR) option, that ordering dependencies between the list of dependencies and this service. This option may be specified more than once. .PP User-defined dependencies are appended to the generated unit file, but any existing options needed or defined by default (e.g., \fBonline.target\fR) are \fBnot\fP removed or overridden. .SS \fB--container-prefix\fP=\fIprefix\fP .PP Set the systemd unit name prefix for containers. The default is \fIcontainer\fP\&. .SS \fB--env\fP, \fB-e\fP=\fIenv\fP .PP Set environment variables to the systemd unit files. .PP If an environment variable is specified without a value, Podman checks the host environment for a value and sets the variable only if it is set on the host. As a special case, if an environment variable ending in \fB*\fP is specified without a value, Podman searches the host environment for variables starting with the prefix and adds those variables to the systemd unit files. .SS \fB--files\fP, \fB-f\fP .PP Generate files instead of printing to stdout. The generated files are named {container,pod}-{ID,name}.service and are placed in the current working directory. .PP Note: On a system with SELinux enabled, the generated files inherits contexts from the current working directory. Depending on the SELinux setup, changes to the generated files using \fBrestorecon\fR, \fBchcon\fR, or \fBsemanage\fR may be required to allow systemd to access these files. Alternatively, use the \fB-Z\fR option when running \fBmv\fR or \fBcp\fR\&. .SS \fB--format\fP=\fIformat\fP .PP Print the created units in the specified format (json). If \fB--files\fR is specified, the paths to the created files are printed instead of the unit content. .SS \fB--name\fP, \fB-n\fP .PP Use the name of the container for the start, stop, and description in the unit file .SS \fB--new\fP .PP This option yields unit files that do not expect containers and pods to exist. Instead, new containers and pods are created based on their configuration files. The unit files are created best effort and may need further editing; please review the generated files carefully before using them in production. .PP Note that \fB--new\fR only works on containers and pods created directly via Podman (i.e., \fBpodman [container] {create,run}\fR or \fBpodman pod create\fR). It does not work on containers or pods created via the REST API or via \fBpodman kube play\fR\&. For \fBpodman kube play\fR, use the \fBpodman-kube@.service\fR systemd template instead. .SS \fB--no-header\fP .PP Do not generate the header including meta data such as the Podman version and the timestamp. .SS \fB--pod-prefix\fP=\fIprefix\fP .PP Set the systemd unit name prefix for pods. The default is \fIpod\fP\&. .SS \fB--requires\fP=\fIdependency_name\fP .PP Set the systemd unit requires (\fBRequires=\fR) option. Similar to wants, but declares a stronger requirement dependency. .SS \fB--restart-policy\fP=\fIpolicy\fP .PP Set the systemd restart policy. The restart-policy must be one of: "no", "on-success", "on-failure", "on-abnormal", "on-watchdog", "on-abort", or "always". The default policy is \fIon-failure\fP unless the container was created with a custom restart policy. .PP Note that generating a unit without \fB--new\fR on a container with a custom restart policy can lead to issues on shutdown; systemd attempts to stop the unit while Podman tries to restart it. Creating the container without \fB--restart\fR and using the \fB--restart-policy\fR option when generating the unit file is recommended. .SS \fB--restart-sec\fP=\fItime\fP .PP Set the systemd service restartsec value. Configures the time to sleep before restarting a service (as configured with restart-policy). Takes a value in seconds. .SS \fB--separator\fP=\fIseparator\fP .PP Set the systemd unit name separator between the name/id of a container/pod and the prefix. The default is \fI-\fP\&. .SS \fB--start-timeout\fP=\fIvalue\fP .PP Override the default start timeout for the container with the given value in seconds. .SS \fB--stop-timeout\fP=\fIvalue\fP .PP Override the default stop timeout for the container with the given value in seconds. .SS \fB--template\fP .PP Add template specifiers to run multiple services from the systemd unit file. .PP Note that if \fB--new\fR was not set to true, it is set to true by default. However, the command fails if \fB--new\fR is set to \fBfalse\fR explicitly. .SS \fB--wants\fP=\fIdependency_name\fP .PP Add the systemd unit wants (\fBWants=\fR) option, that this service is (weak) dependent on. This option may be specified more than once. This option does not influence the order in which services are started or stopped. .PP User-defined dependencies are appended to the generated unit file, but any existing options needed or defined by default (e.g., \fBonline.target\fR) are \fBnot\fP removed or overridden. .SH EXAMPLES .SS Generate and print a systemd unit file for a container .PP Generate a systemd unit file for a container running nginx with an \fIalways\fP restart policy and 1-second timeout to stdout. Note that the \fBRequiresMountsFor\fP option in the \fBUnit\fP section ensures that the container storage for both the GraphRoot and the RunRoot are mounted prior to starting the service. For systems with container storage on disks like iSCSI or other remote block protocols, this ensures that Podman is not executed prior to any necessary storage operations coming online. .EX $ podman create --name nginx nginx:latest $ podman generate systemd --restart-policy=always -t 1 nginx # container-de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6.service # autogenerated by Podman 1.8.0 # Wed Mar 09 09:46:45 CEST 2020 [Unit] Description=Podman container-de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6.service Documentation=man:podman-generate-systemd(1) Wants=network-online.target After=network-online.target RequiresMountsFor=/var/run/container/storage [Service] Restart=always ExecStart=/usr/bin/podman start de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6 ExecStop=/usr/bin/podman stop -t 1 de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6 KillMode=none Type=forking PIDFile=/run/user/1000/overlay-containers/de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6/userdata/conmon.pid [Install] WantedBy=default.target .EE .SS Generate systemd unit file for a container with \fB--new\fR flag .PP The \fB--new\fR flag generates systemd unit files that create and remove containers at service start and stop commands (see ExecStartPre and ExecStopPost service actions). Such unit files are not tied to a single machine and can easily be shared and used on other machines. .EX $ sudo podman generate systemd --new --files --name bb310a0780ae # container-busy_moser.service # autogenerated by Podman 1.8.3 # Fri Apr 3 09:40:47 EDT 2020 [Unit] Description=Podman container-busy_moser.service Documentation=man:podman-generate-systemd(1) Wants=network-online.target After=network-online.target RequiresMountsFor=/var/run/container/storage [Service] Environment=PODMAN_SYSTEMD_UNIT=%n Restart=on-failure ExecStartPre=/bin/rm -f %t/%n-pid %t/%n-cid ExecStart=/usr/local/bin/podman run --conmon-pidfile %t/%n-pid --cidfile %t/%n-cid --cgroups=no-conmon -d -dit alpine ExecStop=/usr/local/bin/podman stop --ignore --cidfile %t/%n-cid -t 10 ExecStopPost=/usr/local/bin/podman rm --ignore -f --cidfile %t/%n-cid PIDFile=%t/%n-pid KillMode=none Type=forking [Install] WantedBy=default.target .EE .SS Generate systemd unit files for a pod with two simple alpine containers .PP Note \fBsystemctl\fR must only be used on the pod unit and not used to start or stop containers individually. The containers are managed by the pod service along with the internal infra-container. .PP Use \fBsystemctl status\fR or \fBjournalctl\fR to examine container or pod unit files. .EX $ podman pod create --name systemd-pod $ podman create --pod systemd-pod alpine top $ podman create --pod systemd-pod alpine top $ podman generate systemd --files --name systemd-pod /home/user/pod-systemd-pod.service /home/user/container-amazing_chandrasekhar.service /home/user/container-jolly_shtern.service $ cat pod-systemd-pod.service # pod-systemd-pod.service # autogenerated by Podman 1.8.0 # Wed Mar 09 09:52:37 CEST 2020 [Unit] Description=Podman pod-systemd-pod.service Documentation=man:podman-generate-systemd(1) Requires=container-amazing_chandrasekhar.service container-jolly_shtern.service Before=container-amazing_chandrasekhar.service container-jolly_shtern.service Wants=network-online.target After=network-online.target RequiresMountsFor=/var/run/container/storage [Service] Restart=on-failure ExecStart=/usr/bin/podman start 77a818221650-infra ExecStop=/usr/bin/podman stop -t 10 77a818221650-infra KillMode=none Type=forking PIDFile=/run/user/1000/overlay-containers/ccfd5c71a088768774ca7bd05888d55cc287698dde06f475c8b02f696a25adcd/userdata/conmon.pid [Install] WantedBy=default.target .EE .SS Installation of generated systemd unit files. .PP Podman-generated unit files include an \fB[Install]\fR section, which carries installation information for the unit. It is used by the enable and disable commands of systemctl(1) during installation. .PP Once the systemd unit file is generated, install it to \fI/etc/systemd/system\fP to be run by the root user or to \fI$HOME/.config/systemd/user\fP for installing it as a non-root user. Enable the copied unit file or files using \fBsystemctl enable\fR\&. .PP Note: Copying unit files to \fI/etc/systemd/system\fP and enabling it marks the unit file to be automatically started at boot. And similarly, copying a unit file to \fI$HOME/.config/systemd/user\fP and enabling it marks the unit file to be automatically started on user login. .EX # Generated systemd files. $ podman pod create --name systemd-pod $ podman create --pod systemd-pod alpine top $ podman generate systemd --files --name systemd-pod # Copy all the generated files. $ sudo cp pod-systemd-pod.service container-great_payne.service /etc/systemd/system $ systemctl enable pod-systemd-pod.service Created symlink /etc/systemd/system/multi-user.target.wants/pod-systemd-pod.service → /etc/systemd/system/pod-systemd-pod.service. Created symlink /etc/systemd/system/default.target.wants/pod-systemd-pod.service → /etc/systemd/system/pod-systemd-pod.service. $ systemctl is-enabled pod-systemd-pod.service enabled .EE .PP To run the user services placed in \fB$HOME/.config/systemd/user\fR on first login of that user, enable the service with --user flag. .EX $ systemctl --user enable <.service> .EE .PP The systemd user instance is killed after the last session for the user is closed. The systemd user instance can be started at boot and kept running even after the user logs out by enabling \fBlingering\fR using .EX $ loginctl enable-linger .EE .SS Use \fBsystemctl\fR to perform operations on generated installed unit files. .PP Create and enable systemd unit files for a pod using the above examples as reference and use \fBsystemctl\fR to perform operations. .PP Since systemctl defaults to using the root user, all the changes using the systemctl can be seen by appending sudo to the podman cli commands. To perform \fBsystemctl\fR actions as a non-root user use the \fB--user\fR flag when interacting with \fBsystemctl\fR\&. .PP Note: If the previously created containers or pods are using shared resources, such as ports, make sure to remove them before starting the generated systemd units. .EX $ systemctl --user start pod-systemd-pod.service $ podman pod ps POD ID NAME STATUS CREATED # OF CONTAINERS INFRA ID 0815c7b8e7f5 systemd-pod Running 29 minutes ago 2 6c5d116f4bbe $ sudo podman ps # 0 Number of pods on root. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES $ systemctl stop pod-systemd-pod.service $ podman pod ps POD ID NAME STATUS CREATED # OF CONTAINERS INFRA ID 272d2813c798 systemd-pod Exited 29 minutes ago 2 6c5d116f4bbe .EE .PP Create a simple alpine container and generate the systemd unit file with \fB--new\fR flag. Enable the service and control operations using the systemctl commands. .PP Note: When starting the container using \fBsystemctl start\fR rather than altering the already running container it spins up a "new" container with similar configuration. .EX # Enable the service. $ sudo podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bb310a0780ae docker.io/library/alpine:latest /bin/sh 2 minutes ago Created busy_moser $ sudo systemctl start container-busy_moser.service $ sudo podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 772df2f8cf3b docker.io/library/alpine:latest /bin/sh 1 second ago Up 1 second distracted_albattani bb310a0780ae docker.io/library/alpine:latest /bin/sh 3 minutes ago Created busy_moser .EE .SH SEE ALSO .PP \fBpodman(1)\fP, \fBpodman-container(1)\fP, \fBsystemctl(1)\fP, \fBsystemd.unit(5)\fP, \fBsystemd.service(5)\fP, \fBconmon(8)\fP, \fBpodman-systemd.unit(5)\fP .SH HISTORY .PP April 2020, Updated details and added use case to use generated .service files as root and non-root, by Sujil Shah (sushah at redhat dot com) .PP August 2019, Updated with pod support by Valentin Rothberg (rothberg at redhat dot com) .PP April 2019, Originally compiled by Brent Baude (bbaude at redhat dot com)