github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/command/server_force_leave.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/posener/complete" 8 ) 9 10 type ServerForceLeaveCommand struct { 11 Meta 12 } 13 14 func (c *ServerForceLeaveCommand) Help() string { 15 helpText := ` 16 Usage: nomad server force-leave [options] <node> 17 18 Forces an server to enter the "left" state. This can be used to 19 eject nodes which have failed and will not rejoin the cluster. 20 Note that if the member is actually still alive, it will 21 eventually rejoin the cluster again. 22 23 General Options: 24 25 ` + generalOptionsUsage() 26 return strings.TrimSpace(helpText) 27 } 28 29 func (c *ServerForceLeaveCommand) Synopsis() string { 30 return "Force a server into the 'left' state" 31 } 32 33 func (c *ServerForceLeaveCommand) AutocompleteFlags() complete.Flags { 34 return c.Meta.AutocompleteFlags(FlagSetClient) 35 } 36 37 func (c *ServerForceLeaveCommand) AutocompleteArgs() complete.Predictor { 38 return complete.PredictNothing 39 } 40 41 func (c *ServerForceLeaveCommand) Name() string { return "server force-leave" } 42 43 func (c *ServerForceLeaveCommand) Run(args []string) int { 44 flags := c.Meta.FlagSet(c.Name(), FlagSetClient) 45 flags.Usage = func() { c.Ui.Output(c.Help()) } 46 if err := flags.Parse(args); err != nil { 47 return 1 48 } 49 50 // Check that we got exactly one node 51 args = flags.Args() 52 if len(args) != 1 { 53 c.Ui.Error("This command takes one argument: <node>") 54 c.Ui.Error(commandErrorText(c)) 55 return 1 56 } 57 node := args[0] 58 59 // Get the HTTP client 60 client, err := c.Meta.Client() 61 if err != nil { 62 c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) 63 return 1 64 } 65 66 // Call force-leave on the node 67 if err := client.Agent().ForceLeave(node); err != nil { 68 c.Ui.Error(fmt.Sprintf("Error force-leaving server %s: %s", node, err)) 69 return 1 70 } 71 72 return 0 73 }