mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 17:05:43 +03:00
Fixed the executor command
This commit is contained in:
@@ -18,6 +18,8 @@ import (
|
||||
//"github.com/hashicorp/nomad/client/getter"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
//"github.com/mitchellh/mapstructure"
|
||||
|
||||
"github.com/hashicorp/nomad/helper/discover"
|
||||
)
|
||||
|
||||
// ExecDriver fork/execs tasks using as many of the underlying OS's isolation
|
||||
@@ -117,10 +119,15 @@ func (d *ExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
|
||||
// return nil, fmt.Errorf("failed to start command: %v", err)
|
||||
// }
|
||||
//
|
||||
|
||||
bin, err := discover.NomadExecutable()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to find the nomad binary: %v", err)
|
||||
}
|
||||
executorClient := plugin.NewClient(&plugin.ClientConfig{
|
||||
HandshakeConfig: plugins.HandshakeConfig,
|
||||
Plugins: plugins.PluginMap,
|
||||
Cmd: exec.Command("/home/diptanuc/Projects/gocode/bin/nomad"),
|
||||
Cmd: exec.Command(bin, "executor"),
|
||||
})
|
||||
|
||||
rpcClient, err := executorClient.Client()
|
||||
|
||||
@@ -9,7 +9,9 @@ import (
|
||||
)
|
||||
|
||||
var HandshakeConfig = plugin.HandshakeConfig{
|
||||
ProtocolVersion: 1,
|
||||
ProtocolVersion: 1,
|
||||
MagicCookieKey: "executor_plugin",
|
||||
MagicCookieValue: "value",
|
||||
}
|
||||
|
||||
var PluginMap = map[string]plugin.Plugin{
|
||||
|
||||
32
client/driver/plugins/executor_basic.go
Normal file
32
client/driver/plugins/executor_basic.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// +build !linux
|
||||
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"time"
|
||||
)
|
||||
|
||||
type BasicExecutor struct {
|
||||
}
|
||||
|
||||
func NewExecutor() Executor {
|
||||
return &BasicExecutor{}
|
||||
}
|
||||
|
||||
func (e *BasicExecutor) LaunchCmd(cmd *exec.Cmd, ctx *ExecutorContext) (*ProcessState, error) {
|
||||
return &ProcessState{Pid: 5, ExitCode: -1, Time: time.Now()}, nil
|
||||
}
|
||||
|
||||
func (e *BasicExecutor) Wait() (*ProcessState, error) {
|
||||
time.Sleep(5 * time.Second)
|
||||
return &ProcessState{Pid: 0, ExitCode: 0, Time: time.Now()}, nil
|
||||
}
|
||||
|
||||
func (e *BasicExecutor) Exit() (*ProcessState, error) {
|
||||
return &ProcessState{Pid: 0, ExitCode: 0, Time: time.Now()}, nil
|
||||
}
|
||||
|
||||
func (e *BasicExecutor) ShutDown() (*ProcessState, error) {
|
||||
return &ProcessState{Pid: 0, ExitCode: 0, Time: time.Now()}, nil
|
||||
}
|
||||
@@ -8,22 +8,22 @@ import (
|
||||
"github.com/hashicorp/nomad/client/driver/plugins"
|
||||
)
|
||||
|
||||
type ExecutorPlugin struct {
|
||||
type ExecutorPluginCommand struct {
|
||||
Meta
|
||||
}
|
||||
|
||||
func (e *ExecutorPlugin) Help() string {
|
||||
func (e *ExecutorPluginCommand) Help() string {
|
||||
helpText := `
|
||||
This is a command used by Nomad internally to launch an executor plugin"
|
||||
`
|
||||
return strings.TrimSpace(helpText)
|
||||
}
|
||||
|
||||
func (e *ExecutorPlugin) Synopsis() string {
|
||||
func (e *ExecutorPluginCommand) Synopsis() string {
|
||||
return "internal - launch an executor plugin"
|
||||
}
|
||||
|
||||
func (e *ExecutorPlugin) Run(args []string) int {
|
||||
func (e *ExecutorPluginCommand) Run(args []string) int {
|
||||
plugin.Serve(&plugin.ServeConfig{
|
||||
HandshakeConfig: plugins.HandshakeConfig,
|
||||
Plugins: plugins.PluginMap,
|
||||
|
||||
@@ -57,6 +57,11 @@ func Commands(metaPtr *command.Meta) map[string]cli.CommandFactory {
|
||||
Meta: meta,
|
||||
}, nil
|
||||
},
|
||||
"executor": func() (cli.Command, error) {
|
||||
return &command.ExecutorPluginCommand{
|
||||
Meta: meta,
|
||||
}, nil
|
||||
},
|
||||
"fs ls": func() (cli.Command, error) {
|
||||
return &command.FSListCommand{
|
||||
Meta: meta,
|
||||
|
||||
Reference in New Issue
Block a user