Documentation ¶
Overview ¶
Package state manages the state of the container
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Cmd = &cobra.Command{ Use: "state", Short: "Prints the current container state", Long: `Prints the current container state`, Run: func(cmd *cobra.Command, args []string) { cfg, err := config.Read() if err != nil { glg.Fatalf("Can't read config file: %s", err) } pman := podman.New(cfg.Podman.Path) if !pman.Exists(cfg.Container.Name) { fmt.Println("Container does not exist.") os.Exit(1) } running := pman.IsRunning(cfg.Container.Name) if running { fmt.Println("Container is running!") os.Exit(0) } else { fmt.Println("Container exists but is not running!") os.Exit(2) } }, }
Cmd is the cobra command for the state command
View Source
var ( // Restart is the cobra command for the restart command Restart = &cobra.Command{ Use: "restart", Aliases: []string{"reset"}, Short: "Restarts the container", Run: func(cmd *cobra.Command, args []string) { cfg, err := config.Read() if err != nil { glg.Fatal(err) } pman := podman.New(cfg.Podman.Path) if !pman.Exists(cfg.Container.Name) { glg.Fatal("Container does not exist") } err = pman.Stop([]string{cfg.Container.Name}, podman.Attach{}) if err != nil { glg.Fatal(err) } err = pman.Start([]string{cfg.Container.Name}, podman.Attach{}) if err != nil { glg.Fatal(err) } }, } )
View Source
var ( // Start is the cobra command for the start command Start = &cobra.Command{ Use: "start", Aliases: []string{"up"}, Short: "Starts the container", Run: func(cmd *cobra.Command, args []string) { cfg, err := config.Read() if err != nil { glg.Fatal(err) } pman := podman.New(cfg.Podman.Path) if !pman.Exists(cfg.Container.Name) { glg.Fatal("Container does not exist") } err = StartContainer(cfg.Container.Name, pman, podman.Attach{}) if err != nil { glg.Fatal(err) } fmt.Println("Container started.") }, } )
View Source
var ( // Stop is the cobra command for the stop command Stop = &cobra.Command{ Use: "stop", Aliases: []string{"down"}, Short: "Stops the container", Run: func(cmd *cobra.Command, args []string) { cfg, err := config.Read() if err != nil { glg.Fatal(err) } pman := podman.New(cfg.Podman.Path) if !pman.Exists(cfg.Container.Name) { glg.Fatal("Container does not exist") } err = SearchActiveContainers(cfg.Container.Name, pman, podman.Attach{}) if err != nil { glg.Fatal(err) } err = pman.Stop([]string{cfg.Container.Name}, podman.Attach{}) if err != nil { glg.Fatal(err) } }, } )
View Source
var ( // Trash is the cobra command for the trash command Trash = &cobra.Command{ Use: "trash", Aliases: []string{"rm"}, Short: "Deletes the container", Run: func(cmd *cobra.Command, args []string) { cfg, err := config.Read() if err != nil { glg.Fatal(err) } pman := podman.New(cfg.Podman.Path) if !pman.Exists(cfg.Container.Name) { glg.Fatal("Container does not exist") } err = pman.Remove([]string{cfg.Container.Name}, podman.Attach{Stderr: true}) if err != nil { glg.Fatal(err) } }, } )
Functions ¶
func SearchActiveContainers ¶ added in v0.6.0
SearchActiveContainers searches for all containers that are running and asks user to choose which ones to stop
Types ¶
type ContInfo ¶ added in v0.6.0
ContInfo is a struct to store the information of a container
func SearchActiveContainer ¶ added in v0.6.0
SearchActiveContainer searches for all active containers and returns id, name, and project path of containers that match Mainly, it searches containers with the label develbox_container=1 For the project path it gets the label develbox_project_path
Click to show internal directories.
Click to hide internal directories.