package service import ( "reflect" cda "git.loafle.net/commons_go/di/annotation" cdr "git.loafle.net/commons_go/di/registry" crc "git.loafle.net/commons_go/rpc/client" ) func init() { cdr.RegisterType(reflect.TypeOf((*ContainerService)(nil)), &cda.ComponentAnnotation{}) } type ContainerService struct { clients map[string]*containerState } type containerState struct { socketName string pid int client crc.Client } func (cs *ContainerService) Call(name string, result interface{}, method string, params ...interface{}) error { c, err := cs.GetClient(name) if nil != err { return err } return c.Call(result, method, params...) } func (cs *ContainerService) Send(name string, method string, params ...interface{}) error { c, err := cs.GetClient(name) if nil != err { return err } return c.Send(method, params...) } func (cs *ContainerService) GetClient(name string) (crc.Client, error) { return nil, nil } func (cs *ContainerService) Connect(name string) error { return nil } func (cs *ContainerService) runProcess(name string) error { ok := cs.checkProcess(name) if ok { return nil } // runCmd := config.Config.Paths["root"] + "/" + config.Config.Paths["bin"] + "/" + name + "/start" // sockFile := uuid.NewV4().String() // sockArg := fmt.Sprintf("-sock=\"%s\"", sockFile) // cmd := exec.Command(runCmd, sockArg) // if err := cmd.Start(); nil != err { // logging.Logger().Error(fmt.Sprintf("Probe: To run container(%s) failed err %v", name, err)) // return err // } // time.Sleep(time.Duration(time.Second * 2)) // cs := &containerState{ // socketName: sockFile, // pid: cmd.Process.Pid, // } // cs.client = oopmcc.New(sockFile, nil) // // write pid file // cs.containerClients[name] = cs return nil } func (cs *ContainerService) checkProcess(name string) bool { return false } func (cs *ContainerService) killProcess(name string) error { // cs, ok := cs.containerClients[name] // if !ok || nil == cs || nil == cs.client { // return fmt.Errorf("Probe: Container[%s] is not exist", name) // } // p, err := os.FindProcess(cs.pid) // if nil != err { // return err // } // if err = p.Kill(); nil != err { // return err // } // // remove pid file return nil }