Changes default for `leave_on_terminate` based on server or client mode.

This commit is contained in:
James Phillips 2016-08-31 23:39:11 -07:00
parent dd8061b3db
commit 55ef6c54a6
No known key found for this signature in database
GPG Key ID: 77183E682AC5FC11
5 changed files with 46 additions and 39 deletions

View File

@ -179,15 +179,13 @@ func (c *Command) readConfig() *Config {
return nil
}
// Make sure SkipLeaveOnInt is set to the right default based on the
// agent's mode (client or server)
if config.SkipLeaveOnInt == nil {
config.SkipLeaveOnInt = new(bool)
if config.Server {
*config.SkipLeaveOnInt = true
} else {
*config.SkipLeaveOnInt = false
// Make sure LeaveOnTerm and SkipLeaveOnInt are set to the right
// defaults based on the agent's mode (client or server).
if config.LeaveOnTerm == nil {
config.LeaveOnTerm = Bool(!config.Server)
}
if config.SkipLeaveOnInt == nil {
config.SkipLeaveOnInt = Bool(config.Server)
}
// Ensure we have a data directory
@ -922,7 +920,7 @@ WAIT:
graceful := false
if sig == os.Interrupt && !(*config.SkipLeaveOnInt) {
graceful = true
} else if sig == syscall.SIGTERM && config.LeaveOnTerm {
} else if sig == syscall.SIGTERM && (*config.LeaveOnTerm) {
graceful = true
}

View File

@ -137,7 +137,7 @@ func TestReadCliConfig(t *testing.T) {
}
}
// Test SkipLeaveOnInt default for server mode
// Test LeaveOnTerm and SkipLeaveOnInt defaults for server mode
{
ui := new(cli.MockUi)
cmd := &Command{
@ -157,12 +157,15 @@ func TestReadCliConfig(t *testing.T) {
if config.Server != true {
t.Errorf(`Expected -server to be true`)
}
if (*config.LeaveOnTerm) != false {
t.Errorf(`Expected LeaveOnTerm to be false in server mode`)
}
if (*config.SkipLeaveOnInt) != true {
t.Errorf(`Expected SkipLeaveOnInt to be true in server mode`)
}
}
// Test SkipLeaveOnInt default for client mode
// Test LeaveOnTerm and SkipLeaveOnInt defaults for client mode
{
ui := new(cli.MockUi)
cmd := &Command{
@ -181,6 +184,9 @@ func TestReadCliConfig(t *testing.T) {
if config.Server != false {
t.Errorf(`Expected server to be false`)
}
if (*config.LeaveOnTerm) != true {
t.Errorf(`Expected LeaveOnTerm to be true in client mode`)
}
if *config.SkipLeaveOnInt != false {
t.Errorf(`Expected SkipLeaveOnInt to be false in client mode`)
}

View File

@ -303,8 +303,9 @@ type Config struct {
TaggedAddresses map[string]string
// LeaveOnTerm controls if Serf does a graceful leave when receiving
// the TERM signal. Defaults false. This can be changed on reload.
LeaveOnTerm bool `mapstructure:"leave_on_terminate"`
// the TERM signal. Defaults true on clients, false on servers. This can
// be changed on reload.
LeaveOnTerm *bool `mapstructure:"leave_on_terminate"`
// SkipLeaveOnInt controls if Serf skips a graceful leave when
// receiving the INT signal. Defaults false on clients, true on
@ -1170,8 +1171,8 @@ func MergeConfig(a, b *Config) *Config {
if b.Server == true {
result.Server = b.Server
}
if b.LeaveOnTerm == true {
result.LeaveOnTerm = true
if b.LeaveOnTerm != nil {
result.LeaveOnTerm = b.LeaveOnTerm
}
if b.SkipLeaveOnInt != nil {
result.SkipLeaveOnInt = b.SkipLeaveOnInt

View File

@ -78,8 +78,8 @@ func TestDecodeConfig(t *testing.T) {
t.Fatalf("bad: expected nil SkipLeaveOnInt")
}
if config.LeaveOnTerm != DefaultConfig().LeaveOnTerm {
t.Fatalf("bad: %#v", config)
if config.LeaveOnTerm != nil {
t.Fatalf("bad: expected nil LeaveOnTerm")
}
// Server bootstrap
@ -279,7 +279,7 @@ func TestDecodeConfig(t *testing.T) {
t.Fatalf("err: %s", err)
}
if config.LeaveOnTerm != true {
if *config.LeaveOnTerm != true {
t.Fatalf("bad: %#v", config)
}
@ -1382,7 +1382,7 @@ func TestMergeConfig(t *testing.T) {
BindAddr: "127.0.0.1",
AdvertiseAddr: "127.0.0.1",
Server: false,
LeaveOnTerm: false,
LeaveOnTerm: new(bool),
SkipLeaveOnInt: new(bool),
EnableDebug: false,
CheckUpdateIntervalRaw: "8m",
@ -1441,8 +1441,8 @@ func TestMergeConfig(t *testing.T) {
HTTPS: "127.0.0.4",
},
Server: true,
LeaveOnTerm: true,
SkipLeaveOnInt: new(bool),
LeaveOnTerm: Bool(true),
SkipLeaveOnInt: Bool(true),
EnableDebug: true,
VerifyIncoming: true,
VerifyOutgoing: true,
@ -1521,7 +1521,6 @@ func TestMergeConfig(t *testing.T) {
},
Reap: Bool(true),
}
*b.SkipLeaveOnInt = true
c := MergeConfig(a, b)

View File

@ -567,9 +567,11 @@ Consul will not enable TLS for the HTTP API unless the `https` port has been ass
```
* <a name="leave_on_terminate"></a><a href="#leave_on_terminate">`leave_on_terminate`</a> If
enabled, when the agent receives a TERM signal,
it will send a `Leave` message to the rest of the cluster and gracefully
leave. Defaults to false.
enabled, when the agent receives a TERM signal, it will send a `Leave` message to the rest
of the cluster and gracefully leave. The default behavior for this feature varies based on
whether or not the agent is running as a client or a server (prior to Consul 0.7 the default
value was unconditionally set to `false`). On agents in client-mode, this defaults to `true`
and for agents in server-mode, this defaults to `false`.
* <a name="log_level"></a><a href="#log_level">`log_level`</a> Equivalent to the
[`-log-level` command-line flag](#_log_level).
@ -581,7 +583,8 @@ Consul will not enable TLS for the HTTP API unless the `https` port has been ass
later, this is a nested object that allows tuning the performance of different subsystems in
Consul. See the [Server Performance](/docs/guides/performance.html) guide for more details. The
following parameters are available:
* <a name="raft_multiplier"></a><a href="#raft_multiplier">`raft_multiplier`</a> - An integer
* <a name="raft_multiplier"></a><a href="#raft_multiplier">`raft_multiplier`</a> - An integer
multiplier used by Consul servers to scale key Raft timing parameters. Omitting this value
or setting it to 0 uses default timing described below. Lower values are used to tighten
timing and increase sensitivity while higher values relax timings and reduce sensitivity.