-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.go
51 lines (44 loc) · 980 Bytes
/
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
46
47
48
49
50
51
package main
import (
"os/signal"
"syscall"
lazlo "github.com/djosephsen/lazlo/lib"
)
func main() {
lazlo.Logger.Debug(`creating broker`)
//make a broker
broker, err := lazlo.NewBroker()
if err != nil {
lazlo.Logger.Error(err)
return
}
defer broker.Brain.Close()
lazlo.Logger.Debug(`starting modules`)
// register the modules
if err := initModules(broker); err != nil {
lazlo.Logger.Error(err)
return
}
//start the Modules
broker.StartModules()
lazlo.Logger.Debug(`starting broker`)
//start the broker
go broker.Start()
// Loop
signal.Notify(broker.SigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
stop := false
for !stop {
select {
case sig := <-broker.SigChan:
switch sig {
case syscall.SIGINT, syscall.SIGTERM:
stop = true
}
}
}
// Stop listening for new signals
signal.Stop(broker.SigChan)
broker.Stop()
//wait for the write thread to stop (so the shutdown hooks have a chance to run)
<-broker.SyncChan
}