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