-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstop.go
More file actions
38 lines (35 loc) · 859 Bytes
/
stop.go
File metadata and controls
38 lines (35 loc) · 859 Bytes
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
package fleet
import (
"github.com/coreos/fleet/job"
"github.com/coreos/fleet/schema"
)
// Stop sets target units to inactive and blocks until complete
func (c *FleetClient) Stop(targets []string) error {
units := make([][]string, len(targets))
for i, target := range targets {
u, err := c.Units(target)
if err != nil {
return err
}
units[i] = u
}
desiredState := string(job.JobStateLoaded)
for _, names := range units {
for _, name := range names {
if err := c.Fleet.SetUnitTargetState(name, desiredState); err != nil {
return err
}
}
}
var errchan chan error
var outchan chan *schema.Unit
for _, names := range units {
for _, name := range names {
outchan, errchan = waitForUnitSubStates(names, "dead")
if err := printUnitSubState(name, outchan, errchan); err != nil {
return err
}
}
}
return nil
}