Merge pull request #17041 from vrothberg/post-run
cobra: move engine shutdown to Execute
This commit is contained in:
commit
619933a530
|
|
@ -115,6 +115,22 @@ func Execute() {
|
||||||
}
|
}
|
||||||
fmt.Fprintln(os.Stderr, formatError(err))
|
fmt.Fprintln(os.Stderr, formatError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if requireCleanup {
|
||||||
|
// The cobra post-run is not being executed in case of
|
||||||
|
// a previous error , so make sure that the engine(s)
|
||||||
|
// are correctly shutdown.
|
||||||
|
//
|
||||||
|
// See https://github.com/spf13/cobra/issues/914
|
||||||
|
logrus.Debugf("Shutting down engines")
|
||||||
|
if engine := registry.ImageEngine(); engine != nil {
|
||||||
|
engine.Shutdown(registry.Context())
|
||||||
|
}
|
||||||
|
if engine := registry.ContainerEngine(); engine != nil {
|
||||||
|
engine.Shutdown(registry.Context())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
os.Exit(registry.GetExitCode())
|
os.Exit(registry.GetExitCode())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -298,13 +314,6 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
|
||||||
func persistentPostRunE(cmd *cobra.Command, args []string) error {
|
func persistentPostRunE(cmd *cobra.Command, args []string) error {
|
||||||
logrus.Debugf("Called %s.PersistentPostRunE(%s)", cmd.Name(), strings.Join(os.Args, " "))
|
logrus.Debugf("Called %s.PersistentPostRunE(%s)", cmd.Name(), strings.Join(os.Args, " "))
|
||||||
|
|
||||||
if !requireCleanup {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
registry.ImageEngine().Shutdown(registry.Context())
|
|
||||||
registry.ContainerEngine().Shutdown(registry.Context())
|
|
||||||
|
|
||||||
if registry.IsRemote() {
|
if registry.IsRemote() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -238,4 +238,11 @@ run_podman --noout system connection ls
|
||||||
is "$output" "" "output should be empty"
|
is "$output" "" "output should be empty"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "podman - shutdown engines" {
|
||||||
|
run_podman --log-level=debug run --rm $IMAGE true
|
||||||
|
is "$output" ".*Shutting down engines.*"
|
||||||
|
run_podman 125 --log-level=debug run dockah://rien.de/rien:latest
|
||||||
|
is "${lines[-1]}" ".*Shutting down engines"
|
||||||
|
}
|
||||||
|
|
||||||
# vim: filetype=sh
|
# vim: filetype=sh
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue