overflow_probes/client/container/client.go

47 lines
1.4 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-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:
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)
cmd = exec.Command(javaPath, "-jar", jarPath, pidPath)
case ooccp.ContainerNetworkName:
exePath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerNetworkFileName)
arg := fmt.Sprintf("-pid-path=%s", pidPath)
cmd = exec.Command(exePath, arg)
case ooccp.ContainerDiscoveryName:
exePath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerDiscoveryFileName)
arg := fmt.Sprintf("-pid-path=%s", pidPath)
cmd = exec.Command(exePath, arg)
default:
}
return
}