-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
90 lines (78 loc) · 1.48 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"flag"
"github.com/OTCGO/sea-server-go/config"
"github.com/OTCGO/sea-server-go/db"
"github.com/OTCGO/sea-server-go/job/clean"
"github.com/OTCGO/sea-server-go/job/node"
"github.com/OTCGO/sea-server-go/job/sync"
"github.com/OTCGO/sea-server-go/server"
"github.com/hzxiao/goutil/log"
"github.com/hzxiao/goutil/version"
"os"
"os/signal"
"syscall"
)
var (
conf string
ver bool
)
func init() {
flag.BoolVar(&ver, "v", false, "show version info.")
flag.StringVar(&conf, "conf", "seago.toml", "default config file")
}
func main() {
flag.Parse()
var err error
if ver {
err = version.Print()
if err != nil {
panic(err)
}
return
}
err = config.Init(conf)
if err != nil {
panic(err)
}
//log init
err = log.SetLogger(config.Conf.Log.OutputWay, config.Conf.Log.Output)
if err != nil {
panic(err)
}
err = initTaskAndServer()
if err != nil {
panic(err)
}
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
log.Info("get a signal %s", s.String())
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
return
case syscall.SIGHUP:
default:
return
}
}
}
func initTaskAndServer() (err error) {
err = db.InitDB(config.Conf.MySQLUrl)
if err != nil {
return
}
if config.Conf.OpenSync {
node.Init()
err = sync.Init()
if err != nil {
return
}
sync.SyncAll()
clean.StartClean()
}
server.Init()
go server.Run()
return
}