|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"gitea.anxinyun.cn/container/common_utils/configLoad"
|
|
|
|
"log"
|
|
|
|
etMaster "master/app"
|
|
|
|
"net/http"
|
|
|
|
_ "net/http/pprof"
|
|
|
|
etNode "node/app"
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
VERSION string
|
|
|
|
SVN_REVISION string
|
|
|
|
BUILD_NUMBER string
|
|
|
|
BUILD_TIME string
|
|
|
|
GO_VERSION string
|
|
|
|
)
|
|
|
|
|
|
|
|
func logVersions() {
|
|
|
|
log.Printf("Version:%s", VERSION)
|
|
|
|
log.Printf("SVN Revision:%s", SVN_REVISION)
|
|
|
|
log.Printf("Build Number:%s", BUILD_NUMBER)
|
|
|
|
log.Printf("Build Time:%s", BUILD_TIME)
|
|
|
|
log.Printf("Go Version:%s", GO_VERSION)
|
|
|
|
log.Printf("Go OS/Arch:%s/%s", runtime.GOOS, runtime.GOARCH)
|
|
|
|
log.Println()
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
logVersions()
|
|
|
|
|
|
|
|
//获取状态集合序号
|
|
|
|
hostName, err := os.Hostname() //"etgo-0"
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Error getting hostname:%s", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
masterTag := configLoad.LoadConfig().GetString("master.hostNameTag")
|
|
|
|
log.Printf("hostName =[%s],masterTag=[%s]", hostName, masterTag)
|
|
|
|
if hostName == masterTag {
|
|
|
|
log.Printf("启动类型:master => hostName=[%s]", hostName)
|
|
|
|
etMaster.Start()
|
|
|
|
} else {
|
|
|
|
pprofEnable := configLoad.LoadConfig().GetBool("pprof.enable")
|
|
|
|
if pprofEnable {
|
|
|
|
pprofRun()
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("启动类型:node => hostName=[%s]", hostName)
|
|
|
|
etNode.Start()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func pprofRun() {
|
|
|
|
|
|
|
|
pprofAddr := ":10000"
|
|
|
|
log.Printf("性能分析 => pprofAddr=[%s]", pprofAddr)
|
|
|
|
go func() {
|
|
|
|
err := http.ListenAndServe(pprofAddr, nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Panicf("启动异常 => [%s]", err.Error())
|
|
|
|
} //开启一个http服务,nil表示绑定默认路由器DefaultServeMux
|
|
|
|
}()
|
|
|
|
}
|