-
Notifications
You must be signed in to change notification settings - Fork 24
/
stop.go
41 lines (35 loc) · 988 Bytes
/
stop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package cmd
import (
"github.com/aserto-dev/topaz/pkg/cc/config"
"github.com/aserto-dev/topaz/pkg/cli/cc"
"github.com/aserto-dev/topaz/pkg/cli/dockerx"
"github.com/fatih/color"
)
type StopCmd struct {
ContainerName string `optional:"" default:"${container_name}" env:"CONTAINER_NAME" help:"container name"`
Wait bool `optional:"" default:"false" help:"wait for ports to be closed"`
}
func (cmd *StopCmd) Run(c *cc.CommonCtx) error {
c.NoCheck = false // enforce that Stop does not bypass CheckRunStatus() to short-circuit.
if c.CheckRunStatus(cmd.ContainerName, cc.StatusNotRunning) {
return nil
}
color.Green(">>> stopping topaz...")
dc, err := dockerx.New()
if err != nil {
return err
}
if err := dc.Stop(cmd.ContainerName); err != nil {
return err
}
if cmd.Wait {
ports, err := config.CurrentConfig().Ports()
if err != nil {
return err
}
if err := cc.WaitForPorts(ports, cc.PortClosed); err != nil {
return err
}
}
return nil
}