overflow_probes/service/ContainerService.go

92 lines
2.0 KiB
Go
Raw Normal View History

2017-12-08 08:31:45 +00:00
package service
import (
crc "git.loafle.net/commons_go/rpc/client"
)
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
}