5dee1141d1
* client/executor: refactor client to remove interpolation * executor: POC libcontainer based executor * vendor: use hashicorp libcontainer fork * vendor: add libcontainer/nsenter dep * executor: updated executor interface to simplify operations * executor: implement logging pipe * logmon: new logmon plugin to manage task logs * driver/executor: use logmon for log management * executor: fix tests and windows build * executor: fix logging key names * executor: fix test failures * executor: add config field to toggle between using libcontainer and standard executors * logmon: use discover utility to discover nomad executable * executor: only call libcontainer-shim on main in linux * logmon: use seperate path configs for stdout/stderr fifos * executor: windows fixes * executor: created reusable pid stats collection utility that can be used in an executor * executor: update fifo.Open calls * executor: fix build * remove executor from docker driver * executor: Shutdown func to kill and cleanup executor and its children * executor: move linux specific universal executor funcs to seperate file * move logmon initialization to a task runner hook * client: doc fixes and renaming from code review * taskrunner: use shared config struct for logmon fifo fields * taskrunner: logmon only needs to be started once per task
70 lines
1.5 KiB
Go
70 lines
1.5 KiB
Go
package logmon
|
|
|
|
import (
|
|
"context"
|
|
"os/exec"
|
|
|
|
hclog "github.com/hashicorp/go-hclog"
|
|
plugin "github.com/hashicorp/go-plugin"
|
|
"github.com/hashicorp/nomad/client/logmon/proto"
|
|
"github.com/hashicorp/nomad/helper/discover"
|
|
"github.com/hashicorp/nomad/plugins/base"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
// LaunchLogMon an instance of logmon
|
|
// TODO: Integrate with base plugin loader
|
|
func LaunchLogMon(logger hclog.Logger) (LogMon, *plugin.Client, error) {
|
|
logger = logger.Named("logmon-launcher")
|
|
bin, err := discover.NomadExecutable()
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
client := plugin.NewClient(&plugin.ClientConfig{
|
|
HandshakeConfig: base.Handshake,
|
|
Plugins: map[string]plugin.Plugin{
|
|
"logmon": NewPlugin(NewLogMon(hclog.L().Named("logmon"))),
|
|
},
|
|
Cmd: exec.Command(bin, "logmon"),
|
|
AllowedProtocols: []plugin.Protocol{
|
|
plugin.ProtocolGRPC,
|
|
},
|
|
})
|
|
|
|
rpcClient, err := client.Client()
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
raw, err := rpcClient.Dispense("logmon")
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
l := raw.(LogMon)
|
|
return l, client, nil
|
|
|
|
}
|
|
|
|
type Plugin struct {
|
|
plugin.NetRPCUnsupportedPlugin
|
|
impl LogMon
|
|
}
|
|
|
|
func NewPlugin(i LogMon) plugin.Plugin {
|
|
return &Plugin{impl: i}
|
|
}
|
|
|
|
func (p *Plugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
|
|
proto.RegisterLogMonServer(s, &logmonServer{
|
|
impl: p.impl,
|
|
broker: broker,
|
|
})
|
|
return nil
|
|
}
|
|
|
|
func (p *Plugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
|
|
return &logmonClient{client: proto.NewLogMonClient(c)}, nil
|
|
}
|