diff --git a/service/ContainerService.go b/service/ContainerService.go index a74feac..c47287f 100644 --- a/service/ContainerService.go +++ b/service/ContainerService.go @@ -141,13 +141,13 @@ func (s *ContainerService) runContainer(containerType occp.ContainerType) (*cont return nil, err } - go func(containerType occp.ContainerType, cmd *exec.Cmd) { - if err := cmd.Wait(); nil != err { - logging.Logger().Error(err) - } - logging.Logger().Infof("Container[%s] has been stopped", containerType.String()) - s.refreshContainer(containerType) - }(containerType, cmd) + // go func(containerType occp.ContainerType, cmd *exec.Cmd) { + // if err := cmd.Wait(); nil != err { + // logging.Logger().Error(err) + // } + // logging.Logger().Infof("Container[%s] has been stopped", containerType.String()) + // s.refreshContainer(containerType) + // }(containerType, cmd) cs := &containerState{ containerType: containerType, @@ -173,6 +173,7 @@ func (s *ContainerService) refreshContainer(containerType occp.ContainerType) { logging.Logger().Error(err) } cs.client = nil + delete(s.containerStates, containerType) if _, err := s.getClient(containerType); nil != err { logging.Logger().Error(err) } @@ -238,20 +239,20 @@ func (s *ContainerService) checkContainer(containerType occp.ContainerType) *con return nil } - p, err := os.FindProcess(cs.cmd.Process.Pid) - if nil != err { - s.removeContainerState(containerType) - return nil - } - if nil == p { - s.removeContainerState(containerType) - return nil - } + // 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 - //} + // if nil != cs.cmd.ProcessState && cs.cmd.ProcessState.Exited() { + // s.removeContainerState(containerType) + // return nil + // } return cs } @@ -276,8 +277,10 @@ func (s *ContainerService) removeContainerState(containerType occp.ContainerType return } - delete(s.connectorMap, cs.client.Connector) - cs.client.Stop(context.Background()) + if nil != cs.client { + delete(s.connectorMap, cs.client.Connector) + cs.client.Stop(context.Background()) + } s.killContainer(containerType) delete(s.containerStates, containerType) }