-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
45 lines (37 loc) · 1.14 KB
/
main.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
package main
import (
"github.com/skynetservices/skynet"
"github.com/skynetservices/skynet/log"
"github.com/skynetservices/skynet/service"
_ "github.com/skynetservices/zkmanager"
"time"
)
// Daemon will run and maintain skynet services.
//
// Daemon will run the "SkynetDeployment" service, which can be used
// to remotely spawn new services on the host.
func main() {
si := skynet.NewServiceInfo("SkynetDaemon", "2.0.0")
deployment := NewSkynetDaemon()
s := service.CreateService(deployment, si)
deployment.Service = s
// handle panic so that we remove ourselves from the pool in case of catastrophic failure
defer func() {
s.Shutdown()
deployment.closeStateFile()
if err := recover(); err != nil {
e := err.(error)
log.Fatal("Unrecovered error occured: " + e.Error())
}
}()
// Collect Host metrics
statTicker := time.Tick((5 * time.Second))
go func() {
for _ = range statTicker {
deployment.updateHostStats(si.ServiceAddr.IPAddress)
}
}()
// If we pass false here service will not be Registered
// we could do other work/tasks by implementing the Started method and calling Register() when we're ready
s.Start().Wait()
}