github.com/mattyr/nomad@v0.3.3-0.20160919021406-3485a065154a/command/executor_plugin.go (about)

     1  package command
     2  
     3  import (
     4  	"os"
     5  	"strings"
     6  
     7  	"github.com/hashicorp/go-plugin"
     8  
     9  	"github.com/hashicorp/nomad/client/driver"
    10  )
    11  
    12  type ExecutorPluginCommand struct {
    13  	Meta
    14  }
    15  
    16  func (e *ExecutorPluginCommand) Help() string {
    17  	helpText := `
    18  	This is a command used by Nomad internally to launch an executor plugin"
    19  	`
    20  	return strings.TrimSpace(helpText)
    21  }
    22  
    23  func (e *ExecutorPluginCommand) Synopsis() string {
    24  	return "internal - launch an executor plugin"
    25  }
    26  
    27  func (e *ExecutorPluginCommand) Run(args []string) int {
    28  	if len(args) == 0 {
    29  		e.Ui.Error("log output file isn't provided")
    30  		return 1
    31  	}
    32  	logFileName := args[0]
    33  	stdo, err := os.OpenFile(logFileName, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
    34  	if err != nil {
    35  		e.Ui.Error(err.Error())
    36  		return 1
    37  	}
    38  	plugin.Serve(&plugin.ServeConfig{
    39  		HandshakeConfig: driver.HandshakeConfig,
    40  		Plugins:         driver.GetPluginMap(stdo),
    41  	})
    42  	return 0
    43  }