forked from rexray/rexray
/
service_00_controller.go
67 lines (55 loc) · 1.29 KB
/
service_00_controller.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// +build !client
// +build !agent
package cli
import (
gofig "github.com/akutz/gofig/types"
apitypes "github.com/rexray/rexray/libstorage/api/types"
"github.com/rexray/rexray/util"
)
func init() {
startFuncs = append(startFuncs, startLibStorageAsService)
}
func startLibStorageAsService(
ctx apitypes.Context,
config gofig.Config) (apitypes.Context, <-chan error, error) {
var (
err error
errs <-chan error
)
// Attempt to activate libStorage. If an ErrHostDetectionFailed
// error occurs then just log it as a warning since modules may
// define hosts directly
ctx, _, errs, err = util.ActivateLibStorage(ctx, config)
if err != nil {
if err.Error() == util.ErrHostDetectionFailed.Error() {
ctx.Warn(err)
} else {
return nil, nil, err
}
}
if errs == nil {
return ctx, nil, nil
}
var (
waitErrs = make(chan error, 1)
strtErrs = make(chan error, 1)
)
go func() {
for err := range errs {
if err != nil {
waitErrs <- err
strtErrs <- err
}
}
close(waitErrs)
}()
// Stop libStorage if the context is cancelled.
go func() {
ctx.Info("libStorage context cancellation - waiting")
<-ctx.Done()
ctx.Info("libStorage context cancellation - received")
util.WaitUntilLibStorageStopped(ctx, waitErrs)
close(strtErrs)
}()
return ctx, strtErrs, nil
}