From d8ed2949cdb7c08157402979f7688624e3595e09 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Thu, 4 Feb 2016 17:36:31 -0800 Subject: [PATCH] Not syncing stdout and stderr of pluging with client --- client/driver/exec.go | 3 ++- client/driver/executor/executor.go | 2 ++ client/driver/executor_plugin.go | 10 +++++----- client/driver/java.go | 4 +++- client/driver/qemu.go | 4 +++- client/driver/raw_exec.go | 3 ++- client/driver/utils.go | 4 +--- command/executor_plugin.go | 13 ++++++++++++- 8 files changed, 30 insertions(+), 13 deletions(-) diff --git a/client/driver/exec.go b/client/driver/exec.go index 5273f1d7f..c57c48e56 100644 --- a/client/driver/exec.go +++ b/client/driver/exec.go @@ -103,8 +103,9 @@ func (d *ExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, if err != nil { return nil, fmt.Errorf("unable to find the nomad binary: %v", err) } + pluginLogFile := filepath.Join(ctx.AllocDir.AllocDir, "plugin.out") pluginConfig := &plugin.ClientConfig{ - Cmd: exec.Command(bin, "executor"), + Cmd: exec.Command(bin, "executor", pluginLogFile), } exec, pluginClient, err := createExecutor(pluginConfig, d.config.LogOutput) diff --git a/client/driver/executor/executor.go b/client/driver/executor/executor.go index d4bc088e7..cdf153cb3 100644 --- a/client/driver/executor/executor.go +++ b/client/driver/executor/executor.go @@ -77,6 +77,8 @@ func NewExecutor(logger *log.Logger) Executor { // LaunchCmd launches a process and returns it's state. It also configures an // applies isolation on certain platforms. func (e *UniversalExecutor) LaunchCmd(command *ExecCommand, ctx *ExecutorContext) (*ProcessState, error) { + e.logger.Printf("[INFO] executor: launching command %v", command.Cmd) + e.ctx = ctx if err := e.configureTaskDir(); err != nil { diff --git a/client/driver/executor_plugin.go b/client/driver/executor_plugin.go index 9cb5f7720..57a95e326 100644 --- a/client/driver/executor_plugin.go +++ b/client/driver/executor_plugin.go @@ -1,10 +1,10 @@ package driver import ( + "io" "log" "net" "net/rpc" - "os" "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/client/driver/executor" @@ -16,8 +16,10 @@ var HandshakeConfig = plugin.HandshakeConfig{ MagicCookieValue: "e4327c2e01eabfd75a8a67adb114fb34a757d57eee7728d857a8cec6e91a7255", } -var PluginMap = map[string]plugin.Plugin{ - "executor": new(ExecutorPlugin), +func GetPluginMap(w io.Writer) map[string]plugin.Plugin { + p := new(ExecutorPlugin) + p.logger = log.New(w, "executor-plugin-server:", log.LstdFlags) + return map[string]plugin.Plugin{"executor": p} } // ExecutorReattachConfig is the config that we seralize and de-serialize and @@ -107,11 +109,9 @@ type ExecutorPlugin struct { } func (p *ExecutorPlugin) Server(*plugin.MuxBroker) (interface{}, error) { - p.logger = log.New(os.Stdout, "executor-plugin-server:", log.LstdFlags) return &ExecutorRPCServer{Impl: executor.NewExecutor(p.logger)}, nil } func (p *ExecutorPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) { - p.logger = log.New(os.Stdout, "executor-plugin-client:", log.LstdFlags) return &ExecutorRPC{client: c}, nil } diff --git a/client/driver/java.go b/client/driver/java.go index 74f295cf8..60bc6c3f4 100644 --- a/client/driver/java.go +++ b/client/driver/java.go @@ -148,8 +148,10 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, if err != nil { return nil, fmt.Errorf("unable to find the nomad binary: %v", err) } + + pluginLogFile := filepath.Join(ctx.AllocDir.AllocDir, "plugin.out") pluginConfig := &plugin.ClientConfig{ - Cmd: exec.Command(bin, "executor"), + Cmd: exec.Command(bin, "executor", pluginLogFile), } exec, pluginClient, err := createExecutor(pluginConfig, d.config.LogOutput) diff --git a/client/driver/qemu.go b/client/driver/qemu.go index e7753fcc9..cfe0f19fb 100644 --- a/client/driver/qemu.go +++ b/client/driver/qemu.go @@ -192,8 +192,10 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, if err != nil { return nil, fmt.Errorf("unable to find the nomad binary: %v", err) } + + pluginLogFile := filepath.Join(ctx.AllocDir.AllocDir, "plugin.out") pluginConfig := &plugin.ClientConfig{ - Cmd: exec.Command(bin, "executor"), + Cmd: exec.Command(bin, "executor", pluginLogFile), } exec, pluginClient, err := createExecutor(pluginConfig, d.config.LogOutput) diff --git a/client/driver/raw_exec.go b/client/driver/raw_exec.go index 5b92e6d85..1875caab6 100644 --- a/client/driver/raw_exec.go +++ b/client/driver/raw_exec.go @@ -99,8 +99,9 @@ func (d *RawExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandl if err != nil { return nil, fmt.Errorf("unable to find the nomad binary: %v", err) } + pluginLogFile := filepath.Join(ctx.AllocDir.AllocDir, "plugin.out") pluginConfig := &plugin.ClientConfig{ - Cmd: exec.Command(bin, "executor"), + Cmd: exec.Command(bin, "executor", pluginLogFile), } exec, pluginClient, err := createExecutor(pluginConfig, d.config.LogOutput) diff --git a/client/driver/utils.go b/client/driver/utils.go index 972876eeb..b42c4a74a 100644 --- a/client/driver/utils.go +++ b/client/driver/utils.go @@ -12,9 +12,7 @@ import ( func createExecutor(config *plugin.ClientConfig, w io.Writer) (executor.Executor, *plugin.Client, error) { config.HandshakeConfig = HandshakeConfig - config.Plugins = PluginMap - config.SyncStdout = w - config.SyncStderr = w + config.Plugins = GetPluginMap(w) executorClient := plugin.NewClient(config) rpcClient, err := executorClient.Client() if err != nil { diff --git a/command/executor_plugin.go b/command/executor_plugin.go index 15a84db84..666cab961 100644 --- a/command/executor_plugin.go +++ b/command/executor_plugin.go @@ -1,6 +1,7 @@ package command import ( + "os" "strings" "github.com/hashicorp/go-plugin" @@ -24,9 +25,19 @@ func (e *ExecutorPluginCommand) Synopsis() string { } func (e *ExecutorPluginCommand) Run(args []string) int { + if len(args) == 0 { + e.Ui.Error("log output file isn't provided") + return 1 + } + logFileName := args[0] + stdo, err := os.OpenFile(logFileName, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666) + if err != nil { + e.Ui.Error(err.Error()) + return 1 + } plugin.Serve(&plugin.ServeConfig{ HandshakeConfig: driver.HandshakeConfig, - Plugins: driver.PluginMap, + Plugins: driver.GetPluginMap(stdo), }) return 0 }