forked from hashicorp/consul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
force_leave.go
69 lines (56 loc) · 1.67 KB
/
force_leave.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package command
import (
"flag"
"fmt"
"github.com/mitchellh/cli"
"strings"
)
// ForceLeaveCommand is a Command implementation that tells a running Consul
// to force a member to enter the "left" state.
type ForceLeaveCommand struct {
Ui cli.Ui
}
func (c *ForceLeaveCommand) Run(args []string) int {
cmdFlags := flag.NewFlagSet("join", flag.ContinueOnError)
cmdFlags.Usage = func() { c.Ui.Output(c.Help()) }
rpcAddr := RPCAddrFlag(cmdFlags)
if err := cmdFlags.Parse(args); err != nil {
return 1
}
nodes := cmdFlags.Args()
if len(nodes) != 1 {
c.Ui.Error("A node name must be specified to force leave.")
c.Ui.Error("")
c.Ui.Error(c.Help())
return 1
}
client, err := RPCClient(*rpcAddr)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err))
return 1
}
defer client.Close()
err = client.ForceLeave(nodes[0])
if err != nil {
c.Ui.Error(fmt.Sprintf("Error force leaving: %s", err))
return 1
}
return 0
}
func (c *ForceLeaveCommand) Synopsis() string {
return "Forces a member of the cluster to enter the \"left\" state"
}
func (c *ForceLeaveCommand) Help() string {
helpText := `
Usage: consul force-leave [options] name
Forces a member of a Consul cluster to enter the "left" state. Note
that if the member is still actually alive, it will eventually rejoin
the cluster. This command is most useful for cleaning out "failed" nodes
that are never coming back. If you do not force leave a failed node,
Consul will attempt to reconnect to those failed nodes for some period of
time before eventually reaping them.
Options:
-rpc-addr=127.0.0.1:8400 RPC address of the Consul agent.
`
return strings.TrimSpace(helpText)
}