-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathstart.go
More file actions
45 lines (42 loc) · 1.09 KB
/
start.go
File metadata and controls
45 lines (42 loc) · 1.09 KB
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
43
44
45
package fleet
import (
"strings"
"github.com/coreos/fleet/job"
"github.com/coreos/fleet/schema"
)
// Start launches target units and blocks until active
func (c *FleetClient) Start(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.JobStateLaunched)
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 {
// wait for systemd to tell us that it's running, not fleet
// data containers are special snowflakes who just exit
if strings.Contains(name, "-data.service") {
outchan, errchan = waitForUnitSubStates(names, "exited")
} else {
outchan, errchan = waitForUnitSubStates(names, "running")
}
if err := printUnitSubState(name, outchan, errchan); err != nil {
return err
}
}
}
return nil
}