-
Notifications
You must be signed in to change notification settings - Fork 3
/
daemon.go
55 lines (46 loc) · 1.12 KB
/
daemon.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
package main
import (
"github.com/Sirupsen/logrus"
"github.com/huawei-openlab/harbour/api/server"
"github.com/huawei-openlab/harbour/engine"
"github.com/huawei-openlab/harbour/engine/trap"
"github.com/huawei-openlab/harbour/mflag"
"github.com/huawei-openlab/harbour/opts"
)
func mainDaemon() {
if mflag.NArg() != 0 {
mflag.Usage()
return
}
if len(*flDockerSock) == 0 {
engine.DockerSock = opts.DEFAULTDOCKERSOCKET
} else {
engine.DockerSock = *flDockerSock
}
RuntimeType := engine.RuntimeDocker
if len(*flRuntime) != 0 && *flRuntime == opts.RKTRUNTIME {
RuntimeType = engine.RuntimeRkt
}
if len(*flGroup) > 0 {
engine.SocketGroup = *flGroup
}
eng := engine.New(RuntimeType)
//catch signals
trap.SignalsHandler(trap.Shutdown)
var srv *server.Server
srv = server.New(eng, false)
serverWait := make(chan error)
go func() {
if err := srv.CreateServer(eng, flHosts); err != nil {
logrus.Errorf("Server error: %v", err)
serverWait <- err
return
}
serverWait <- nil
}()
err := <-serverWait
if err != nil {
logrus.Fatalf("Shutting down due to Server error: %v", err)
}
<-trap.CleanupDone
}