mirror of https://github.com/status-im/consul.git
Return pid file errors and fix help formatting
This commit is contained in:
parent
dd1ce61fb1
commit
4124ddf763
|
@ -107,7 +107,10 @@ func Create(config *Config, logOutput io.Writer) (*Agent, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
agent.storePid()
|
err = agent.storePid()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return agent, nil
|
return agent, nil
|
||||||
}
|
}
|
||||||
|
@ -252,7 +255,10 @@ func (a *Agent) Shutdown() error {
|
||||||
err = a.client.Shutdown()
|
err = a.client.Shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
a.deletePid()
|
pidErr := a.deletePid()
|
||||||
|
if pidErr != nil {
|
||||||
|
a.logger.Println("[WARN] agent: could not delete pid file ", pidErr)
|
||||||
|
}
|
||||||
|
|
||||||
a.logger.Println("[INFO] agent: shutdown complete")
|
a.logger.Println("[INFO] agent: shutdown complete")
|
||||||
a.shutdown = true
|
a.shutdown = true
|
||||||
|
@ -501,7 +507,7 @@ func (a *Agent) Stats() map[string]map[string]string {
|
||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) storePid() {
|
func (a *Agent) storePid() error {
|
||||||
pidPath := a.config.PidFile
|
pidPath := a.config.PidFile
|
||||||
|
|
||||||
if pidPath != "" {
|
if pidPath != "" {
|
||||||
|
@ -509,7 +515,7 @@ func (a *Agent) storePid() {
|
||||||
pidFile, err := os.OpenFile(pidPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
|
pidFile, err := os.OpenFile(pidPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Errorf("Could not open pid file: %v", err)
|
return fmt.Errorf("Could not open pid file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer pidFile.Close()
|
defer pidFile.Close()
|
||||||
|
@ -517,19 +523,33 @@ func (a *Agent) storePid() {
|
||||||
_, err = pidFile.WriteString(fmt.Sprintf("%d", pid))
|
_, err = pidFile.WriteString(fmt.Sprintf("%d", pid))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Errorf("Could not write to pid file: %s", err)
|
return fmt.Errorf("Could not write to pid file: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) deletePid() {
|
func (a *Agent) deletePid() error {
|
||||||
pidPath := a.config.PidFile
|
pidPath := a.config.PidFile
|
||||||
|
|
||||||
if pidPath != "" {
|
if pidPath != "" {
|
||||||
err := os.Remove(pidPath)
|
stat, err := os.Stat(pidPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Errorf("Could not remove pid file: %s", err)
|
return fmt.Errorf("Could not remove pid file: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if stat.IsDir() {
|
||||||
|
return fmt.Errorf("Specified pid file path is directory")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Remove(pidPath)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Could not remove pid file: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -486,7 +486,7 @@ Options:
|
||||||
-protocol=N Sets the protocol version. Defaults to latest.
|
-protocol=N Sets the protocol version. Defaults to latest.
|
||||||
-server Switches agent to server mode.
|
-server Switches agent to server mode.
|
||||||
-ui-dir=path Path to directory containing the Web UI resources
|
-ui-dir=path Path to directory containing the Web UI resources
|
||||||
-pid-file=path Path to file to store agent PID
|
-pid-file=path Path to file to store agent PID
|
||||||
|
|
||||||
`
|
`
|
||||||
return strings.TrimSpace(helpText)
|
return strings.TrimSpace(helpText)
|
||||||
|
|
Loading…
Reference in New Issue