feat: add command to stop a running service
This commit is contained in:
parent
c843d35ae5
commit
fca61353b7
3 changed files with 42 additions and 0 deletions
11
main.go
11
main.go
|
@ -28,7 +28,18 @@ var start = &cobra.Command{
|
|||
},
|
||||
}
|
||||
|
||||
var stop = &cobra.Command{
|
||||
Use: "stop",
|
||||
Short: "Stops a running service and all of its containers.",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
serviceName := args[0]
|
||||
service.StopService(serviceName)
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
cli.AddCommand(start)
|
||||
cli.AddCommand(stop)
|
||||
|
||||
cli.Execute()
|
||||
}
|
||||
|
|
|
@ -59,6 +59,24 @@ func CreatePod(name string, ports []service_definition.PortMapping) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
* Stops a running pod.
|
||||
*/
|
||||
func StopPod(name string) error {
|
||||
args := []string{"pod", "stop", name}
|
||||
|
||||
command := exec.Command("podman", args...)
|
||||
|
||||
if err := command.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("✅ Stopped pod \"%s\" and child containers.", name)
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates individual containers.
|
||||
*/
|
||||
|
|
|
@ -30,3 +30,16 @@ func CreateService(definition service_definition.ServiceDefinition) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Stops a running service.
|
||||
*
|
||||
* The service and all its containers are stopped but not deleted.
|
||||
*/
|
||||
func StopService(name string) {
|
||||
err := podman.StopPod(name)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("%s", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue