Skip to content

Commit

Permalink
generate systemd: add default.target to INSTALL
Browse files Browse the repository at this point in the history
When enabling a systemd service we can specify which target will start
it by specifying it in the `[INSTALL]` section.  In case of root, this
is commonly set to `multi-user.target` which is used to start other
essential system services such as the network manager, D-BUS and more.

However, the `multi-user.target` is not enough on all systems,
especially when running rootless and enabling user services.  Multiple
users have reported issues that there isn't even an attempt to start the
service.

Setting the INSTALL target to `default.target` will fix the rootless
case.  However, `default.target` may vary among systems.  Fedora
Workstation, for instance, sets the `default.target` to the graphical
target (i.e., runlevel 5) while Fedora Server sets it to
`multi-user.target` which is on runlevel 2 and hence way earlier in the
startup sequence.

As INSTALL allows for specifying multiple INSTALL targets, we can set it
to `multi-user.target` to continue supporting existing workloads AND to
`default.target` which MAY redundantly attempt to start it at a later point;
effectively a NOP for the root case and essential for rootless.

Fixes: #5423
Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg committed Mar 9, 2020
1 parent f378e82 commit 220f9a7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions docs/source/markdown/podman-generate-systemd.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ Create and print a systemd unit file for a container running nginx with an *alwa
$ podman create --name nginx nginx:latest
$ podman generate systemd --restart-policy=always -t 1 nginx
# container-de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6.service
# autogenerated by Podman 1.5.2
# Wed Aug 21 09:46:45 CEST 2019
# autogenerated by Podman 1.8.0
# Wed Mar 09 09:46:45 CEST 2020
[Unit]
Description=Podman container-de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6.service
Expand All @@ -58,7 +58,7 @@ Type=forking
PIDFile=/run/user/1000/overlay-containers/de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6/userdata/conmon.pid
[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target default.target
```

Create systemd unit files for a pod with two simple alpine containers. Note that these container services cannot be started or stopped individually via `systemctl`; they are managed by the pod service. You can still use `systemctl status` or journalctl to examine them.
Expand All @@ -72,8 +72,8 @@ $ podman generate systemd --files --name systemd-pod
/home/user/container-jolly_shtern.service
$ cat pod-systemd-pod.service
# pod-systemd-pod.service
# autogenerated by Podman 1.5.2
# Wed Aug 21 09:52:37 CEST 2019
# autogenerated by Podman 1.8.0
# Wed Mar 09 09:52:37 CEST 2020
[Unit]
Description=Podman pod-systemd-pod.service
Expand All @@ -90,7 +90,7 @@ Type=forking
PIDFile=/run/user/1000/overlay-containers/ccfd5c71a088768774ca7bd05888d55cc287698dde06f475c8b02f696a25adcd/userdata/conmon.pid
[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target default.target
```

## SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion pkg/systemd/generate/systemdgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ KillMode=none
Type=forking
[Install]
WantedBy=multi-user.target`
WantedBy=multi-user.target default.target`

// Options include different options to control the unit file generation.
type Options struct {
Expand Down
10 changes: 5 additions & 5 deletions pkg/systemd/generate/systemdgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ KillMode=none
Type=forking
[Install]
WantedBy=multi-user.target`
WantedBy=multi-user.target default.target`

goodName := `# container-foobar.service
# autogenerated by Podman CI
Expand All @@ -72,7 +72,7 @@ KillMode=none
Type=forking
[Install]
WantedBy=multi-user.target`
WantedBy=multi-user.target default.target`

goodNameBoundTo := `# container-foobar.service
# autogenerated by Podman CI
Expand All @@ -96,7 +96,7 @@ KillMode=none
Type=forking
[Install]
WantedBy=multi-user.target`
WantedBy=multi-user.target default.target`

podGoodName := `# pod-123abc.service
# autogenerated by Podman CI
Expand All @@ -118,7 +118,7 @@ KillMode=none
Type=forking
[Install]
WantedBy=multi-user.target`
WantedBy=multi-user.target default.target`

goodNameNew := `# jadda-jadda.service
# autogenerated by Podman CI
Expand All @@ -140,7 +140,7 @@ KillMode=none
Type=forking
[Install]
WantedBy=multi-user.target`
WantedBy=multi-user.target default.target`

tests := []struct {
name string
Expand Down

0 comments on commit 220f9a7

Please sign in to comment.