ing
This commit is contained in:
parent
ba6bb15295
commit
1e7be8bc07
|
@ -5,6 +5,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.loafle.net/commons_go/logging"
|
"git.loafle.net/commons_go/logging"
|
||||||
|
@ -12,8 +13,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewServerHandler(pidPath string, serverName string, socketHandler SocketHandler) ServerHandler {
|
func NewServerHandler(pidPath string, serverName string, socketHandler SocketHandler) ServerHandler {
|
||||||
|
pidPathABS, err := filepath.Abs(pidPath)
|
||||||
|
if nil != err {
|
||||||
|
logging.Logger().Panicf("Container: pid file path[%s] is not valid %v", pidPath, err)
|
||||||
|
}
|
||||||
|
|
||||||
sh := &ServerHandlers{
|
sh := &ServerHandlers{
|
||||||
pidPath: pidPath,
|
pidPath: pidPath,
|
||||||
|
pidPathABS: pidPathABS,
|
||||||
}
|
}
|
||||||
|
|
||||||
sh.Name = serverName
|
sh.Name = serverName
|
||||||
|
@ -24,8 +31,9 @@ func NewServerHandler(pidPath string, serverName string, socketHandler SocketHan
|
||||||
type ServerHandlers struct {
|
type ServerHandlers struct {
|
||||||
server.ServerHandlers
|
server.ServerHandlers
|
||||||
|
|
||||||
pidPath string
|
pidPath string
|
||||||
port int
|
pidPathABS string
|
||||||
|
port int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *ServerHandlers) Init(serverCTX server.ServerContext) error {
|
func (sh *ServerHandlers) Init(serverCTX server.ServerContext) error {
|
||||||
|
@ -52,19 +60,19 @@ func (sh *ServerHandlers) Listen(serverCTX server.ServerContext) (net.Listener,
|
||||||
func (sh *ServerHandlers) OnStart(serverCTX server.ServerContext) {
|
func (sh *ServerHandlers) OnStart(serverCTX server.ServerContext) {
|
||||||
sh.ServerHandlers.OnStart(serverCTX)
|
sh.ServerHandlers.OnStart(serverCTX)
|
||||||
|
|
||||||
if _, err := os.Stat(sh.pidPath); os.IsExist(err) {
|
if _, err := os.Stat(sh.pidPathABS); os.IsExist(err) {
|
||||||
if err := os.Remove(sh.pidPath); nil != err {
|
if err := os.Remove(sh.pidPathABS); nil != err {
|
||||||
logging.Logger().Errorf("Container: Removing pid file has been failed [%v]", err)
|
logging.Logger().Errorf("Container: Removing pid file has been failed [%v]", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s := strconv.FormatInt(int64(sh.port), 10)
|
s := strconv.FormatInt(int64(sh.port), 10)
|
||||||
ioutil.WriteFile(sh.pidPath, []byte(s), os.ModePerm)
|
ioutil.WriteFile(sh.pidPathABS, []byte(s), os.ModePerm)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *ServerHandlers) OnStop(serverCTX server.ServerContext) {
|
func (sh *ServerHandlers) OnStop(serverCTX server.ServerContext) {
|
||||||
if _, err := os.Stat(sh.pidPath); os.IsExist(err) {
|
if _, err := os.Stat(sh.pidPathABS); os.IsExist(err) {
|
||||||
if err := os.Remove(sh.pidPath); nil != err {
|
if err := os.Remove(sh.pidPathABS); nil != err {
|
||||||
logging.Logger().Errorf("Container: Removing pid file has been failed [%v]", err)
|
logging.Logger().Errorf("Container: Removing pid file has been failed [%v]", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user