open-nomad/command/executor_plugin.go

55 lines
1.2 KiB
Go
Raw Normal View History

2016-02-02 21:38:38 +00:00
package command
import (
2017-01-12 19:50:49 +00:00
"encoding/json"
"os"
2016-02-02 21:38:38 +00:00
"strings"
hclog "github.com/hashicorp/go-hclog"
2016-02-02 21:38:38 +00:00
"github.com/hashicorp/go-plugin"
2018-11-30 09:59:23 +00:00
"github.com/hashicorp/nomad/plugins/base"
2018-11-29 13:59:53 +00:00
"github.com/hashicorp/nomad/plugins/executor"
2016-02-02 21:38:38 +00:00
)
2016-02-02 22:36:11 +00:00
type ExecutorPluginCommand struct {
2016-02-02 21:38:38 +00:00
Meta
}
2016-02-02 22:36:11 +00:00
func (e *ExecutorPluginCommand) Help() string {
2016-02-02 21:38:38 +00:00
helpText := `
This is a command used by Nomad internally to launch an executor plugin"
`
return strings.TrimSpace(helpText)
}
2016-02-02 22:36:11 +00:00
func (e *ExecutorPluginCommand) Synopsis() string {
2016-02-02 21:38:38 +00:00
return "internal - launch an executor plugin"
}
2016-02-02 22:36:11 +00:00
func (e *ExecutorPluginCommand) Run(args []string) int {
2017-01-12 19:50:49 +00:00
if len(args) != 1 {
e.Ui.Error("json configuration not provided")
return 1
}
2017-01-12 19:50:49 +00:00
config := args[0]
2018-11-29 13:59:53 +00:00
var executorConfig executor.ExecutorConfig
2017-01-12 19:50:49 +00:00
if err := json.Unmarshal([]byte(config), &executorConfig); err != nil {
return 1
}
stdo, err := os.OpenFile(executorConfig.LogFile, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
if err != nil {
e.Ui.Error(err.Error())
return 1
}
2016-02-02 21:38:38 +00:00
plugin.Serve(&plugin.ServeConfig{
2018-11-30 09:59:23 +00:00
HandshakeConfig: base.Handshake,
2018-11-29 13:59:53 +00:00
Plugins: executor.GetPluginMap(
stdo,
hclog.LevelFromString(executorConfig.LogLevel),
executorConfig.FSIsolation,
),
2016-02-02 21:38:38 +00:00
})
return 0
}