60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"rocommon"
|
|
"rocommon/service"
|
|
_ "rocommon/socket"
|
|
_ "rocommon/socket/tcp"
|
|
"roserver/baseserver"
|
|
"roserver/baseserver/model"
|
|
model2 "roserver/cross_rank/model"
|
|
_ "roserver/cross_rank/msg"
|
|
_ "roserver/serverproto"
|
|
"runtime"
|
|
"strconv"
|
|
"syscall"
|
|
)
|
|
|
|
func main() {
|
|
//记录gate pid用来做关闭操作
|
|
sysType := runtime.GOOS
|
|
if sysType != "windows" {
|
|
if pid := syscall.Getpid(); pid != 1 {
|
|
fileName := "crossrank_server.pid" + strconv.Itoa(pid)
|
|
ioutil.WriteFile(fileName, []byte(strconv.Itoa(pid)), 0777)
|
|
defer os.Remove(fileName)
|
|
}
|
|
}
|
|
|
|
baseserver.Init(model.SERVICE_NODE_TYPE_CROSSRANK_STR, model2.ConfigInit, &model2.CrossRankUpdate{})
|
|
|
|
//先建立服务器对应的连接,在监听客户端
|
|
sConfig := service.GetServiceConfig()
|
|
//创建监听器
|
|
var acceptorNode rocommon.ServerNode = nil
|
|
if sConfig.Node.Addr != "" {
|
|
acceptorNode = baseserver.CreateAcceptor(baseserver.ServiceParam{
|
|
ServiceType: "tcpAcceptor",
|
|
ServiceName: model.SERVICE_NODE_TYPE_CROSSRANK_STR,
|
|
ProcName: "common.backend",
|
|
LisAddr: sConfig.Node.Addr,
|
|
}, sConfig)
|
|
}
|
|
|
|
for _, concern := range sConfig.Node.Concern {
|
|
//建立需要链接的服务器,通过服务器发现etcd来处理(包含在了CreateConnector中)
|
|
baseserver.CreateConnector(baseserver.ServiceParam{
|
|
DiscoveryServiceName: concern,
|
|
DiscoveryServiceZone: sConfig.Node.Zone,
|
|
ServiceType: "tcpConnector",
|
|
ServiceName: model.SERVICE_NODE_TYPE_CROSSRANK_STR,
|
|
ProcName: "common.backend",
|
|
})
|
|
}
|
|
|
|
baseserver.Wait()
|
|
baseserver.Exit(acceptorNode)
|
|
}
|