diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2021-11-22 11:05:59 +0100 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2021-11-23 09:38:51 +0100 |
commit | 566b78dd02e91f376e9f219cb96ddba153671eb5 (patch) | |
tree | 02e30c7c2fc1e2726579ee1f5d8fc9e38fea40f2 /cmd | |
parent | 1bfbb28b0365790552483b961b4bd48a69dd8070 (diff) | |
download | podman-566b78dd02e91f376e9f219cb96ddba153671eb5.tar.gz podman-566b78dd02e91f376e9f219cb96ddba153671eb5.tar.bz2 podman-566b78dd02e91f376e9f219cb96ddba153671eb5.zip |
generate systemd: add --start-timeout flag
Add a new flag to set the start timeout for a generated systemd unit.
To make naming consistent, add a new --stop-timeout flag as well and let
the previous --time map to it.
Fixes: #11618
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/generate/systemd.go | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/cmd/podman/generate/systemd.go b/cmd/podman/generate/systemd.go index cdc103865..173b3656b 100644 --- a/cmd/podman/generate/systemd.go +++ b/cmd/podman/generate/systemd.go @@ -19,16 +19,19 @@ import ( ) const ( - restartPolicyFlagName = "restart-policy" - timeFlagName = "time" - newFlagName = "new" + startTimeoutFlagName = "start-timeout" + stopTimeoutFlagName = "stop-timeout" + stopTimeoutCompatFlagName = "time" + restartPolicyFlagName = "restart-policy" + newFlagName = "new" ) var ( files bool format string - systemdTimeout uint systemdRestart string + startTimeout uint + stopTimeout uint systemdOptions = entities.GenerateSystemdOptions{} systemdDescription = `Generate systemd units for a pod or container. The generated units can later be controlled via systemctl(1).` @@ -56,8 +59,17 @@ func init() { flags.BoolVarP(&files, "files", "f", false, "Generate .service files instead of printing to stdout") flags.BoolVar(&systemdOptions.TemplateUnitFile, "template", false, "Make it a template file and use %i and %I specifiers. Working only for containers") - flags.UintVarP(&systemdTimeout, timeFlagName, "t", containerConfig.Engine.StopTimeout, "Stop timeout override") - _ = systemdCmd.RegisterFlagCompletionFunc(timeFlagName, completion.AutocompleteNone) + flags.UintVarP(&startTimeout, startTimeoutFlagName, "", 0, "Start timeout override") + _ = systemdCmd.RegisterFlagCompletionFunc(startTimeoutFlagName, completion.AutocompleteNone) + + // NOTE: initially, there was only a --time/-t flag which mapped to + // stop-timeout. To remain backwards compatible create a hidden flag + // that maps to StopTimeout. + flags.UintVarP(&stopTimeout, stopTimeoutFlagName, "", containerConfig.Engine.StopTimeout, "Stop timeout override") + _ = systemdCmd.RegisterFlagCompletionFunc(stopTimeoutFlagName, completion.AutocompleteNone) + flags.UintVarP(&stopTimeout, stopTimeoutCompatFlagName, "t", containerConfig.Engine.StopTimeout, "Backwards alias for --stop-timeout") + _ = flags.MarkHidden("time") + flags.BoolVar(&systemdOptions.New, newFlagName, false, "Create a new container or pod instead of starting an existing one") flags.BoolVarP(&systemdOptions.NoHeader, "no-header", "", false, "Skip header generation") @@ -84,9 +96,6 @@ func init() { } func systemd(cmd *cobra.Command, args []string) error { - if cmd.Flags().Changed(timeFlagName) { - systemdOptions.StopTimeout = &systemdTimeout - } if cmd.Flags().Changed(restartPolicyFlagName) { systemdOptions.RestartPolicy = &systemdRestart } @@ -102,6 +111,23 @@ func systemd(cmd *cobra.Command, args []string) error { systemdOptions.New = true } + if cmd.Flags().Changed(startTimeoutFlagName) { + systemdOptions.StartTimeout = &startTimeout + } + setStopTimeout := 0 + if cmd.Flags().Changed(stopTimeoutFlagName) { + setStopTimeout++ + } + if cmd.Flags().Changed(stopTimeoutCompatFlagName) { + setStopTimeout++ + } + switch setStopTimeout { + case 1: + systemdOptions.StopTimeout = &stopTimeout + case 2: + return fmt.Errorf("%s and %s are redundant and cannot be used together", stopTimeoutFlagName, stopTimeoutCompatFlagName) + } + reports, err := registry.ContainerEngine().GenerateSystemd(registry.GetContext(), args[0], systemdOptions) if err != nil { return err |