2016-02-02 21:38:38 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2016-02-05 01:36:31 +00:00
|
|
|
"os"
|
2016-02-02 21:38:38 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-plugin"
|
|
|
|
|
2016-02-05 00:03:17 +00:00
|
|
|
"github.com/hashicorp/nomad/client/driver"
|
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-09 19:21:51 +00:00
|
|
|
if len(args) != 2 {
|
|
|
|
e.Ui.Error("log output file and log level are not provided")
|
2016-02-05 01:36:31 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
logFileName := args[0]
|
2017-01-09 19:21:51 +00:00
|
|
|
logLevel := args[1]
|
2016-02-05 01:36:31 +00:00
|
|
|
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
|
|
|
|
}
|
2016-02-02 21:38:38 +00:00
|
|
|
plugin.Serve(&plugin.ServeConfig{
|
2016-02-05 00:03:17 +00:00
|
|
|
HandshakeConfig: driver.HandshakeConfig,
|
2017-01-09 19:21:51 +00:00
|
|
|
Plugins: driver.GetPluginMap(stdo, logLevel),
|
2016-02-02 21:38:38 +00:00
|
|
|
})
|
|
|
|
return 0
|
|
|
|
}
|