diff options
author | Alex Auvolat <alex@adnab.me> | 2022-11-28 17:15:12 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-11-28 17:15:12 +0100 |
commit | bf3165a7069fc6dcf9ae3a28be3af07fe8b4e1c2 (patch) | |
tree | 32f52eeb5d60ae33e8a40c2d8b26d70cac19a473 /executor/z_executor_cmd.go | |
parent | 63e31b9ed97f34f4ea709f505c37f5e8968a0f36 (diff) | |
download | nomad-driver-nix2-bf3165a7069fc6dcf9ae3a28be3af07fe8b4e1c2.tar.gz nomad-driver-nix2-bf3165a7069fc6dcf9ae3a28be3af07fe8b4e1c2.zip |
Vendor executor module so that we can patch it
Diffstat (limited to 'executor/z_executor_cmd.go')
-rw-r--r-- | executor/z_executor_cmd.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/executor/z_executor_cmd.go b/executor/z_executor_cmd.go new file mode 100644 index 0000000..5a5f13b --- /dev/null +++ b/executor/z_executor_cmd.go @@ -0,0 +1,55 @@ +package executor + +import ( + "encoding/json" + "os" + + hclog "github.com/hashicorp/go-hclog" + plugin "github.com/hashicorp/go-plugin" + + "github.com/hashicorp/nomad/plugins/base" +) + +// Install a plugin cli handler to ease working with tests +// and external plugins. +// This init() must be initialized last in package required by the child plugin +// process. It's recommended to avoid any other `init()` or inline any necessary calls +// here. See eeaa95d commit message for more details. +func init() { + if len(os.Args) > 1 && os.Args[1] == "executor" { + if len(os.Args) != 3 { + hclog.L().Error("json configuration not provided") + os.Exit(1) + } + + config := os.Args[2] + var executorConfig ExecutorConfig + if err := json.Unmarshal([]byte(config), &executorConfig); err != nil { + os.Exit(1) + } + + f, err := os.OpenFile(executorConfig.LogFile, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666) + if err != nil { + hclog.L().Error(err.Error()) + os.Exit(1) + } + + // Create the logger + logger := hclog.New(&hclog.LoggerOptions{ + Level: hclog.LevelFromString(executorConfig.LogLevel), + JSONFormat: true, + Output: f, + }) + + plugin.Serve(&plugin.ServeConfig{ + HandshakeConfig: base.Handshake, + Plugins: GetPluginMap( + logger, + executorConfig.FSIsolation, + ), + GRPCServer: plugin.DefaultGRPCServer, + Logger: logger, + }) + os.Exit(0) + } +} |