mirror of
https://github.com/status-im/consul.git
synced 2025-02-16 23:57:07 +00:00
agent: Adding support for -join flag. Fixes #33.
This commit is contained in:
parent
6fd3f81c48
commit
a8d9fefdfe
@ -58,6 +58,9 @@ func (c *Command) readConfig() *Config {
|
|||||||
|
|
||||||
cmdFlags.IntVar(&cmdConfig.Protocol, "protocol", -1, "protocol version")
|
cmdFlags.IntVar(&cmdConfig.Protocol, "protocol", -1, "protocol version")
|
||||||
|
|
||||||
|
cmdFlags.Var((*AppendSliceValue)(&cmdConfig.StartJoin), "join",
|
||||||
|
"address of agent to join on startup")
|
||||||
|
|
||||||
if err := cmdFlags.Parse(c.args); err != nil {
|
if err := cmdFlags.Parse(c.args); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -200,6 +203,22 @@ func (c *Command) setupAgent(config *Config, logOutput io.Writer, logWriter *log
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// startupJoin is invoked to handle any joins specified to take place at start time
|
||||||
|
func (c *Command) startupJoin(config *Config) error {
|
||||||
|
if len(config.StartJoin) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Ui.Output("Joining cluster...")
|
||||||
|
n, err := c.agent.JoinLAN(config.StartJoin)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Ui.Info(fmt.Sprintf("Join completed. Synced with %d initial agents", n))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Command) Run(args []string) int {
|
func (c *Command) Run(args []string) int {
|
||||||
c.Ui = &cli.PrefixedUi{
|
c.Ui = &cli.PrefixedUi{
|
||||||
OutputPrefix: "==> ",
|
OutputPrefix: "==> ",
|
||||||
@ -262,6 +281,12 @@ func (c *Command) Run(args []string) int {
|
|||||||
defer c.httpServer.Shutdown()
|
defer c.httpServer.Shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Join startup nodes if specified
|
||||||
|
if err := c.startupJoin(config); err != nil {
|
||||||
|
c.Ui.Error(err.Error())
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
// Register the services
|
// Register the services
|
||||||
for _, service := range config.Services {
|
for _, service := range config.Services {
|
||||||
ns := service.NodeService()
|
ns := service.NodeService()
|
||||||
@ -447,6 +472,8 @@ Options:
|
|||||||
order.
|
order.
|
||||||
-data-dir=path Path to a data directory to store agent state
|
-data-dir=path Path to a data directory to store agent state
|
||||||
-dc=east-aws Datacenter of the agent
|
-dc=east-aws Datacenter of the agent
|
||||||
|
-join=1.2.3.4 Address of an agent to join at start time.
|
||||||
|
Can be specified multiple times.
|
||||||
-log-level=info Log level of the agent.
|
-log-level=info Log level of the agent.
|
||||||
-node=hostname Name of this node. Must be unique in the cluster
|
-node=hostname Name of this node. Must be unique in the cluster
|
||||||
-protocol=N Sets the protocol version. Defaults to latest.
|
-protocol=N Sets the protocol version. Defaults to latest.
|
||||||
|
@ -119,6 +119,11 @@ type Config struct {
|
|||||||
// Must be provided to serve TLS connections.
|
// Must be provided to serve TLS connections.
|
||||||
KeyFile string `mapstructure:"key_file"`
|
KeyFile string `mapstructure:"key_file"`
|
||||||
|
|
||||||
|
// StartJoin is a list of addresses to attempt to join when the
|
||||||
|
// agent starts. If Serf is unable to communicate with any of these
|
||||||
|
// addresses, then the agent will error and exit.
|
||||||
|
StartJoin []string `mapstructure:"start_join"`
|
||||||
|
|
||||||
// AEInterval controls the anti-entropy interval. This is how often
|
// AEInterval controls the anti-entropy interval. This is how often
|
||||||
// the agent attempts to reconcile it's local state with the server'
|
// the agent attempts to reconcile it's local state with the server'
|
||||||
// representation of our state. Defaults to every 60s.
|
// representation of our state. Defaults to every 60s.
|
||||||
@ -396,6 +401,12 @@ func MergeConfig(a, b *Config) *Config {
|
|||||||
if b.Ports.Server != 0 {
|
if b.Ports.Server != 0 {
|
||||||
result.Ports.Server = b.Ports.Server
|
result.Ports.Server = b.Ports.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy the start join addresses
|
||||||
|
result.StartJoin = make([]string, 0, len(a.StartJoin)+len(b.StartJoin))
|
||||||
|
result.StartJoin = append(result.StartJoin, a.StartJoin...)
|
||||||
|
result.StartJoin = append(result.StartJoin, b.StartJoin...)
|
||||||
|
|
||||||
return &result
|
return &result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +66,11 @@ The options below are all specified on the command-line.
|
|||||||
it relies on proper configuration. Nodes in the same datacenter should be on a single
|
it relies on proper configuration. Nodes in the same datacenter should be on a single
|
||||||
LAN.
|
LAN.
|
||||||
|
|
||||||
|
* `-join` - Address of another agent to join upon starting up. This can be
|
||||||
|
specified multiple times to specify multiple agents to join. If Consul is
|
||||||
|
unable to join with any of the specified addresses, agent startup will
|
||||||
|
fail. By default, the agent won't join any nodes when it starts up.
|
||||||
|
|
||||||
* `-log-level` - The level of logging to show after the Consul agent has
|
* `-log-level` - The level of logging to show after the Consul agent has
|
||||||
started. This defaults to "info". The available log levels are "trace",
|
started. This defaults to "info". The available log levels are "trace",
|
||||||
"debug", "info", "warn", "err". This is the log level that will be shown
|
"debug", "info", "warn", "err". This is the log level that will be shown
|
||||||
@ -190,6 +195,9 @@ definitions support being updated during a reload.
|
|||||||
gracefully leave, but setting this to true disables that. Defaults to false.
|
gracefully leave, but setting this to true disables that. Defaults to false.
|
||||||
Interrupts are usually from a Control-C from a shell.
|
Interrupts are usually from a Control-C from a shell.
|
||||||
|
|
||||||
|
* `start_join` - An array of strings specifying addresses of nodes to
|
||||||
|
join upon startup.
|
||||||
|
|
||||||
* `statsite_addr` - This provides the address of a statsite instance. If provided
|
* `statsite_addr` - This provides the address of a statsite instance. If provided
|
||||||
Consul will stream various telemetry information to that instance for aggregation.
|
Consul will stream various telemetry information to that instance for aggregation.
|
||||||
This can be used to capture various runtime information.
|
This can be used to capture various runtime information.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user