diff --git a/cmd/init.go b/cmd/init.go index 09e3f1e..97ae6d4 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -50,7 +50,6 @@ Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("init called") verifyContainerRuntime() pullImages() diff --git a/cmd/start.go b/cmd/start.go index 96a7073..63d143f 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -36,7 +36,6 @@ Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("start called") runContianers() }, } diff --git a/cmd/stop.go b/cmd/stop.go index 1c3e3f5..99441b5 100644 --- a/cmd/stop.go +++ b/cmd/stop.go @@ -17,7 +17,7 @@ package cmd import ( "fmt" - + "github.com/robertsandoval/ocp4-helpernode/utils" "github.com/spf13/cobra" ) @@ -32,7 +32,8 @@ Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("stop called") + fmt.Println("Stopping services") + stopContainers() }, } @@ -49,3 +50,10 @@ func init() { // is called directly, e.g.: // stopCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } + +func stopContainers() { + //MVP, just stop everything + for k, _ := range images { + utils.StopImage(k) + } +} diff --git a/utils/container.go b/utils/container.go index 9619e3a..a880535 100644 --- a/utils/container.go +++ b/utils/container.go @@ -18,6 +18,7 @@ func PullImage(image string, version string){ cmd, err := exec.Command(containerRuntime, "pull", image + ":" + version).Output() if err != nil { fmt.Println(cmd) + fmt.Println(err) } } @@ -26,7 +27,10 @@ func PullImage(image string, version string){ func StartImage(image string, version string, encodedyaml string, containername string){ fmt.Println("Running: " + image) - //TODO Need to write the output for the image run + /* TODO: + - Need to write the output for the image run + - Check if the image is already running + */ cmd, err := exec.Command(containerRuntime, "run", "-d", "--env=HELPERPOD_CONFIG_YAML=" + encodedyaml, "--net=host", "--name=helpernode-" + containername, image + ":" + version).Output() if err != nil { fmt.Println(err) @@ -34,3 +38,26 @@ func StartImage(image string, version string, encodedyaml string, containername } } + +//going to covert this to use the podman module in the future +func StopImage(containername string){ + + fmt.Println("Stopping: helpernode-" + containername) + /* TODO: + - Need to write the output for the image run + - Check if service is already stopped + */ + // First, stop container + stopcmd, err := exec.Command(containerRuntime, "stop", "-i", "helpernode-" + containername).Output() + if err != nil { + fmt.Println(err) + fmt.Println(stopcmd) + } + // Then, rm the container so we can reuse the name afterwards + rmcmd, err := exec.Command(containerRuntime, "rm", "-i", "--force", "helpernode-" + containername).Output() + if err != nil { + fmt.Println(err) + fmt.Println(rmcmd) + } + +}