github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/client/logmon/z_logmon_cmd.go (about)

     1  package logmon
     2  
     3  import (
     4  	"os"
     5  
     6  	hclog "github.com/hashicorp/go-hclog"
     7  	plugin "github.com/hashicorp/go-plugin"
     8  	"github.com/hashicorp/nomad/plugins/base"
     9  )
    10  
    11  // Install a plugin cli handler to ease working with tests
    12  // and external plugins.
    13  // This init() must be initialized last in package required by the child plugin
    14  // process. It's recommended to avoid any other `init()` or inline any necessary calls
    15  // here. See eeaa95d commit message for more details.
    16  func init() {
    17  	if len(os.Args) > 1 && os.Args[1] == "logmon" {
    18  		logger := hclog.New(&hclog.LoggerOptions{
    19  			Level:      hclog.Trace,
    20  			JSONFormat: true,
    21  			Name:       "logmon",
    22  		})
    23  		plugin.Serve(&plugin.ServeConfig{
    24  			HandshakeConfig: base.Handshake,
    25  			Plugins: map[string]plugin.Plugin{
    26  				"logmon": NewPlugin(NewLogMon(logger)),
    27  			},
    28  			GRPCServer: plugin.DefaultGRPCServer,
    29  			Logger:     logger,
    30  		})
    31  		os.Exit(0)
    32  	}
    33  }