mirror of
https://github.com/containers/podman.git
synced 2025-06-23 02:18:13 +08:00
V2 restore libpod.Shutdown() when exiting podman commands
Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
@ -155,6 +155,9 @@ func persistentPostRunE(cmd *cobra.Command, args []string) error {
|
|||||||
cfg.Span.Finish()
|
cfg.Span.Finish()
|
||||||
cfg.SpanCloser.Close()
|
cfg.SpanCloser.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registry.ImageEngine().Shutdown(registry.Context())
|
||||||
|
registry.ContainerEngine().Shutdown(registry.Context())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ type ContainerEngine interface {
|
|||||||
ContainerAttach(ctx context.Context, nameOrId string, options AttachOptions) error
|
ContainerAttach(ctx context.Context, nameOrId string, options AttachOptions) error
|
||||||
ContainerCheckpoint(ctx context.Context, namesOrIds []string, options CheckpointOptions) ([]*CheckpointReport, error)
|
ContainerCheckpoint(ctx context.Context, namesOrIds []string, options CheckpointOptions) ([]*CheckpointReport, error)
|
||||||
ContainerCleanup(ctx context.Context, namesOrIds []string, options ContainerCleanupOptions) ([]*ContainerCleanupReport, error)
|
ContainerCleanup(ctx context.Context, namesOrIds []string, options ContainerCleanupOptions) ([]*ContainerCleanupReport, error)
|
||||||
ContainerPrune(ctx context.Context, options ContainerPruneOptions) (*ContainerPruneReport, error)
|
|
||||||
ContainerCommit(ctx context.Context, nameOrId string, options CommitOptions) (*CommitReport, error)
|
ContainerCommit(ctx context.Context, nameOrId string, options CommitOptions) (*CommitReport, error)
|
||||||
ContainerCp(ctx context.Context, source, dest string, options ContainerCpOptions) (*ContainerCpReport, error)
|
ContainerCp(ctx context.Context, source, dest string, options ContainerCpOptions) (*ContainerCpReport, error)
|
||||||
ContainerCreate(ctx context.Context, s *specgen.SpecGenerator) (*ContainerCreateReport, error)
|
ContainerCreate(ctx context.Context, s *specgen.SpecGenerator) (*ContainerCreateReport, error)
|
||||||
@ -30,6 +29,7 @@ type ContainerEngine interface {
|
|||||||
ContainerMount(ctx context.Context, nameOrIds []string, options ContainerMountOptions) ([]*ContainerMountReport, error)
|
ContainerMount(ctx context.Context, nameOrIds []string, options ContainerMountOptions) ([]*ContainerMountReport, error)
|
||||||
ContainerPause(ctx context.Context, namesOrIds []string, options PauseUnPauseOptions) ([]*PauseUnpauseReport, error)
|
ContainerPause(ctx context.Context, namesOrIds []string, options PauseUnPauseOptions) ([]*PauseUnpauseReport, error)
|
||||||
ContainerPort(ctx context.Context, nameOrId string, options ContainerPortOptions) ([]*ContainerPortReport, error)
|
ContainerPort(ctx context.Context, nameOrId string, options ContainerPortOptions) ([]*ContainerPortReport, error)
|
||||||
|
ContainerPrune(ctx context.Context, options ContainerPruneOptions) (*ContainerPruneReport, error)
|
||||||
ContainerRestart(ctx context.Context, namesOrIds []string, options RestartOptions) ([]*RestartReport, error)
|
ContainerRestart(ctx context.Context, namesOrIds []string, options RestartOptions) ([]*RestartReport, error)
|
||||||
ContainerRestore(ctx context.Context, namesOrIds []string, options RestoreOptions) ([]*RestoreReport, error)
|
ContainerRestore(ctx context.Context, namesOrIds []string, options RestoreOptions) ([]*RestoreReport, error)
|
||||||
ContainerRm(ctx context.Context, namesOrIds []string, options RmOptions) ([]*RmReport, error)
|
ContainerRm(ctx context.Context, namesOrIds []string, options RmOptions) ([]*RmReport, error)
|
||||||
@ -48,15 +48,16 @@ type ContainerEngine interface {
|
|||||||
PodInspect(ctx context.Context, options PodInspectOptions) (*PodInspectReport, error)
|
PodInspect(ctx context.Context, options PodInspectOptions) (*PodInspectReport, error)
|
||||||
PodKill(ctx context.Context, namesOrIds []string, options PodKillOptions) ([]*PodKillReport, error)
|
PodKill(ctx context.Context, namesOrIds []string, options PodKillOptions) ([]*PodKillReport, error)
|
||||||
PodPause(ctx context.Context, namesOrIds []string, options PodPauseOptions) ([]*PodPauseReport, error)
|
PodPause(ctx context.Context, namesOrIds []string, options PodPauseOptions) ([]*PodPauseReport, error)
|
||||||
|
PodPrune(ctx context.Context, options PodPruneOptions) ([]*PodPruneReport, error)
|
||||||
PodPs(ctx context.Context, options PodPSOptions) ([]*ListPodsReport, error)
|
PodPs(ctx context.Context, options PodPSOptions) ([]*ListPodsReport, error)
|
||||||
PodRestart(ctx context.Context, namesOrIds []string, options PodRestartOptions) ([]*PodRestartReport, error)
|
PodRestart(ctx context.Context, namesOrIds []string, options PodRestartOptions) ([]*PodRestartReport, error)
|
||||||
PodRm(ctx context.Context, namesOrIds []string, options PodRmOptions) ([]*PodRmReport, error)
|
PodRm(ctx context.Context, namesOrIds []string, options PodRmOptions) ([]*PodRmReport, error)
|
||||||
PodPrune(ctx context.Context, options PodPruneOptions) ([]*PodPruneReport, error)
|
|
||||||
PodStart(ctx context.Context, namesOrIds []string, options PodStartOptions) ([]*PodStartReport, error)
|
PodStart(ctx context.Context, namesOrIds []string, options PodStartOptions) ([]*PodStartReport, error)
|
||||||
PodStop(ctx context.Context, namesOrIds []string, options PodStopOptions) ([]*PodStopReport, error)
|
PodStop(ctx context.Context, namesOrIds []string, options PodStopOptions) ([]*PodStopReport, error)
|
||||||
PodTop(ctx context.Context, options PodTopOptions) (*StringSliceReport, error)
|
PodTop(ctx context.Context, options PodTopOptions) (*StringSliceReport, error)
|
||||||
PodUnpause(ctx context.Context, namesOrIds []string, options PodunpauseOptions) ([]*PodUnpauseReport, error)
|
PodUnpause(ctx context.Context, namesOrIds []string, options PodunpauseOptions) ([]*PodUnpauseReport, error)
|
||||||
SetupRootless(ctx context.Context, cmd *cobra.Command) error
|
SetupRootless(ctx context.Context, cmd *cobra.Command) error
|
||||||
|
Shutdown(ctx context.Context)
|
||||||
VarlinkService(ctx context.Context, opts ServiceOptions) error
|
VarlinkService(ctx context.Context, opts ServiceOptions) error
|
||||||
VolumeCreate(ctx context.Context, opts VolumeCreateOptions) (*IdOrNameResponse, error)
|
VolumeCreate(ctx context.Context, opts VolumeCreateOptions) (*IdOrNameResponse, error)
|
||||||
VolumeInspect(ctx context.Context, namesOrIds []string, opts VolumeInspectOptions) ([]*VolumeInspectReport, error)
|
VolumeInspect(ctx context.Context, namesOrIds []string, opts VolumeInspectOptions) ([]*VolumeInspectReport, error)
|
||||||
|
@ -22,6 +22,7 @@ type ImageEngine interface {
|
|||||||
Remove(ctx context.Context, images []string, opts ImageRemoveOptions) (*ImageRemoveReport, error)
|
Remove(ctx context.Context, images []string, opts ImageRemoveOptions) (*ImageRemoveReport, error)
|
||||||
Save(ctx context.Context, nameOrId string, tags []string, options ImageSaveOptions) error
|
Save(ctx context.Context, nameOrId string, tags []string, options ImageSaveOptions) error
|
||||||
Search(ctx context.Context, term string, opts ImageSearchOptions) ([]ImageSearchReport, error)
|
Search(ctx context.Context, term string, opts ImageSearchOptions) ([]ImageSearchReport, error)
|
||||||
|
Shutdown(ctx context.Context)
|
||||||
Tag(ctx context.Context, nameOrId string, tags []string, options ImageTagOptions) error
|
Tag(ctx context.Context, nameOrId string, tags []string, options ImageTagOptions) error
|
||||||
Tree(ctx context.Context, nameOrId string, options ImageTreeOptions) (*ImageTreeReport, error)
|
Tree(ctx context.Context, nameOrId string, options ImageTreeOptions) (*ImageTreeReport, error)
|
||||||
Untag(ctx context.Context, nameOrId string, tags []string, options ImageUntagOptions) error
|
Untag(ctx context.Context, nameOrId string, tags []string, options ImageUntagOptions) error
|
||||||
|
@ -957,3 +957,10 @@ func (ic *ContainerEngine) ContainerPort(ctx context.Context, nameOrId string, o
|
|||||||
}
|
}
|
||||||
return reports, nil
|
return reports, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shutdown Libpod engine
|
||||||
|
func (ic *ContainerEngine) Shutdown(_ context.Context) {
|
||||||
|
shutdownSync.Do(func() {
|
||||||
|
_ = ic.Libpod.Shutdown(false)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -553,3 +553,10 @@ func (ir *ImageEngine) Remove(ctx context.Context, images []string, opts entitie
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shutdown Libpod engine
|
||||||
|
func (ir *ImageEngine) Shutdown(_ context.Context) {
|
||||||
|
shutdownSync.Do(func() {
|
||||||
|
_ = ir.Libpod.Shutdown(false)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package abi
|
package abi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,3 +15,5 @@ type ImageEngine struct {
|
|||||||
type ContainerEngine struct {
|
type ContainerEngine struct {
|
||||||
Libpod *libpod.Runtime
|
Libpod *libpod.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var shutdownSync sync.Once
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/pkg/cgroups"
|
"github.com/containers/libpod/pkg/cgroups"
|
||||||
@ -18,6 +19,14 @@ import (
|
|||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// runtimeSync only guards the non-specialized runtime
|
||||||
|
runtimeSync sync.Once
|
||||||
|
// The default GetRuntime() always returns the same object and error
|
||||||
|
runtimeLib *libpod.Runtime
|
||||||
|
runtimeErr error
|
||||||
|
)
|
||||||
|
|
||||||
type engineOpts struct {
|
type engineOpts struct {
|
||||||
name string
|
name string
|
||||||
renumber bool
|
renumber bool
|
||||||
@ -63,13 +72,16 @@ func GetRuntimeRenumber(ctx context.Context, fs *flag.FlagSet, cfg *entities.Pod
|
|||||||
|
|
||||||
// GetRuntime generates a new libpod runtime configured by command line options
|
// GetRuntime generates a new libpod runtime configured by command line options
|
||||||
func GetRuntime(ctx context.Context, flags *flag.FlagSet, cfg *entities.PodmanConfig) (*libpod.Runtime, error) {
|
func GetRuntime(ctx context.Context, flags *flag.FlagSet, cfg *entities.PodmanConfig) (*libpod.Runtime, error) {
|
||||||
return getRuntime(ctx, flags, &engineOpts{
|
runtimeSync.Do(func() {
|
||||||
|
runtimeLib, runtimeErr = getRuntime(ctx, flags, &engineOpts{
|
||||||
renumber: false,
|
renumber: false,
|
||||||
migrate: false,
|
migrate: false,
|
||||||
noStore: false,
|
noStore: false,
|
||||||
withFDS: true,
|
withFDS: true,
|
||||||
config: cfg,
|
config: cfg,
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
return runtimeLib, runtimeErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRuntimeNoStore generates a new libpod runtime configured by command line options
|
// GetRuntimeNoStore generates a new libpod runtime configured by command line options
|
||||||
|
@ -379,3 +379,7 @@ func (ic *ContainerEngine) ContainerPort(ctx context.Context, nameOrId string, o
|
|||||||
func (ic *ContainerEngine) ContainerCp(ctx context.Context, source, dest string, options entities.ContainerCpOptions) (*entities.ContainerCpReport, error) {
|
func (ic *ContainerEngine) ContainerCp(ctx context.Context, source, dest string, options entities.ContainerCpOptions) (*entities.ContainerCpReport, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shutdown Libpod engine
|
||||||
|
func (ic *ContainerEngine) Shutdown(_ context.Context) {
|
||||||
|
}
|
||||||
|
@ -260,3 +260,7 @@ func (ir *ImageEngine) Build(ctx context.Context, containerFiles []string, opts
|
|||||||
func (ir *ImageEngine) Tree(ctx context.Context, nameOrId string, opts entities.ImageTreeOptions) (*entities.ImageTreeReport, error) {
|
func (ir *ImageEngine) Tree(ctx context.Context, nameOrId string, opts entities.ImageTreeOptions) (*entities.ImageTreeReport, error) {
|
||||||
return nil, errors.New("not implemented yet")
|
return nil, errors.New("not implemented yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shutdown Libpod engine
|
||||||
|
func (ir *ImageEngine) Shutdown(_ context.Context) {
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user