Not syncing stdout and stderr of pluging with client

This commit is contained in:
Diptanu Choudhury
2016-02-04 17:36:31 -08:00
parent 9800b7dcfe
commit d8ed2949cd
8 changed files with 30 additions and 13 deletions

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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
}