overflow_probes/client/container/client.go

48 lines
1.3 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"
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) {
2018-03-26 06:55:38 +00:00
pidPath = config.ContainerPIDPath(name)
logConfigPath := config.ContainerLogConfigPath(name)
binPath := config.ContainerBinPath(name)
2018-03-15 13:52:23 +00:00
switch name {
case ooccp.ContainerGeneralName:
2018-03-26 06:55:38 +00:00
javaPath := config.JavaBinPath()
2018-03-15 13:52:23 +00:00
2018-03-26 06:55:38 +00:00
cmd = exec.Command(javaPath, "-jar", binPath, pidPath, logConfigPath)
2018-03-15 13:52:23 +00:00
case ooccp.ContainerNetworkName:
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-26 06:55:38 +00:00
cmd = exec.Command(binPath, arg1, arg2)
2018-03-15 13:52:23 +00:00
case ooccp.ContainerDiscoveryName:
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-26 06:55:38 +00:00
cmd = exec.Command(binPath, arg1, arg2)
2018-03-15 13:52:23 +00:00
default:
}
return
}