mirror of
https://github.com/containers/podman.git
synced 2025-06-19 16:33:24 +08:00
Merge pull request #15777 from vrothberg/fix-14546
generate systemd: fix pod dependencies
This commit is contained in:
@ -92,7 +92,7 @@ type podInfo struct {
|
|||||||
Requires []string
|
Requires []string
|
||||||
}
|
}
|
||||||
|
|
||||||
const podTemplate = headerTemplate + `Requires={{{{- range $index, $value := .RequiredServices -}}}}{{{{if $index}}}} {{{{end}}}}{{{{ $value }}}}.service{{{{end}}}}
|
const podTemplate = headerTemplate + `Wants={{{{- range $index, $value := .RequiredServices -}}}}{{{{if $index}}}} {{{{end}}}}{{{{ $value }}}}.service{{{{end}}}}
|
||||||
Before={{{{- range $index, $value := .RequiredServices -}}}}{{{{if $index}}}} {{{{end}}}}{{{{ $value }}}}.service{{{{end}}}}
|
Before={{{{- range $index, $value := .RequiredServices -}}}}{{{{if $index}}}} {{{{end}}}}{{{{ $value }}}}.service{{{{end}}}}
|
||||||
{{{{- if or .Wants .After .Requires }}}}
|
{{{{- if or .Wants .After .Requires }}}}
|
||||||
|
|
||||||
@ -252,6 +252,7 @@ func generatePodInfo(pod *libpod.Pod, options entities.GenerateSystemdOptions) (
|
|||||||
StopTimeout: stopTimeout,
|
StopTimeout: stopTimeout,
|
||||||
GenerateTimestamp: true,
|
GenerateTimestamp: true,
|
||||||
CreateCommand: createCommand,
|
CreateCommand: createCommand,
|
||||||
|
RunRoot: infraCtr.Runtime().RunRoot(),
|
||||||
}
|
}
|
||||||
return &info, nil
|
return &info, nil
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ Documentation=man:podman-generate-systemd(1)
|
|||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
RequiresMountsFor=/var/run/containers/storage
|
RequiresMountsFor=/var/run/containers/storage
|
||||||
Requires=container-1.service container-2.service
|
Wants=container-1.service container-2.service
|
||||||
Before=container-1.service container-2.service
|
Before=container-1.service container-2.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
@ -99,7 +99,7 @@ Documentation=man:podman-generate-systemd(1)
|
|||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
RequiresMountsFor=/var/run/containers/storage
|
RequiresMountsFor=/var/run/containers/storage
|
||||||
Requires=container-1.service container-2.service
|
Wants=container-1.service container-2.service
|
||||||
Before=container-1.service container-2.service
|
Before=container-1.service container-2.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
@ -125,7 +125,7 @@ Documentation=man:podman-generate-systemd(1)
|
|||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
RequiresMountsFor=/var/run/containers/storage
|
RequiresMountsFor=/var/run/containers/storage
|
||||||
Requires=container-1.service container-2.service
|
Wants=container-1.service container-2.service
|
||||||
Before=container-1.service container-2.service
|
Before=container-1.service container-2.service
|
||||||
|
|
||||||
# User-defined dependencies
|
# User-defined dependencies
|
||||||
@ -153,7 +153,7 @@ Documentation=man:podman-generate-systemd(1)
|
|||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
RequiresMountsFor=/var/run/containers/storage
|
RequiresMountsFor=/var/run/containers/storage
|
||||||
Requires=container-1.service container-2.service
|
Wants=container-1.service container-2.service
|
||||||
Before=container-1.service container-2.service
|
Before=container-1.service container-2.service
|
||||||
|
|
||||||
# User-defined dependencies
|
# User-defined dependencies
|
||||||
@ -181,7 +181,7 @@ Documentation=man:podman-generate-systemd(1)
|
|||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
RequiresMountsFor=/var/run/containers/storage
|
RequiresMountsFor=/var/run/containers/storage
|
||||||
Requires=container-1.service container-2.service
|
Wants=container-1.service container-2.service
|
||||||
Before=container-1.service container-2.service
|
Before=container-1.service container-2.service
|
||||||
|
|
||||||
# User-defined dependencies
|
# User-defined dependencies
|
||||||
@ -209,7 +209,7 @@ Documentation=man:podman-generate-systemd(1)
|
|||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
RequiresMountsFor=/var/run/containers/storage
|
RequiresMountsFor=/var/run/containers/storage
|
||||||
Requires=container-1.service container-2.service
|
Wants=container-1.service container-2.service
|
||||||
Before=container-1.service container-2.service
|
Before=container-1.service container-2.service
|
||||||
|
|
||||||
# User-defined dependencies
|
# User-defined dependencies
|
||||||
@ -267,7 +267,7 @@ Documentation=man:podman-generate-systemd(1)
|
|||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
RequiresMountsFor=/var/run/containers/storage
|
RequiresMountsFor=/var/run/containers/storage
|
||||||
Requires=container-1.service container-2.service
|
Wants=container-1.service container-2.service
|
||||||
Before=container-1.service container-2.service
|
Before=container-1.service container-2.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
@ -294,7 +294,7 @@ Documentation=man:podman-generate-systemd(1)
|
|||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
RequiresMountsFor=/var/run/containers/storage
|
RequiresMountsFor=/var/run/containers/storage
|
||||||
Requires=container-1.service container-2.service
|
Wants=container-1.service container-2.service
|
||||||
Before=container-1.service container-2.service
|
Before=container-1.service container-2.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
@ -322,7 +322,7 @@ Documentation=man:podman-generate-systemd(1)
|
|||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
RequiresMountsFor=/var/run/containers/storage
|
RequiresMountsFor=/var/run/containers/storage
|
||||||
Requires=container-1.service container-2.service
|
Wants=container-1.service container-2.service
|
||||||
Before=container-1.service container-2.service
|
Before=container-1.service container-2.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
@ -350,7 +350,7 @@ Documentation=man:podman-generate-systemd(1)
|
|||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
RequiresMountsFor=/var/run/containers/storage
|
RequiresMountsFor=/var/run/containers/storage
|
||||||
Requires=container-1.service container-2.service
|
Wants=container-1.service container-2.service
|
||||||
Before=container-1.service container-2.service
|
Before=container-1.service container-2.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
@ -378,7 +378,7 @@ Documentation=man:podman-generate-systemd(1)
|
|||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
RequiresMountsFor=/var/run/containers/storage
|
RequiresMountsFor=/var/run/containers/storage
|
||||||
Requires=container-1.service container-2.service
|
Wants=container-1.service container-2.service
|
||||||
Before=container-1.service container-2.service
|
Before=container-1.service container-2.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
|
@ -3,6 +3,7 @@ package integration
|
|||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
. "github.com/containers/podman/v4/test/utils"
|
. "github.com/containers/podman/v4/test/utils"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
@ -220,19 +221,20 @@ var _ = Describe("Podman generate systemd", func() {
|
|||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
// Grepping the output (in addition to unit tests)
|
// Grepping the output (in addition to unit tests)
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("# pod-foo.service"))
|
output := session.OutputToString()
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("Requires=container-foo-1.service container-foo-2.service"))
|
Expect(output).To(ContainSubstring("# pod-foo.service"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("# container-foo-1.service"))
|
Expect(output).To(ContainSubstring("Wants=container-foo-1.service container-foo-2.service"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring(" start foo-1"))
|
Expect(output).To(ContainSubstring("# container-foo-1.service"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("-infra")) // infra container
|
Expect(output).To(ContainSubstring(" start foo-1"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("# container-foo-2.service"))
|
Expect(output).To(ContainSubstring("-infra")) // infra container
|
||||||
Expect(session.OutputToString()).To(ContainSubstring(" stop -t 42 foo-2"))
|
Expect(output).To(ContainSubstring("# container-foo-2.service"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("BindsTo=pod-foo.service"))
|
Expect(output).To(ContainSubstring(" stop -t 42 foo-2"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("PIDFile="))
|
Expect(output).To(ContainSubstring("BindsTo=pod-foo.service"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("/userdata/conmon.pid"))
|
Expect(output).To(ContainSubstring("PIDFile="))
|
||||||
|
Expect(output).To(ContainSubstring("/userdata/conmon.pid"))
|
||||||
|
Expect(strings.Count(output, "RequiresMountsFor="+podmanTest.RunRoot)).To(Equal(3))
|
||||||
// The podman commands in the unit should not contain the root flags
|
// The podman commands in the unit should not contain the root flags
|
||||||
Expect(session.OutputToString()).ToNot(ContainSubstring(" --runroot"))
|
Expect(output).ToNot(ContainSubstring(" --runroot"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman generate systemd pod --name --files", func() {
|
It("podman generate systemd pod --name --files", func() {
|
||||||
@ -468,7 +470,7 @@ var _ = Describe("Podman generate systemd", func() {
|
|||||||
|
|
||||||
// Grepping the output (in addition to unit tests)
|
// Grepping the output (in addition to unit tests)
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("# p-foo.service"))
|
Expect(session.OutputToString()).To(ContainSubstring("# p-foo.service"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("Requires=container-foo-1.service container-foo-2.service"))
|
Expect(session.OutputToString()).To(ContainSubstring("Wants=container-foo-1.service container-foo-2.service"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("# container-foo-1.service"))
|
Expect(session.OutputToString()).To(ContainSubstring("# container-foo-1.service"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("BindsTo=p-foo.service"))
|
Expect(session.OutputToString()).To(ContainSubstring("BindsTo=p-foo.service"))
|
||||||
})
|
})
|
||||||
@ -492,7 +494,7 @@ var _ = Describe("Podman generate systemd", func() {
|
|||||||
|
|
||||||
// Grepping the output (in addition to unit tests)
|
// Grepping the output (in addition to unit tests)
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("# p_foo.service"))
|
Expect(session.OutputToString()).To(ContainSubstring("# p_foo.service"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("Requires=con_foo-1.service con_foo-2.service"))
|
Expect(session.OutputToString()).To(ContainSubstring("Wants=con_foo-1.service con_foo-2.service"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("# con_foo-1.service"))
|
Expect(session.OutputToString()).To(ContainSubstring("# con_foo-1.service"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("# con_foo-2.service"))
|
Expect(session.OutputToString()).To(ContainSubstring("# con_foo-2.service"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("BindsTo=p_foo.service"))
|
Expect(session.OutputToString()).To(ContainSubstring("BindsTo=p_foo.service"))
|
||||||
@ -518,7 +520,7 @@ var _ = Describe("Podman generate systemd", func() {
|
|||||||
|
|
||||||
// Grepping the output (in addition to unit tests)
|
// Grepping the output (in addition to unit tests)
|
||||||
Expect(session1.OutputToString()).To(ContainSubstring("# foo.service"))
|
Expect(session1.OutputToString()).To(ContainSubstring("# foo.service"))
|
||||||
Expect(session1.OutputToString()).To(ContainSubstring("Requires=container-foo-1.service container-foo-2.service"))
|
Expect(session1.OutputToString()).To(ContainSubstring("Wants=container-foo-1.service container-foo-2.service"))
|
||||||
Expect(session1.OutputToString()).To(ContainSubstring("# container-foo-1.service"))
|
Expect(session1.OutputToString()).To(ContainSubstring("# container-foo-1.service"))
|
||||||
Expect(session1.OutputToString()).To(ContainSubstring("BindsTo=foo.service"))
|
Expect(session1.OutputToString()).To(ContainSubstring("BindsTo=foo.service"))
|
||||||
|
|
||||||
@ -529,7 +531,7 @@ var _ = Describe("Podman generate systemd", func() {
|
|||||||
|
|
||||||
// Grepping the output (in addition to unit tests)
|
// Grepping the output (in addition to unit tests)
|
||||||
Expect(session2.OutputToString()).To(ContainSubstring("# foo.service"))
|
Expect(session2.OutputToString()).To(ContainSubstring("# foo.service"))
|
||||||
Expect(session2.OutputToString()).To(ContainSubstring("Requires=foo-1.service foo-2.service"))
|
Expect(session2.OutputToString()).To(ContainSubstring("Wants=foo-1.service foo-2.service"))
|
||||||
Expect(session2.OutputToString()).To(ContainSubstring("# foo-1.service"))
|
Expect(session2.OutputToString()).To(ContainSubstring("# foo-1.service"))
|
||||||
Expect(session2.OutputToString()).To(ContainSubstring("# foo-2.service"))
|
Expect(session2.OutputToString()).To(ContainSubstring("# foo-2.service"))
|
||||||
Expect(session2.OutputToString()).To(ContainSubstring("BindsTo=foo.service"))
|
Expect(session2.OutputToString()).To(ContainSubstring("BindsTo=foo.service"))
|
||||||
@ -560,7 +562,7 @@ var _ = Describe("Podman generate systemd", func() {
|
|||||||
|
|
||||||
// Grepping the output (in addition to unit tests)
|
// Grepping the output (in addition to unit tests)
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("# pod-foo.service"))
|
Expect(session.OutputToString()).To(ContainSubstring("# pod-foo.service"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("Requires=container-foo-1.service container-foo-2.service"))
|
Expect(session.OutputToString()).To(ContainSubstring("Wants=container-foo-1.service container-foo-2.service"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("BindsTo=pod-foo.service"))
|
Expect(session.OutputToString()).To(ContainSubstring("BindsTo=pod-foo.service"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("pod create --infra-conmon-pidfile %t/pod-foo.pid --pod-id-file %t/pod-foo.pod-id --exit-policy=stop --name foo"))
|
Expect(session.OutputToString()).To(ContainSubstring("pod create --infra-conmon-pidfile %t/pod-foo.pid --pod-id-file %t/pod-foo.pod-id --exit-policy=stop --name foo"))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("ExecStartPre=/bin/rm -f %t/pod-foo.pid %t/pod-foo.pod-id"))
|
Expect(session.OutputToString()).To(ContainSubstring("ExecStartPre=/bin/rm -f %t/pod-foo.pid %t/pod-foo.pod-id"))
|
||||||
|
Reference in New Issue
Block a user