From 3d1a0e1686f9444d40f56edc0f6b935b083eb69e Mon Sep 17 00:00:00 2001 From: geek Date: Fri, 20 Apr 2018 20:19:14 +0900 Subject: [PATCH] ing --- _build/bin/auth.json | 4 +- _build/config/_ | 0 config/path.go | 8 ++++ service/ContainerService.go | 84 +++++++++++++++++++++++++++++++++++-- 4 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 _build/config/_ diff --git a/_build/bin/auth.json b/_build/bin/auth.json index d9bbb50..76c5616 100644 --- a/_build/bin/auth.json +++ b/_build/bin/auth.json @@ -1,4 +1,4 @@ { - "tempKey": "38dc61ec42de11e8b0460242ac120002", - "acceptedDate": "2018-04-18T16:57:23.23885679+09:00" + "tempKey": "f2d22c4c448111e89c0ad28d1c524cb3", + "acceptedDate": "2018-04-20T19:03:12.521576174+09:00" } \ No newline at end of file diff --git a/_build/config/_ b/_build/config/_ new file mode 100644 index 0000000..e69de29 diff --git a/config/path.go b/config/path.go index 9fde01d..0eba223 100644 --- a/config/path.go +++ b/config/path.go @@ -8,6 +8,8 @@ import ( ocncc "git.loafle.net/overflow/commons-go/noauthprobe/constants" ocpcc "git.loafle.net/overflow/commons-go/probe/constants" + "log" + "os/user" ) var ( @@ -24,6 +26,12 @@ func init() { if "debug" == filepath.Base(exePath) { 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 { rootDir = filepath.Clean(fmt.Sprintf("%s/..", binDir)) } diff --git a/service/ContainerService.go b/service/ContainerService.go index 6be1889..03a681d 100644 --- a/service/ContainerService.go +++ b/service/ContainerService.go @@ -86,8 +86,8 @@ func (s *ContainerService) Send(containerType ocpcc.ContainerType, method string func (s *ContainerService) getClient(containerType ocpcc.ContainerType) (*crc.Client, error) { cs := s.checkContainer(containerType) if nil == cs { - // _cs, err := s.runContainer(containerType) - _cs, err := s.debugContainer(containerType) + _cs, err := s.runContainer(containerType) + //_cs, err := s.debugContainer(containerType) if nil != err { return nil, err } @@ -118,7 +118,7 @@ func (s *ContainerService) onDisconnected(connector csc.Connector) { if !ok || nil == cs { 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) { @@ -144,6 +144,7 @@ func (s *ContainerService) runContainer(containerType ocpcc.ContainerType) (*con logging.Logger().Error(err) } logging.Logger().Infof("Container[%s] has been stopped", containerType.String()) + s.refreshContainer(containerType) }(containerType, cmd) cs := &containerState{ @@ -155,6 +156,71 @@ func (s *ContainerService) runContainer(containerType ocpcc.ContainerType) (*con 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) { cs := &containerState{ containerType: containerType, @@ -171,10 +237,20 @@ func (s *ContainerService) checkContainer(containerType ocpcc.ContainerType) *co 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) 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 }