github.com/sl1pm4t/consul@v1.4.5-0.20190325224627-74c31c540f9c/command/reload/reload.go (about) 1 package reload 2 3 import ( 4 "flag" 5 "fmt" 6 7 "github.com/hashicorp/consul/command/flags" 8 "github.com/mitchellh/cli" 9 ) 10 11 func New(ui cli.Ui) *cmd { 12 c := &cmd{UI: ui} 13 c.init() 14 return c 15 } 16 17 type cmd struct { 18 UI cli.Ui 19 flags *flag.FlagSet 20 http *flags.HTTPFlags 21 help string 22 } 23 24 func (c *cmd) init() { 25 c.flags = flag.NewFlagSet("", flag.ContinueOnError) 26 c.http = &flags.HTTPFlags{} 27 flags.Merge(c.flags, c.http.ClientFlags()) 28 c.help = flags.Usage(help, c.flags) 29 } 30 31 func (c *cmd) Run(args []string) int { 32 if err := c.flags.Parse(args); err != nil { 33 return 1 34 } 35 36 client, err := c.http.APIClient() 37 if err != nil { 38 c.UI.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err)) 39 return 1 40 } 41 42 if err := client.Agent().Reload(); err != nil { 43 c.UI.Error(fmt.Sprintf("Error reloading: %s", err)) 44 return 1 45 } 46 47 c.UI.Output("Configuration reload triggered") 48 return 0 49 } 50 51 func (c *cmd) Synopsis() string { 52 return synopsis 53 } 54 55 func (c *cmd) Help() string { 56 return c.help 57 } 58 59 const synopsis = "Triggers the agent to reload configuration files" 60 const help = ` 61 Usage: consul reload 62 63 Causes the agent to reload configurations. This can be used instead 64 of sending the SIGHUP signal to the agent. 65 `