summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2020-03-03 17:39:53 +0100
committerValentin Rothberg <rothberg@redhat.com>2020-03-03 17:39:53 +0100
commit05a0bf7c07e53a3142fb4e6d1bb71e60ee16e5c9 (patch)
treef3527eedb5d34a78e230fb696513733db35adc14
parent3bc5f431d4df9724501a42a68e333f7e98a0b0cf (diff)
downloadpodman-05a0bf7c07e53a3142fb4e6d1bb71e60ee16e5c9.tar.gz
podman-05a0bf7c07e53a3142fb4e6d1bb71e60ee16e5c9.tar.bz2
podman-05a0bf7c07e53a3142fb4e6d1bb71e60ee16e5c9.zip
generate systemd: add network dependencies
Add network dependencies to generated systemd services to allow for enabling them at system startup and have a working network if needed. Fixes: #4130 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
-rw-r--r--pkg/systemd/generate/systemdgen.go2
-rw-r--r--pkg/systemd/generate/systemdgen_test.go10
2 files changed, 12 insertions, 0 deletions
diff --git a/pkg/systemd/generate/systemdgen.go b/pkg/systemd/generate/systemdgen.go
index 404347828..999a65126 100644
--- a/pkg/systemd/generate/systemdgen.go
+++ b/pkg/systemd/generate/systemdgen.go
@@ -80,6 +80,8 @@ const containerTemplate = `# {{.ServiceName}}.service
[Unit]
Description=Podman {{.ServiceName}}.service
Documentation=man:podman-generate-systemd(1)
+Wants=network.target
+After=network-online.target
{{- if .BoundToServices}}
RefuseManualStart=yes
RefuseManualStop=yes
diff --git a/pkg/systemd/generate/systemdgen_test.go b/pkg/systemd/generate/systemdgen_test.go
index b74b75258..a68a02d33 100644
--- a/pkg/systemd/generate/systemdgen_test.go
+++ b/pkg/systemd/generate/systemdgen_test.go
@@ -40,6 +40,8 @@ func TestCreateContainerSystemdUnit(t *testing.T) {
[Unit]
Description=Podman container-639c53578af4d84b8800b4635fa4e680ee80fd67e0e6a2d4eea48d1e3230f401.service
Documentation=man:podman-generate-systemd(1)
+Wants=network.target
+After=network-online.target
[Service]
Restart=always
@@ -58,6 +60,8 @@ WantedBy=multi-user.target`
[Unit]
Description=Podman container-foobar.service
Documentation=man:podman-generate-systemd(1)
+Wants=network.target
+After=network-online.target
[Service]
Restart=always
@@ -76,6 +80,8 @@ WantedBy=multi-user.target`
[Unit]
Description=Podman container-foobar.service
Documentation=man:podman-generate-systemd(1)
+Wants=network.target
+After=network-online.target
RefuseManualStart=yes
RefuseManualStop=yes
BindsTo=a.service b.service c.service pod.service
@@ -98,6 +104,8 @@ WantedBy=multi-user.target`
[Unit]
Description=Podman pod-123abc.service
Documentation=man:podman-generate-systemd(1)
+Wants=network.target
+After=network-online.target
Requires=container-1.service container-2.service
Before=container-1.service container-2.service
@@ -118,6 +126,8 @@ WantedBy=multi-user.target`
[Unit]
Description=Podman jadda-jadda.service
Documentation=man:podman-generate-systemd(1)
+Wants=network.target
+After=network-online.target
[Service]
Restart=always