forked from irisnet/irishub-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (40 loc) · 1.02 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
package main
import (
"github.com/irisnet/irishub-sync/cron"
"github.com/irisnet/irishub-sync/logger"
"github.com/irisnet/irishub-sync/monitor"
"github.com/irisnet/irishub-sync/service"
"github.com/irisnet/irishub-sync/store"
"github.com/irisnet/irishub-sync/util/helper"
"os"
"os/signal"
"syscall"
)
func main() {
c := make(chan os.Signal)
engine := service.New()
defer func() {
logger.Info("Irishub Sync Service Exit...")
engine.Stop()
helper.ClosePool()
store.Stop()
logger.Sync()
if err := recover(); err != nil {
logger.Error(err.(string))
os.Exit(1)
}
}()
//monitor system signal
signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
// start monitor
go monitor.NewMonitor().Start()
//start databases service
logger.Info("Databases Service Start...")
store.Start()
//start sync task service
logger.Info("Irishub Sync Service Start...")
go new(cron.CronService).StartCronService()
engine.Start()
//paused until the signal have received
<-c
}