ing
This commit is contained in:
parent
ba6bb15295
commit
1e7be8bc07
|
@ -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,
|
||||
pidPathABS: pidPathABS,
|
||||
}
|
||||
|
||||
sh.Name = serverName
|
||||
|
@ -25,6 +32,7 @@ type ServerHandlers struct {
|
|||
server.ServerHandlers
|
||||
|
||||
pidPath string
|
||||
pidPathABS string
|
||||
port int
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user