mirror of
https://github.com/containers/podman.git
synced 2025-07-03 09:17:15 +08:00
Merge pull request #16475 from Darth-Mera/restartsec-fix
Add restart-sec for container service files
This commit is contained in:
@ -28,6 +28,7 @@ type containerInfo struct {
|
||||
NotifyAccess string
|
||||
StopTimeout uint
|
||||
RestartPolicy string
|
||||
RestartSec uint
|
||||
StartLimitBurst string
|
||||
PIDFile string
|
||||
ContainerIDFile string
|
||||
@ -87,6 +88,9 @@ Environment={{{{- range $index, $value := .ExtraEnvs -}}}}{{{{if $index}}}} {{{{
|
||||
Environment={{{{ $value }}}}{{{{end}}}}
|
||||
{{{{- end}}}}
|
||||
Restart={{{{.RestartPolicy}}}}
|
||||
{{{{- if .RestartSec}}}}
|
||||
RestartSec={{{{.RestartSec}}}}
|
||||
{{{{- end}}}}
|
||||
{{{{- if .StartLimitBurst}}}}
|
||||
StartLimitBurst={{{{.StartLimitBurst}}}}
|
||||
{{{{- end}}}}
|
||||
@ -282,6 +286,10 @@ func executeContainerTemplate(info *containerInfo, options entities.GenerateSyst
|
||||
info.RestartPolicy = *options.RestartPolicy
|
||||
}
|
||||
|
||||
if options.RestartSec != nil {
|
||||
info.RestartSec = *options.RestartSec
|
||||
}
|
||||
|
||||
// Make sure the executable is set.
|
||||
if info.Executable == "" {
|
||||
executable, err := os.Executable()
|
||||
|
@ -995,6 +995,32 @@ ExecStopPost=/usr/bin/podman rm \
|
||||
Type=notify
|
||||
NotifyAccess=all
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
`
|
||||
goodRestartSec := `# container-foobar.service
|
||||
# autogenerated by Podman CI
|
||||
|
||||
[Unit]
|
||||
Description=Podman container-foobar.service
|
||||
Documentation=man:podman-generate-systemd(1)
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
RequiresMountsFor=/var/run/containers/storage
|
||||
|
||||
[Service]
|
||||
Environment=PODMAN_SYSTEMD_UNIT=%n
|
||||
Restart=on-failure
|
||||
RestartSec=15
|
||||
TimeoutStopSec=70
|
||||
ExecStart=/usr/bin/podman start foobar
|
||||
ExecStop=/usr/bin/podman stop \
|
||||
-t 10 foobar
|
||||
ExecStopPost=/usr/bin/podman stop \
|
||||
-t 10 foobar
|
||||
PIDFile=/run/containers/storage/overlay-containers/639c53578af4d84b8800b4635fa4e680ee80fd67e0e6a2d4eea48d1e3230f401/userdata/conmon.pid
|
||||
Type=forking
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
`
|
||||
@ -1658,6 +1684,25 @@ WantedBy=default.target
|
||||
false,
|
||||
false,
|
||||
},
|
||||
{"good with RestartSec",
|
||||
containerInfo{
|
||||
Executable: "/usr/bin/podman",
|
||||
ServiceName: "container-foobar",
|
||||
ContainerNameOrID: "foobar",
|
||||
PIDFile: "/run/containers/storage/overlay-containers/639c53578af4d84b8800b4635fa4e680ee80fd67e0e6a2d4eea48d1e3230f401/userdata/conmon.pid",
|
||||
StopTimeout: 10,
|
||||
PodmanVersion: "CI",
|
||||
EnvVariable: define.EnvVariable,
|
||||
GraphRoot: "/var/lib/containers/storage",
|
||||
RunRoot: "/var/run/containers/storage",
|
||||
RestartSec: 15,
|
||||
},
|
||||
goodRestartSec,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
test := tt
|
||||
|
@ -387,6 +387,15 @@ var _ = Describe("Podman generate systemd", func() {
|
||||
|
||||
// Grepping the output (in addition to unit tests)
|
||||
Expect(session.OutputToString()).To(ContainSubstring("RestartSec=15"))
|
||||
|
||||
n = podmanTest.Podman([]string{"create", "--name", "foocontainer", "alpine", "top"})
|
||||
n.WaitWithDefaultTimeout()
|
||||
Expect(n).Should(Exit(0))
|
||||
|
||||
session2 := podmanTest.Podman([]string{"generate", "systemd", "--restart-sec", "15", "--name", "foocontainer"})
|
||||
session2.WaitWithDefaultTimeout()
|
||||
Expect(session2).Should(Exit(0))
|
||||
Expect(session2.OutputToString()).To(ContainSubstring("RestartSec=15"))
|
||||
})
|
||||
|
||||
It("podman generate systemd --new=false pod", func() {
|
||||
|
Reference in New Issue
Block a user