summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2021-09-06 14:49:59 +0200
committerValentin Rothberg <rothberg@redhat.com>2021-09-07 13:58:11 +0200
commitd1573b95e3427efae21da784e3112c5fb3d463fb (patch)
treeda311feeab3105d4577a7d5c4a9a1dc3027603aa /cmd
parente095667ac8c2ccaf06dea6d4c61f51d93b736968 (diff)
downloadpodman-d1573b95e3427efae21da784e3112c5fb3d463fb.tar.gz
podman-d1573b95e3427efae21da784e3112c5fb3d463fb.tar.bz2
podman-d1573b95e3427efae21da784e3112c5fb3d463fb.zip
generate systemd: handle --restart
Handle custom restart policies of containers when generating the unit files; those should be set on the unit level and removed from ExecStart flags. Fixes: #11438 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/generate/systemd.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/cmd/podman/generate/systemd.go b/cmd/podman/generate/systemd.go
index b76a71f0d..2ab33c26b 100644
--- a/cmd/podman/generate/systemd.go
+++ b/cmd/podman/generate/systemd.go
@@ -12,15 +12,22 @@ import (
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/utils"
"github.com/containers/podman/v3/pkg/domain/entities"
+ systemDefine "github.com/containers/podman/v3/pkg/systemd/define"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
+const (
+ restartPolicyFlagName = "restart-policy"
+ timeFlagName = "time"
+)
+
var (
files bool
format string
systemdTimeout uint
+ systemdRestart string
systemdOptions = entities.GenerateSystemdOptions{}
systemdDescription = `Generate systemd units for a pod or container.
The generated units can later be controlled via systemctl(1).`
@@ -47,7 +54,6 @@ func init() {
flags.BoolVarP(&systemdOptions.Name, "name", "n", false, "Use container/pod names instead of IDs")
flags.BoolVarP(&files, "files", "f", false, "Generate .service files instead of printing to stdout")
- timeFlagName := "time"
flags.UintVarP(&systemdTimeout, timeFlagName, "t", containerConfig.Engine.StopTimeout, "Stop timeout override")
_ = systemdCmd.RegisterFlagCompletionFunc(timeFlagName, completion.AutocompleteNone)
flags.BoolVarP(&systemdOptions.New, "new", "", false, "Create a new container or pod instead of starting an existing one")
@@ -65,8 +71,7 @@ func init() {
flags.StringVar(&systemdOptions.Separator, separatorFlagName, "-", "Systemd unit name separator between name/id and prefix")
_ = systemdCmd.RegisterFlagCompletionFunc(separatorFlagName, completion.AutocompleteNone)
- restartPolicyFlagName := "restart-policy"
- flags.StringVar(&systemdOptions.RestartPolicy, restartPolicyFlagName, "on-failure", "Systemd restart-policy")
+ flags.StringVar(&systemdRestart, restartPolicyFlagName, systemDefine.DefaultRestartPolicy, "Systemd restart-policy")
_ = systemdCmd.RegisterFlagCompletionFunc(restartPolicyFlagName, common.AutocompleteSystemdRestartOptions)
formatFlagName := "format"
@@ -77,9 +82,12 @@ func init() {
}
func systemd(cmd *cobra.Command, args []string) error {
- if cmd.Flags().Changed("time") {
+ if cmd.Flags().Changed(timeFlagName) {
systemdOptions.StopTimeout = &systemdTimeout
}
+ if cmd.Flags().Changed(restartPolicyFlagName) {
+ systemdOptions.RestartPolicy = &systemdRestart
+ }
if registry.IsRemote() {
logrus.Warnln("The generated units should be placed on your remote system")