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