state

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

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

func SearchActiveContainers(name string, pman podman.Podman, attach podman.Attach) error

SearchActiveContainers searches for all containers that are running and asks user to choose which ones to stop

func StartContainer added in v0.6.0

func StartContainer(name string, pman podman.Podman, attach podman.Attach) error

StartContainer starts the container

Types

type ContInfo added in v0.6.0

type ContInfo struct {
	Name        string
	ID          string
	ProjectPath string
	DBoxVersion string
}

ContInfo is a struct to store the information of a container

func SearchActiveContainer added in v0.6.0

func SearchActiveContainer(pman podman.Podman) ([]ContInfo, error)

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

func (*ContInfo) String added in v0.6.0

func (e *ContInfo) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL