overflow_probes/client/container/client.go

55 lines
2.0 KiB
Go
Raw Normal View History

2018-03-15 13:52:23 +00:00
package container
2017-12-05 08:21:47 +00:00
import (
2018-03-15 13:52:23 +00:00
"fmt"
"os/exec"
"path"
2017-12-05 08:21:47 +00:00
crc "git.loafle.net/commons_go/rpc/client"
crr "git.loafle.net/commons_go/rpc/registry"
2018-03-21 10:22:13 +00:00
oocc "git.loafle.net/overflow/overflow_commons_go/config"
2018-03-15 13:52:23 +00:00
ooccp "git.loafle.net/overflow/overflow_commons_go/config/probe"
2017-12-05 08:21:47 +00:00
oopcc "git.loafle.net/overflow/overflow_probe_container/client"
2018-03-15 13:52:23 +00:00
"git.loafle.net/overflow/overflow_probes/config"
2017-12-05 08:21:47 +00:00
)
2018-03-15 13:52:23 +00:00
func New(port int, rpcInvoker crr.RPCInvoker) crc.Client {
addr := fmt.Sprintf("localhost:%d", port)
2017-12-05 08:21:47 +00:00
2018-03-15 13:52:23 +00:00
c := oopcc.New(addr, rpcInvoker)
2017-12-05 08:21:47 +00:00
return c
}
2018-03-15 13:52:23 +00:00
func GetContainerCommand(name string) (cmd *exec.Cmd, pidPath string) {
pidPath = path.Join(config.Config.Paths["root"], ooccp.PathPID, name+".pid")
switch name {
case ooccp.ContainerGeneralName:
2018-03-21 10:22:13 +00:00
logConfigPath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerGeneralLogConfigFileName)
2018-03-15 13:52:23 +00:00
javaPath := path.Join(config.Config.Paths["root"], ooccp.PathJRE, "bin", "java")
jarPath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerGeneralFileName)
// arg := fmt.Sprintf("-jar %s %s", jarPath, pidPath)
2018-03-21 10:22:13 +00:00
cmd = exec.Command(javaPath, "-jar", jarPath, pidPath, logConfigPath)
2018-03-15 13:52:23 +00:00
case ooccp.ContainerNetworkName:
2018-03-21 10:22:13 +00:00
logConfigPath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerNetworkLogConfigFileName)
2018-03-15 13:52:23 +00:00
exePath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerNetworkFileName)
2018-03-22 16:10:38 +00:00
arg1 := fmt.Sprintf("-%s=%s", oocc.FlagPidFilePathName, pidPath)
arg2 := fmt.Sprintf("-%s=%s", oocc.FlagLogConfigFilePathName, logConfigPath)
cmd = exec.Command(exePath, arg1, arg2)
2018-03-15 13:52:23 +00:00
case ooccp.ContainerDiscoveryName:
2018-03-21 10:22:13 +00:00
logConfigPath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerDiscoveryLogConfigFileName)
2018-03-15 13:52:23 +00:00
exePath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerDiscoveryFileName)
2018-03-21 10:22:13 +00:00
2018-03-22 16:10:38 +00:00
arg1 := fmt.Sprintf("-%s=%s", oocc.FlagPidFilePathName, pidPath)
arg2 := fmt.Sprintf("-%s=%s", oocc.FlagLogConfigFilePathName, logConfigPath)
2018-03-15 13:52:23 +00:00
2018-03-22 16:10:38 +00:00
cmd = exec.Command(exePath, arg1, arg2)
2018-03-15 13:52:23 +00:00
default:
}
return
}