diff --git a/command/agent/command.go b/command/agent/command.go new file mode 100644 index 0000000000..1ee2bf07d5 --- /dev/null +++ b/command/agent/command.go @@ -0,0 +1,89 @@ +package agent + +import ( + "github.com/hashicorp/logutils" + "github.com/mitchellh/cli" + "strings" + "time" +) + +// gracefulTimeout controls how long we wait before forcefully terminating +var gracefulTimeout = 3 * time.Second + +// Command is a Command implementation that runs a Serf agent. +// The command will not end unless a shutdown message is sent on the +// ShutdownCh. If two messages are sent on the ShutdownCh it will forcibly +// exit. +type Command struct { + Ui cli.Ui + ShutdownCh <-chan struct{} + args []string + logFilter *logutils.LevelFilter +} + +func (c *Command) Run(args []string) int { + return 0 +} + +func (c *Command) Synopsis() string { + return "Runs a Consul agent" +} + +func (c *Command) Help() string { + helpText := ` +Usage: consul agent [options] + + Starts the Consul agent and runs until an interrupt is received. The + agent represents a single node in a cluster. + +Options: + + -bind=0.0.0.0 Address to bind network listeners to + -config-file=foo Path to a JSON file to read configuration from. + This can be specified multiple times. + -config-dir=foo Path to a directory to read configuration files + from. This will read every file ending in ".json" + as configuration in this directory in alphabetical + order. + -encrypt=foo Key for encrypting network traffic within Serf. + Must be a base64-encoded 16-byte key. + -event-handler=foo Script to execute when events occur. This can + be specified multiple times. See the event scripts + section below for more info. + -join=addr An initial agent to join with. This flag can be + specified multiple times. + -log-level=info Log level of the agent. + -node=hostname Name of this node. Must be unique in the cluster + -profile=[lan|wan|local] Profile is used to control the timing profiles used in Serf. + The default if not provided is lan. + -protocol=n Serf protocol version to use. This defaults to + the latest version, but can be set back for upgrades. + -role=foo The role of this node, if any. This can be used + by event scripts to differentiate different types + of nodes that may be part of the same cluster. + -rpc-addr=127.0.0.1:7373 Address to bind the RPC listener. + -snapshot=path/to/file The snapshot file is used to store alive nodes and + event information so that Serf can rejoin a cluster + and avoid event replay on restart. + +Event handlers: + + For more information on what event handlers are, please read the + Serf documentation. This section will document how to configure them + on the command-line. There are three methods of specifying an event + handler: + + - The value can be a plain script, such as "event.sh". In this case, + Serf will send all events to this script, and you'll be responsible + for differentiating between them based on the SERF_EVENT. + + - The value can be in the format of "TYPE=SCRIPT", such as + "member-join=join.sh". With this format, Serf will only send events + of that type to that script. + + - The value can be in the format of "user:EVENT=SCRIPT", such as + "user:deploy=deploy.sh". This means that Serf will only invoke this + script in the case of user events named "deploy". +` + return strings.TrimSpace(helpText) +} diff --git a/command/agent/command_test.go b/command/agent/command_test.go new file mode 100644 index 0000000000..9259ea691e --- /dev/null +++ b/command/agent/command_test.go @@ -0,0 +1,10 @@ +package agent + +import ( + "github.com/mitchellh/cli" + "testing" +) + +func TestCommand_implements(t *testing.T) { + var _ cli.Command = new(Command) +} diff --git a/commands.go b/commands.go index 9a86283a50..4840bc60e9 100644 --- a/commands.go +++ b/commands.go @@ -2,6 +2,7 @@ package main import ( "github.com/hashicorp/consul/command" + "github.com/hashicorp/consul/command/agent" "github.com/mitchellh/cli" "os" "os/signal" @@ -14,6 +15,13 @@ func init() { ui := &cli.BasicUi{Writer: os.Stdout} Commands = map[string]cli.CommandFactory{ + "agent": func() (cli.Command, error) { + return &agent.Command{ + Ui: ui, + ShutdownCh: make(chan struct{}), + }, nil + }, + "version": func() (cli.Command, error) { return &command.VersionCommand{ Revision: GitCommit,