-
Notifications
You must be signed in to change notification settings - Fork 25
/
main.go
97 lines (79 loc) · 1.7 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
91
92
93
94
95
96
97
package main
import (
"flag"
"fmt"
"os"
"runtime"
_ "time/tzdata"
"github.com/ca17/teamsacs/app"
"github.com/ca17/teamsacs/assets"
"github.com/ca17/teamsacs/common/zaplog/log"
"github.com/ca17/teamsacs/config"
"github.com/ca17/teamsacs/controllers"
"github.com/ca17/teamsacs/installer"
"github.com/ca17/teamsacs/tr069"
"github.com/ca17/teamsacs/webserver"
"golang.org/x/sync/errgroup"
)
var (
g errgroup.Group
)
// 命令行定义
var (
h = flag.Bool("h", false, "help usage")
showVer = flag.Bool("v", false, "show version")
conffile = flag.String("c", "", "config yaml file")
install = flag.Bool("install", false, "run install")
uninstall = flag.Bool("uninstall", false, "run uninstall")
)
// PrintVersion Print version information
func PrintVersion() {
println(assets.BuildInfo)
}
func printHelp() {
if *h {
ustr := fmt.Sprintf("teamsacs version: %s, Usage: teamsacs -h\nOptions:", assets.BuildVersion())
_, _ = fmt.Fprintf(os.Stderr, ustr)
flag.PrintDefaults()
os.Exit(0)
}
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
if *showVer {
PrintVersion()
os.Exit(0)
}
printHelp()
_config := config.LoadConfig(*conffile)
// Install as a system service
if *install {
err := installer.Install()
if err != nil {
log.Error(err)
}
return
}
// 卸载
if *uninstall {
installer.Uninstall()
return
}
app.InitGlobalApplication(_config)
app.GApp().MigrateDB(false)
defer app.Release()
// 管理服务启动
g.Go(func() error {
webserver.Init()
controllers.Init()
return webserver.Listen()
})
g.Go(func() error {
log.Info("Start tr069 server...")
return tr069.Listen()
})
if err := g.Wait(); err != nil {
log.Fatal(err)
}
}