ing
This commit is contained in:
parent
9a68cbc02b
commit
f93dcf388a
|
@ -5,11 +5,13 @@ import (
|
|||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
logging "git.loafle.net/commons/logging-go"
|
||||
"git.loafle.net/commons/server-go"
|
||||
cssn "git.loafle.net/commons/server-go/socket/net"
|
||||
occi "git.loafle.net/overflow/commons-go/core/interfaces"
|
||||
)
|
||||
|
||||
type ServerHandler interface {
|
||||
|
@ -20,6 +22,8 @@ type ServerHandlers struct {
|
|||
cssn.ServerHandlers
|
||||
|
||||
PIDFilePath string
|
||||
Services []interface{}
|
||||
OrderedServices []reflect.Type
|
||||
|
||||
port int
|
||||
}
|
||||
|
@ -29,6 +33,10 @@ func (sh *ServerHandlers) Init(serverCtx server.ServerCtx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := occi.ExecServices(sh.Services, occi.ServiceMethodInit, sh.OrderedServices, false); nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -37,6 +45,10 @@ func (sh *ServerHandlers) OnStart(serverCtx server.ServerCtx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := occi.ExecServices(sh.Services, occi.ServiceMethodStart, sh.OrderedServices, false); nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := os.Stat(sh.PIDFilePath); os.IsExist(err) {
|
||||
if err := os.Remove(sh.PIDFilePath); nil != err {
|
||||
logging.Logger().Errorf("Container[%s]: Removing pid file has been failed [%v]", sh.Name, err)
|
||||
|
@ -52,6 +64,10 @@ func (sh *ServerHandlers) OnStart(serverCtx server.ServerCtx) error {
|
|||
}
|
||||
|
||||
func (sh *ServerHandlers) OnStop(serverCtx server.ServerCtx) {
|
||||
if err := occi.ExecServices(sh.Services, occi.ServiceMethodStop, sh.OrderedServices, true); nil != err {
|
||||
logging.Logger().Errorf("Container[%s]: Service stop err %v", sh.Name, err)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(sh.PIDFilePath); os.IsExist(err) {
|
||||
if err := os.Remove(sh.PIDFilePath); nil != err {
|
||||
logging.Logger().Errorf("Container: Removing pid file has been failed [%v]", err)
|
||||
|
@ -62,6 +78,9 @@ func (sh *ServerHandlers) OnStop(serverCtx server.ServerCtx) {
|
|||
}
|
||||
|
||||
func (sh *ServerHandlers) Destroy(serverCtx server.ServerCtx) {
|
||||
if err := occi.ExecServices(sh.Services, occi.ServiceMethodDestroy, sh.OrderedServices, true); nil != err {
|
||||
logging.Logger().Errorf("Container[%s]: Service destroy err %v", sh.Name, err)
|
||||
}
|
||||
|
||||
sh.ServerHandlers.Destroy(serverCtx)
|
||||
}
|
||||
|
@ -88,5 +107,13 @@ func (sh *ServerHandlers) Validate() error {
|
|||
return fmt.Errorf("Container[%s]: The path of pid file must be specified", sh.Name)
|
||||
}
|
||||
|
||||
if nil == sh.Services {
|
||||
return fmt.Errorf("Container[%s]: Services must be specified", sh.Name)
|
||||
}
|
||||
|
||||
if nil == sh.OrderedServices {
|
||||
return fmt.Errorf("Container[%s]: OrderedServices must be specified", sh.Name)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user