diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/generate/systemd.go | 44 | ||||
-rw-r--r-- | cmd/podman/root.go | 43 |
2 files changed, 78 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 diff --git a/cmd/podman/root.go b/cmd/podman/root.go index 9e4c8d24d..bccc559ce 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -15,6 +15,7 @@ import ( "github.com/containers/podman/v3/cmd/podman/registry" "github.com/containers/podman/v3/cmd/podman/validate" "github.com/containers/podman/v3/libpod/define" + "github.com/containers/podman/v3/pkg/checkpoint/crutils" "github.com/containers/podman/v3/pkg/domain/entities" "github.com/containers/podman/v3/pkg/parallel" "github.com/containers/podman/v3/pkg/rootless" @@ -114,6 +115,48 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error { cfg := registry.PodmanConfig() + // Currently it is only possible to restore a container with the same runtime + // as used for checkpointing. It should be possible to make crun and runc + // compatible to restore a container with another runtime then checkpointed. + // Currently that does not work. + // To make it easier for users we will look into the checkpoint archive and + // set the runtime to the one used during checkpointing. + if !registry.IsRemote() && cmd.Name() == "restore" { + if cmd.Flag("import").Changed { + runtime, err := crutils.CRGetRuntimeFromArchive(cmd.Flag("import").Value.String()) + if err != nil { + return errors.Wrapf( + err, + "failed extracting runtime information from %s", + cmd.Flag("import").Value.String(), + ) + } + if cfg.RuntimePath == "" { + // If the user did not select a runtime, this takes the one from + // the checkpoint archives and tells Podman to use it for the restore. + runtimeFlag := cmd.Root().Flags().Lookup("runtime") + if runtimeFlag == nil { + return errors.Errorf( + "Unexcpected error setting runtime to '%s' for restore", + *runtime, + ) + } + runtimeFlag.Value.Set(*runtime) + runtimeFlag.Changed = true + logrus.Debugf("Checkpoint was created using '%s'. Restore will use the same runtime", *runtime) + } else if cfg.RuntimePath != *runtime { + // If the user selected a runtime on the command-line this checks if + // it is the same then during checkpointing and errors out if not. + return errors.Errorf( + "checkpoint archive %s was created with runtime '%s' and cannot be restored with runtime '%s'", + cmd.Flag("import").Value.String(), + *runtime, + cfg.RuntimePath, + ) + } + } + } + // --connection is not as "special" as --remote so we can wait and process it here conn := cmd.Root().LocalFlags().Lookup("connection") if conn != nil && conn.Changed { |