forked from monzo/orchestra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stop.go
42 lines (37 loc) · 1.02 KB
/
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
42
package commands
import (
"os"
"strings"
"github.com/codegangsta/cli"
"github.com/vinceprignano/orchestra/services"
"github.com/wsxiaoys/terminal"
)
var StopCommand = &cli.Command{
Name: "stop",
Usage: "Stops all the services",
Action: BeforeAfterWrapper(StopAction),
BashComplete: ServicesBashComplete,
}
// StopAction stops all the services (or the specified ones)
func StopAction(c *cli.Context) {
for _, service := range FilterServices(c) {
spacing := strings.Repeat(" ", services.MaxServiceNameLength+2-len(service.Name))
err := killService(service)
if err != nil {
appendError(err)
terminal.Stdout.Colorf("%s%s| @{r} error: @{|}%s\n", service.Name, spacing, err.Error())
} else if service.Process != nil {
terminal.Stdout.Colorf("%s%s| @{r} stopped\n", service.Name, spacing)
}
}
}
func killService(service *services.Service) error {
if service.Process != nil {
err := service.Process.Kill()
defer os.Remove(service.PidFilePath)
if err != nil {
return err
}
}
return nil
}