overflow_probes/client/container/client.go
crusader f073163bf7 ing
2018-03-15 22:52:23 +09:00

47 lines
1.4 KiB
Go

package container
import (
"fmt"
"os/exec"
"path"
crc "git.loafle.net/commons_go/rpc/client"
crr "git.loafle.net/commons_go/rpc/registry"
ooccp "git.loafle.net/overflow/overflow_commons_go/config/probe"
oopcc "git.loafle.net/overflow/overflow_probe_container/client"
"git.loafle.net/overflow/overflow_probes/config"
)
func New(port int, rpcInvoker crr.RPCInvoker) crc.Client {
addr := fmt.Sprintf("localhost:%d", port)
c := oopcc.New(addr, rpcInvoker)
return c
}
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
}