ing
This commit is contained in:
parent
94a4f3136c
commit
45f79e6b42
|
@ -2,7 +2,6 @@ package container
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
"path"
|
||||
|
||||
|
@ -36,17 +35,19 @@ func GetContainerCommand(name string) (cmd *exec.Cmd, pidPath string) {
|
|||
case ooccp.ContainerNetworkName:
|
||||
logConfigPath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerNetworkLogConfigFileName)
|
||||
exePath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerNetworkFileName)
|
||||
arg := fmt.Sprintf("-%s=%s -%s=%s", oocc.FlagPidFilePathName, pidPath, oocc.FlagLogConfigFilePathName, logConfigPath)
|
||||
|
||||
cmd = exec.Command(exePath, arg)
|
||||
arg1 := fmt.Sprintf("-%s=%s", oocc.FlagPidFilePathName, pidPath)
|
||||
arg2 := fmt.Sprintf("-%s=%s", oocc.FlagLogConfigFilePathName, logConfigPath)
|
||||
|
||||
cmd = exec.Command(exePath, arg1, arg2)
|
||||
case ooccp.ContainerDiscoveryName:
|
||||
logConfigPath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerDiscoveryLogConfigFileName)
|
||||
exePath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerDiscoveryFileName)
|
||||
arg := fmt.Sprintf("-%s=%s -%s=%s", oocc.FlagPidFilePathName, pidPath, oocc.FlagLogConfigFilePathName, logConfigPath)
|
||||
|
||||
log.Printf("arg:%s", arg)
|
||||
arg1 := fmt.Sprintf("-%s=%s", oocc.FlagPidFilePathName, pidPath)
|
||||
arg2 := fmt.Sprintf("-%s=%s", oocc.FlagLogConfigFilePathName, logConfigPath)
|
||||
|
||||
cmd = exec.Command(exePath, arg)
|
||||
cmd = exec.Command(exePath, arg1, arg2)
|
||||
default:
|
||||
}
|
||||
return
|
||||
|
|
|
@ -46,13 +46,15 @@ func (pm *probeManagers) Start() error {
|
|||
oocmp.HTTPEntry_Data: centralDataClient,
|
||||
}
|
||||
cdr.RegisterResource("CentralClients", centralClients)
|
||||
cdr.RegisterResource("ProbeRPCInvoker", probeRPCRegistry)
|
||||
|
||||
var (
|
||||
services []interface{}
|
||||
err error
|
||||
)
|
||||
|
||||
if services, err = cdr.GetInstancesByAnnotationName(oopca.ServiceTag); nil != err {
|
||||
services, err = cdr.GetInstancesByAnnotationName(oopca.ServiceTag)
|
||||
if nil != err {
|
||||
logging.Logger().Panicf("Probe: Cannot create instances of service %v", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package service
|
|||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
@ -13,6 +12,7 @@ import (
|
|||
cdr "git.loafle.net/commons_go/di/registry"
|
||||
"git.loafle.net/commons_go/logging"
|
||||
crc "git.loafle.net/commons_go/rpc/client"
|
||||
crr "git.loafle.net/commons_go/rpc/registry"
|
||||
"git.loafle.net/overflow/overflow_probes/client/container"
|
||||
)
|
||||
|
||||
|
@ -23,6 +23,8 @@ func init() {
|
|||
type ContainerService struct {
|
||||
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
|
||||
|
||||
ProbeRPCInvoker crr.RPCInvoker `annotation:"@Resource()"`
|
||||
|
||||
clients map[string]*containerState
|
||||
}
|
||||
|
||||
|
@ -72,6 +74,8 @@ func (cs *ContainerService) runProcess(name string) error {
|
|||
}
|
||||
|
||||
cmd, pidPath := container.GetContainerCommand(name)
|
||||
removePidFile(pidPath)
|
||||
|
||||
if err := cmd.Start(); nil != err {
|
||||
logging.Logger().Errorf("Probe: To run container(%s) failed err %v", name, err)
|
||||
return err
|
||||
|
@ -83,13 +87,13 @@ func (cs *ContainerService) runProcess(name string) error {
|
|||
}
|
||||
// port := 60000
|
||||
|
||||
client := container.New(port, nil)
|
||||
client := container.New(port, cs.ProbeRPCInvoker)
|
||||
if err := client.Connect(); nil != err {
|
||||
cmd.Process.Kill()
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("pid: %d", cmd.Process.Pid)
|
||||
logging.Logger().Debugf("Container[%s] pid: %d", name, cmd.Process.Pid)
|
||||
|
||||
cState := &containerState{
|
||||
pid: cmd.Process.Pid,
|
||||
|
@ -140,6 +144,14 @@ func (cs *ContainerService) killProcess(name string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func removePidFile(pidFilePath string) {
|
||||
if _, err := os.Stat(pidFilePath); err == nil {
|
||||
if err := os.Remove(pidFilePath); nil != err {
|
||||
logging.Logger().Errorf("Probe: Removing pid file has been failed [%v]", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func watchPidFileCreate(pidFilePath string, waitTime time.Duration) (int, error) {
|
||||
startTime := time.Now()
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
cda "git.loafle.net/commons_go/di/annotation"
|
||||
cdr "git.loafle.net/commons_go/di/registry"
|
||||
"git.loafle.net/commons_go/logging"
|
||||
ooccp "git.loafle.net/overflow/overflow_commons_go/config/probe"
|
||||
discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model"
|
||||
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
|
||||
|
@ -22,6 +23,8 @@ type DiscoveryService struct {
|
|||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoverZone(requesterID string, dz *discoveryM.DiscoveryZone) error {
|
||||
logging.Logger().Debugf("DiscoverZone: requesterID(%s)", requesterID)
|
||||
|
||||
return ds.ContainerService.Send(ooccp.ContainerDiscoveryName, "DiscoveryService.DiscoverZone", requesterID, dz)
|
||||
}
|
||||
|
||||
|
@ -39,6 +42,7 @@ func (ds *DiscoveryService) DiscoverService(requesterID string, port *discoveryM
|
|||
|
||||
// use by discovery
|
||||
func (ds *DiscoveryService) DiscoveredZone(requesterID string, zone *discoveryM.Zone) error {
|
||||
logging.Logger().Debugf("DiscoveredZone: requesterID(%s) network(%s) ip(%s) mac(%s) iface(%s)", requesterID, zone.Network, zone.IP, zone.Mac, zone.Iface)
|
||||
return ds.CentralService.Send(oocmp.HTTPEntry_Probe, "DiscoveryService.discoveredZone", requesterID, zone)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user