github.com/hernad/nomad@v1.6.112/drivers/shared/executor/z_executor_cmd.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package executor 5 6 import ( 7 "encoding/json" 8 "os" 9 10 hclog "github.com/hashicorp/go-hclog" 11 plugin "github.com/hashicorp/go-plugin" 12 13 "github.com/hernad/nomad/plugins/base" 14 ) 15 16 // Install a plugin cli handler to ease working with tests 17 // and external plugins. 18 // This init() must be initialized last in package required by the child plugin 19 // process. It's recommended to avoid any other `init()` or inline any necessary calls 20 // here. See eeaa95d commit message for more details. 21 func init() { 22 if len(os.Args) > 1 && os.Args[1] == "executor" { 23 if len(os.Args) != 3 { 24 hclog.L().Error("json configuration not provided") 25 os.Exit(1) 26 } 27 28 config := os.Args[2] 29 var executorConfig ExecutorConfig 30 if err := json.Unmarshal([]byte(config), &executorConfig); err != nil { 31 os.Exit(1) 32 } 33 34 f, err := os.OpenFile(executorConfig.LogFile, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666) 35 if err != nil { 36 hclog.L().Error(err.Error()) 37 os.Exit(1) 38 } 39 40 // Create the logger 41 logger := hclog.New(&hclog.LoggerOptions{ 42 Level: hclog.LevelFromString(executorConfig.LogLevel), 43 JSONFormat: true, 44 Output: f, 45 }) 46 47 plugin.Serve(&plugin.ServeConfig{ 48 HandshakeConfig: base.Handshake, 49 Plugins: GetPluginMap( 50 logger, 51 executorConfig.FSIsolation, 52 executorConfig.CpuTotalTicks, 53 ), 54 GRPCServer: plugin.DefaultGRPCServer, 55 Logger: logger, 56 }) 57 os.Exit(0) 58 } 59 }