Skip to content
This repository has been archived by the owner on Nov 29, 2020. It is now read-only.

Commit

Permalink
started stop action
Browse files Browse the repository at this point in the history
  • Loading branch information
christianh814 committed Nov 3, 2020
1 parent a80711b commit c01aba4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
1 change: 0 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 0 additions & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
}
Expand Down
12 changes: 10 additions & 2 deletions cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package cmd

import (
"fmt"

"github.com/robertsandoval/ocp4-helpernode/utils"
"github.com/spf13/cobra"
)

Expand All @@ -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()
},
}

Expand All @@ -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)
}
}
29 changes: 28 additions & 1 deletion utils/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
Expand All @@ -26,11 +27,37 @@ 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)
fmt.Println(cmd)
}

}

//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)
}

}

0 comments on commit c01aba4

Please sign in to comment.