-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmain.go
101 lines (87 loc) · 2.31 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
98
99
100
101
/*devfeel.longweb
* Author: Panxinming
* LastUpdateTime: 2017-02-07 10:00
*/
package main
import (
"flag"
"fmt"
"github.com/devfeel/longweb/config"
"github.com/devfeel/longweb/framework/file"
"github.com/devfeel/longweb/framework/log"
"github.com/devfeel/longweb/httpserver"
"github.com/devfeel/longweb/message"
"github.com/devfeel/longweb/task"
"os"
"os/signal"
"runtime/debug"
"syscall"
)
var (
innerLogger *logger.InnerLogger
configFile string
)
func init() {
innerLogger = logger.GetInnerLogger()
}
func main() {
defer func() {
if err := recover(); err != nil {
strLog := "longweb:main recover error => " + fmt.Sprintln(err)
os.Stdout.Write([]byte(strLog))
errMsg := strLog + string(debug.Stack())
innerLogger.Error(errMsg)
os.Stdout.Write([]byte(errMsg))
}
}()
currentBaseDir := fileutil.GetCurrentDirectory()
flag.StringVar(&configFile, "config", "", "配置文件路径")
if configFile == "" {
configFile = currentBaseDir + "/app.conf"
}
//启动内部日志服务
logger.StartInnerLogHandler(currentBaseDir)
//加载xml配置文件
appconfig := config.InitConfig(configFile)
//设置基本目录
config.SetBaseDir(currentBaseDir)
//启动日志服务
logger.StartLogHandler(appconfig.Log.FilePath)
//初始化应用信息
message.InitAppInfo()
//start message service
message.StartMessageService()
//监听系统信号
go listenSignal()
//启动task
go task.StartTaskService(currentBaseDir + "/task.conf")
err := httpserver.StartServer()
if err != nil {
innerLogger.Warn("HttpServer.StartServer失败 " + err.Error())
fmt.Println("HttpServer.StartServer失败 " + err.Error())
}
}
func listenSignal() {
c := make(chan os.Signal, 1)
//syscall.SIGSTOP
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
innerLogger.Info("signal::ListenSignal [" + s.String() + "]")
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
return
case syscall.SIGHUP: //配置重载
innerLogger.Info("signal::ListenSignal reload config begin...")
//重新加载配置文件
config.InitConfig(configFile)
//初始化应用信息
message.InitAppInfo()
//start message service
message.ReStartMessageService()
innerLogger.Info("signal::ListenSignal reload config end")
default:
return
}
}
}