github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/command/executor_plugin.go (about) 1 package command 2 3 import ( 4 "encoding/json" 5 "os" 6 "strings" 7 8 "github.com/hashicorp/go-plugin" 9 10 "github.com/hashicorp/nomad/client/driver" 11 dstructs "github.com/hashicorp/nomad/client/driver/structs" 12 ) 13 14 type ExecutorPluginCommand struct { 15 Meta 16 } 17 18 func (e *ExecutorPluginCommand) Help() string { 19 helpText := ` 20 This is a command used by Nomad internally to launch an executor plugin" 21 ` 22 return strings.TrimSpace(helpText) 23 } 24 25 func (e *ExecutorPluginCommand) Synopsis() string { 26 return "internal - launch an executor plugin" 27 } 28 29 func (e *ExecutorPluginCommand) Run(args []string) int { 30 if len(args) != 1 { 31 e.Ui.Error("json configuration not provided") 32 return 1 33 } 34 config := args[0] 35 var executorConfig dstructs.ExecutorConfig 36 if err := json.Unmarshal([]byte(config), &executorConfig); err != nil { 37 return 1 38 } 39 stdo, err := os.OpenFile(executorConfig.LogFile, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666) 40 if err != nil { 41 e.Ui.Error(err.Error()) 42 return 1 43 } 44 plugin.Serve(&plugin.ServeConfig{ 45 HandshakeConfig: driver.HandshakeConfig, 46 Plugins: driver.GetPluginMap(stdo, executorConfig.LogLevel), 47 }) 48 return 0 49 }