github.com/ranjib/nomad@v0.1.1-0.20160225204057-97751b02f70b/command/syslog_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 SyslogPluginCommand struct {
    13  	Meta
    14  }
    15  
    16  func (e *SyslogPluginCommand) Help() string {
    17  	helpText := `
    18  	This is a command used by Nomad internally to launch a syslog collector"
    19  	`
    20  	return strings.TrimSpace(helpText)
    21  }
    22  
    23  func (s *SyslogPluginCommand) Synopsis() string {
    24  	return "internal - lanch a syslog collector plugin"
    25  }
    26  
    27  func (s *SyslogPluginCommand) Run(args []string) int {
    28  	if len(args) == 0 {
    29  		s.Ui.Error("log output file isn't provided")
    30  	}
    31  	logFileName := args[0]
    32  	stdo, err := os.OpenFile(logFileName, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
    33  	if err != nil {
    34  		s.Ui.Error(err.Error())
    35  		return 1
    36  	}
    37  	plugin.Serve(&plugin.ServeConfig{
    38  		HandshakeConfig: driver.HandshakeConfig,
    39  		Plugins:         driver.GetPluginMap(stdo),
    40  	})
    41  
    42  	return 0
    43  }