mirror of https://github.com/hashicorp/consul
agent: cleanup run method
parent
b203ffab29
commit
ae711c3b04
|
@ -705,25 +705,22 @@ func (cmd *Command) Run(args []string) int {
|
||||||
}
|
}
|
||||||
agent.LogOutput = logOutput
|
agent.LogOutput = logOutput
|
||||||
agent.LogWriter = logWriter
|
agent.LogWriter = logWriter
|
||||||
|
|
||||||
if err := agent.Start(); err != nil {
|
if err := agent.Start(); err != nil {
|
||||||
cmd.UI.Error(fmt.Sprintf("Error starting agent: %s", err))
|
cmd.UI.Error(fmt.Sprintf("Error starting agent: %s", err))
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
defer agent.Shutdown()
|
||||||
|
|
||||||
// Setup update checking
|
|
||||||
if !config.DisableUpdateCheck {
|
if !config.DisableUpdateCheck {
|
||||||
cmd.startupUpdateCheck(config)
|
cmd.startupUpdateCheck(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer agent.Shutdown()
|
|
||||||
|
|
||||||
// Join startup nodes if specified
|
|
||||||
if err := cmd.startupJoin(agent, config); err != nil {
|
if err := cmd.startupJoin(agent, config); err != nil {
|
||||||
cmd.UI.Error(err.Error())
|
cmd.UI.Error(err.Error())
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join startup nodes if specified
|
|
||||||
if err := cmd.startupJoinWan(agent, config); err != nil {
|
if err := cmd.startupJoinWan(agent, config); err != nil {
|
||||||
cmd.UI.Error(err.Error())
|
cmd.UI.Error(err.Error())
|
||||||
return 1
|
return 1
|
||||||
|
@ -755,11 +752,7 @@ func (cmd *Command) Run(args []string) int {
|
||||||
cmd.UI.Output("Log data will now stream in as it occurs:\n")
|
cmd.UI.Output("Log data will now stream in as it occurs:\n")
|
||||||
logGate.Flush()
|
logGate.Flush()
|
||||||
|
|
||||||
return cmd.wait(agent, config)
|
// wait for signal
|
||||||
}
|
|
||||||
|
|
||||||
// wait blocks until we get an exit-causing signal
|
|
||||||
func (cmd *Command) wait(agent *Agent, cfg *Config) int {
|
|
||||||
signalCh := make(chan os.Signal, 4)
|
signalCh := make(chan os.Signal, 4)
|
||||||
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
|
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
|
||||||
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGPIPE)
|
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGPIPE)
|
||||||
|
@ -790,9 +783,9 @@ func (cmd *Command) wait(agent *Agent, cfg *Config) int {
|
||||||
case syscall.SIGHUP:
|
case syscall.SIGHUP:
|
||||||
cmd.UI.Output(fmt.Sprintf("Caught signal: %v", sig))
|
cmd.UI.Output(fmt.Sprintf("Caught signal: %v", sig))
|
||||||
|
|
||||||
conf, err := cmd.handleReload(agent, cfg)
|
conf, err := cmd.handleReload(agent, config)
|
||||||
if conf != nil {
|
if conf != nil {
|
||||||
cfg = conf
|
config = conf
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.UI.Error(err.Error())
|
cmd.UI.Error(err.Error())
|
||||||
|
@ -805,7 +798,7 @@ func (cmd *Command) wait(agent *Agent, cfg *Config) int {
|
||||||
default:
|
default:
|
||||||
cmd.UI.Output(fmt.Sprintf("Caught signal: %v", sig))
|
cmd.UI.Output(fmt.Sprintf("Caught signal: %v", sig))
|
||||||
|
|
||||||
graceful := (sig == os.Interrupt && !(*cfg.SkipLeaveOnInt)) || (sig == syscall.SIGTERM && (*cfg.LeaveOnTerm))
|
graceful := (sig == os.Interrupt && !(*config.SkipLeaveOnInt)) || (sig == syscall.SIGTERM && (*config.LeaveOnTerm))
|
||||||
if !graceful {
|
if !graceful {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue