This commit is contained in:
geek 2018-04-20 20:19:14 +09:00
parent 264c1fc72b
commit 3d1a0e1686
4 changed files with 90 additions and 6 deletions

View File

@ -1,4 +1,4 @@
{ {
"tempKey": "38dc61ec42de11e8b0460242ac120002", "tempKey": "f2d22c4c448111e89c0ad28d1c524cb3",
"acceptedDate": "2018-04-18T16:57:23.23885679+09:00" "acceptedDate": "2018-04-20T19:03:12.521576174+09:00"
} }

0
_build/config/_ Normal file
View File

View File

@ -8,6 +8,8 @@ import (
ocncc "git.loafle.net/overflow/commons-go/noauthprobe/constants" ocncc "git.loafle.net/overflow/commons-go/noauthprobe/constants"
ocpcc "git.loafle.net/overflow/commons-go/probe/constants" ocpcc "git.loafle.net/overflow/commons-go/probe/constants"
"log"
"os/user"
) )
var ( var (
@ -24,6 +26,12 @@ func init() {
if "debug" == filepath.Base(exePath) { if "debug" == filepath.Base(exePath) {
rootDir = path.Join(binDir, "_build") rootDir = path.Join(binDir, "_build")
} else if "/tmp" == binDir {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
rootDir = path.Join(usr.HomeDir, "/go/src/git.loafle.net/overflow/probe/_build")
} else { } else {
rootDir = filepath.Clean(fmt.Sprintf("%s/..", binDir)) rootDir = filepath.Clean(fmt.Sprintf("%s/..", binDir))
} }

View File

@ -86,8 +86,8 @@ func (s *ContainerService) Send(containerType ocpcc.ContainerType, method string
func (s *ContainerService) getClient(containerType ocpcc.ContainerType) (*crc.Client, error) { func (s *ContainerService) getClient(containerType ocpcc.ContainerType) (*crc.Client, error) {
cs := s.checkContainer(containerType) cs := s.checkContainer(containerType)
if nil == cs { if nil == cs {
// _cs, err := s.runContainer(containerType) _cs, err := s.runContainer(containerType)
_cs, err := s.debugContainer(containerType) //_cs, err := s.debugContainer(containerType)
if nil != err { if nil != err {
return nil, err return nil, err
} }
@ -118,7 +118,7 @@ func (s *ContainerService) onDisconnected(connector csc.Connector) {
if !ok || nil == cs { if !ok || nil == cs {
return return
} }
logging.Logger().Debugf("Client[%s] has been disconnected", cs.containerType.String()) s.refreshContainer(cs.containerType)
} }
func (s *ContainerService) runContainer(containerType ocpcc.ContainerType) (*containerState, error) { func (s *ContainerService) runContainer(containerType ocpcc.ContainerType) (*containerState, error) {
@ -144,6 +144,7 @@ func (s *ContainerService) runContainer(containerType ocpcc.ContainerType) (*con
logging.Logger().Error(err) logging.Logger().Error(err)
} }
logging.Logger().Infof("Container[%s] has been stopped", containerType.String()) logging.Logger().Infof("Container[%s] has been stopped", containerType.String())
s.refreshContainer(containerType)
}(containerType, cmd) }(containerType, cmd)
cs := &containerState{ cs := &containerState{
@ -155,6 +156,71 @@ func (s *ContainerService) runContainer(containerType ocpcc.ContainerType) (*con
return cs, nil return cs, nil
} }
func (s *ContainerService) refreshContainer(containerType ocpcc.ContainerType) {
cs := s.checkContainer(containerType)
if nil == cs {
if _, err := s.getClient(containerType); nil != err {
logging.Logger().Error(err)
}
return
}
delete(s.connectorMap, cs.client.Connector)
err := cs.client.Stop(context.Background())
if nil != err {
logging.Logger().Error(err)
}
cs.client = nil
if _, err := s.getClient(containerType); nil != err {
logging.Logger().Error(err)
}
//
//if cs, ok := s.checkContainer(containerType); nil == cs {
// cs, ok := s.containerStates[containerType]
// if !ok {
// return
// }
// delete(s.connectorMap, cs.client.Connector)
//
// logging.Logger().Debugf("Client[%s]11 has been disconnected", cs.containerType.String())
// err := cs.client.Stop(context.Background())
// if nil != err {
// logging.Logger().Error(err)
// }
//
// client, err := container.NewClient(cs.containerType, cs.port, s.rpcServiceMap[cs.containerType])
// if nil != err {
// s.removeContainerState(cs.containerType)
// logging.Logger().Error(err)
// return
// }
// if err := client.Start(); nil != err {
// s.removeContainerState(cs.containerType)
// logging.Logger().Error(err)
// return
// }
// cs.client = client
// cs.client.Connector.SetOnDisconnected(s.onDisconnected)
// s.connectorMap[cs.client.Connector] = cs
//} else {
// cs, ok := s.containerStates[containerType]
// if !ok {
// return
// }
// delete(s.connectorMap, cs.client.Connector)
// err := cs.client.Stop(context.Background())
// if nil != err {
// logging.Logger().Error(err)
// }
// delete(s.containerStates, containerType)
// _, err = s.getClient(containerType)
// if nil != err {
// logging.Logger().Error(err)
// }
//}
}
func (s *ContainerService) debugContainer(containerType ocpcc.ContainerType) (*containerState, error) { func (s *ContainerService) debugContainer(containerType ocpcc.ContainerType) (*containerState, error) {
cs := &containerState{ cs := &containerState{
containerType: containerType, containerType: containerType,
@ -171,10 +237,20 @@ func (s *ContainerService) checkContainer(containerType ocpcc.ContainerType) *co
return nil return nil
} }
if nil != cs.cmd.ProcessState && cs.cmd.ProcessState.Exited() { p, err := os.FindProcess(cs.cmd.Process.Pid)
if nil != err {
s.removeContainerState(containerType) s.removeContainerState(containerType)
return nil return nil
} }
if nil == p {
s.removeContainerState(containerType)
return nil
}
//if nil != cs.cmd.ProcessState && cs.cmd.ProcessState.Exited() {
// s.removeContainerState(containerType)
// return nil
//}
return cs return cs
} }