86 lines
1.7 KiB
Go
86 lines
1.7 KiB
Go
package container
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"time"
|
|
|
|
"git.loafle.net/commons_go/logging"
|
|
crc "git.loafle.net/commons_go/rpc/client"
|
|
oopcc "git.loafle.net/overflow/overflow_probes/client/container"
|
|
uuid "github.com/satori/go.uuid"
|
|
)
|
|
|
|
type ContainerManager interface {
|
|
GetClient(name string) crc.Client
|
|
}
|
|
|
|
type containerManager struct {
|
|
containerClients map[string]*containerState
|
|
}
|
|
|
|
type containerState struct {
|
|
socketName string
|
|
pid int
|
|
client crc.Client
|
|
}
|
|
|
|
func (cm *containerManager) GetClient(name string) crc.Client {
|
|
return nil
|
|
}
|
|
|
|
func (cm *containerManager) CheckClient(name string) bool {
|
|
cs, ok := cm.containerClients[name]
|
|
if !ok || nil == cs || nil == cs.client {
|
|
return false
|
|
}
|
|
|
|
stateOk := false
|
|
if err := cs.client.Call(&stateOk, "StateService.State"); nil != err {
|
|
logging.Logger().Error(fmt.Sprintf("Probe: Call[%s(%s)] err %v", name, "StateService.State", err))
|
|
return false
|
|
}
|
|
|
|
return stateOk
|
|
}
|
|
|
|
func (cm *containerManager) ConnectClient(name string) error {
|
|
|
|
return nil
|
|
}
|
|
|
|
func (cm *containerManager) runProcess(name string) error {
|
|
sockFile := uuid.NewV4().String()
|
|
sockArg := fmt.Sprintf("-sock \"%s\"", sockFile)
|
|
|
|
cmd := exec.Command("", 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 = oopcc.New(sockFile, nil)
|
|
// write pid file
|
|
cm.containerClients[name] = cs
|
|
|
|
return nil
|
|
}
|
|
|
|
// func (cm *containerManager) {
|
|
|
|
// }
|
|
// func (cm *containerManager) {
|
|
|
|
// }
|
|
// func (cm *containerManager) {
|
|
|
|
// }
|
|
// func (cm *containerManager) {
|
|
|
|
// }
|