Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contrib/systemd: use multi-user.target instead of default.target #24524

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1001,12 +1001,6 @@ install.systemd: $(PODMAN_GENERATED_UNIT_FILES)
install ${SELINUXOPT} -m 644 $$unit $(DESTDIR)${USERSYSTEMDDIR}/$$(basename $$unit); \
install ${SELINUXOPT} -m 644 $$unit $(DESTDIR)${SYSTEMDDIR}/$$(basename $$unit); \
done
# HACK; as rootless this unit will not work due the requires on a non existing target
# as the user session does not see system units. We could define two different units
# but this seems much more complicated then this small fixup here.
# https://github.com/containers/podman/issues/23790
sed -i '/Requires=/d' $(DESTDIR)${USERSYSTEMDDIR}/podman-clean-transient.service
sed -i '/After=/d' $(DESTDIR)${USERSYSTEMDDIR}/podman-clean-transient.service

# Important this unit should only be installed for the user session and is thus not added to the loop above.
install ${SELINUXOPT} -m 644 contrib/systemd/user/podman-user-wait-network-online.service \
Expand Down
2 changes: 1 addition & 1 deletion contrib/systemd/system/podman-auto-update.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ ExecStart=@@PODMAN@@ auto-update
ExecStartPost=@@PODMAN@@ image prune -f

[Install]
WantedBy=default.target
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion contrib/systemd/system/podman-clean-transient.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ Type=oneshot
ExecStart=@@PODMAN@@ system prune --external

[Install]
WantedBy=default.target
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion contrib/systemd/system/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Type=notify
NotifyAccess=all

[Install]
WantedBy=default.target
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion contrib/systemd/system/podman-restart.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ ExecStart=@@PODMAN@@ $LOGGING start --all --filter restart-policy=always
ExecStop=/bin/sh -c '@@PODMAN@@ $LOGGING stop $(@@PODMAN@@ container ls --filter restart-policy=always -q)'

[Install]
WantedBy=default.target
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion contrib/systemd/system/podman.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ Environment=LOGGING="--log-level=info"
ExecStart=@@PODMAN@@ $LOGGING system service

[Install]
WantedBy=default.target
WantedBy=multi-user.target
1 change: 0 additions & 1 deletion contrib/systemd/user/podman-auto-update.service.in

This file was deleted.

13 changes: 13 additions & 0 deletions contrib/systemd/user/podman-auto-update.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Podman auto-update service
Documentation=man:podman-auto-update(1)
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=@@PODMAN@@ auto-update
ExecStartPost=@@PODMAN@@ image prune -f

[Install]
WantedBy=default.target
1 change: 0 additions & 1 deletion contrib/systemd/user/podman-auto-update.timer

This file was deleted.

10 changes: 10 additions & 0 deletions contrib/systemd/user/podman-auto-update.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Podman auto-update timer

[Timer]
OnCalendar=daily
RandomizedDelaySec=900
Persistent=true

[Install]
WantedBy=timers.target
1 change: 0 additions & 1 deletion contrib/systemd/user/podman-clean-transient.service.in

This file was deleted.

19 changes: 19 additions & 0 deletions contrib/systemd/user/podman-clean-transient.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This service runs once each boot to remove potential leftover
# container state from previous boots.

# This is needed when using transient storage mode in podman where the
# database and other configs are stored in tmpfs, but some other files
# are not. If we don't run this after an unclean boot then there may
# be some leftover files that grow over time.

[Unit]
Description=Clean up podman transient data
RequiresMountsFor=%t/containers
Documentation=man:podman-system-prune(1)

[Service]
Type=oneshot
ExecStart=@@PODMAN@@ system prune --external

[Install]
WantedBy=default.target
1 change: 0 additions & 1 deletion contrib/systemd/user/[email protected]

This file was deleted.

17 changes: 17 additions & 0 deletions contrib/systemd/user/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=A template for running K8s workloads via podman-kube-play
Documentation=man:podman-kube-play(1)
Wants=network-online.target
After=network-online.target
RequiresMountsFor=%t/containers

[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
TimeoutStopSec=70
ExecStart=@@PODMAN@@ kube play --replace --service-container=true %I
ExecStop=@@PODMAN@@ kube down %I
Type=notify
NotifyAccess=all

[Install]
WantedBy=default.target
1 change: 0 additions & 1 deletion contrib/systemd/user/podman-restart.service.in

This file was deleted.

16 changes: 16 additions & 0 deletions contrib/systemd/user/podman-restart.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Podman Start All Containers With Restart Policy Set To Always
Documentation=man:podman-start(1)
StartLimitIntervalSec=0
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
RemainAfterExit=true
Environment=LOGGING="--log-level=info"
ExecStart=@@PODMAN@@ $LOGGING start --all --filter restart-policy=always
ExecStop=/bin/sh -c '@@PODMAN@@ $LOGGING stop $(@@PODMAN@@ container ls --filter restart-policy=always -q)'

[Install]
WantedBy=default.target
1 change: 0 additions & 1 deletion contrib/systemd/user/podman.service.in

This file was deleted.

16 changes: 16 additions & 0 deletions contrib/systemd/user/podman.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Podman API Service
Requires=podman.socket
After=podman.socket
Documentation=man:podman-system-service(1)
StartLimitIntervalSec=0

[Service]
Delegate=true
Type=exec
KillMode=process
Environment=LOGGING="--log-level=info"
ExecStart=@@PODMAN@@ $LOGGING system service

[Install]
WantedBy=default.target
1 change: 0 additions & 1 deletion contrib/systemd/user/podman.socket

This file was deleted.

10 changes: 10 additions & 0 deletions contrib/systemd/user/podman.socket
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Podman API Socket
Documentation=man:podman-system-service(1)

[Socket]
ListenStream=%t/podman/podman.sock
SocketMode=0660

[Install]
WantedBy=sockets.target
8 changes: 4 additions & 4 deletions docs/source/markdown/podman-generate-systemd.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Type=forking
PIDFile=/run/user/1000/overlay-containers/de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6/userdata/conmon.pid

[Install]
WantedBy=default.target
WantedBy=multi-user.target
```

### Generate systemd unit file for a container with `--new` flag
Expand Down Expand Up @@ -195,7 +195,7 @@ KillMode=none
Type=forking

[Install]
WantedBy=default.target
WantedBy=multi-user.target
```

### Generate systemd unit files for a pod with two simple alpine containers
Expand Down Expand Up @@ -235,7 +235,7 @@ Type=forking
PIDFile=/run/user/1000/overlay-containers/ccfd5c71a088768774ca7bd05888d55cc287698dde06f475c8b02f696a25adcd/userdata/conmon.pid

[Install]
WantedBy=default.target
WantedBy=multi-user.target
```

### Installation of generated systemd unit files.
Expand All @@ -258,7 +258,7 @@ $ podman generate systemd --files --name systemd-pod
$ 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.
Created symlink /etc/systemd/system/multi-user.target.wants/pod-systemd-pod.service → /etc/systemd/system/pod-systemd-pod.service.
$ systemctl is-enabled pod-systemd-pod.service
enabled
```
Expand Down
9 changes: 8 additions & 1 deletion docs/source/markdown/podman-systemd.unit.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,14 @@ in order for them to become automatically enabled on the next boot.
To compensate for this, the generator manually applies the `[Install]` section of the container definition
unit files during generation, in the same way `systemctl enable` does when run later.

For example, to start a container on boot, add something like this to the file:
For example, to start a rootful container on boot, add something like this to the file:

```
[Install]
WantedBy=multi-user.target
```

To start a rootless container on boot, add the following instead:

```
[Install]
Expand Down
2 changes: 1 addition & 1 deletion pkg/systemd/generate/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ NotifyAccess={{{{.NotifyAccess}}}}
{{{{- end}}}}

[Install]
WantedBy=default.target
WantedBy=multi-user.target
`

// ContainerUnit generates a systemd unit for the specified container. Based
Expand Down
Loading