From 1e7be8bc073a9c3ee318dd60ef5b204c143fc808 Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 22 Mar 2018 21:38:00 +0900 Subject: [PATCH] ing --- server/server_handlers.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/server/server_handlers.go b/server/server_handlers.go index 631cfd9..850ddb9 100644 --- a/server/server_handlers.go +++ b/server/server_handlers.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "net" "os" + "path/filepath" "strconv" "git.loafle.net/commons_go/logging" @@ -12,8 +13,14 @@ import ( ) 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{ - pidPath: pidPath, + pidPath: pidPath, + pidPathABS: pidPathABS, } sh.Name = serverName @@ -24,8 +31,9 @@ func NewServerHandler(pidPath string, serverName string, socketHandler SocketHan type ServerHandlers struct { server.ServerHandlers - pidPath string - port int + pidPath string + pidPathABS string + port int } 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) { sh.ServerHandlers.OnStart(serverCTX) - if _, err := os.Stat(sh.pidPath); os.IsExist(err) { - if err := os.Remove(sh.pidPath); nil != err { + if _, err := os.Stat(sh.pidPathABS); os.IsExist(err) { + if err := os.Remove(sh.pidPathABS); nil != err { logging.Logger().Errorf("Container: Removing pid file has been failed [%v]", err) } } 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) { - if _, err := os.Stat(sh.pidPath); os.IsExist(err) { - if err := os.Remove(sh.pidPath); nil != err { + if _, err := os.Stat(sh.pidPathABS); os.IsExist(err) { + if err := os.Remove(sh.pidPathABS); nil != err { logging.Logger().Errorf("Container: Removing pid file has been failed [%v]", err) } }