mirror of https://github.com/status-im/consul.git
agent/proxy: delete pid file on Stop
This commit is contained in:
parent
aaca1fbcf5
commit
de3f49a880
|
@ -263,6 +263,20 @@ func (p *Daemon) Stop() error {
|
|||
gracefulWait = 5 * time.Second
|
||||
}
|
||||
|
||||
// Defer removing the pid file. Even under error conditions we
|
||||
// delete the pid file since Stop means that the manager is no
|
||||
// longer managing this proxy and therefore nothing else will ever
|
||||
// clean it up.
|
||||
if p.PidPath != "" {
|
||||
defer func() {
|
||||
if err := os.Remove(p.PidPath); err != nil && !os.IsNotExist(err) {
|
||||
p.Logger.Printf(
|
||||
"[DEBUG] agent/proxy: error removing pid file %q: %s",
|
||||
p.PidPath, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// First, try a graceful stop
|
||||
err := process.Signal(os.Interrupt)
|
||||
if err == nil {
|
||||
|
|
|
@ -177,6 +177,13 @@ func TestDaemonStart_pidFile(t *testing.T) {
|
|||
pidRaw, err := ioutil.ReadFile(pidPath)
|
||||
require.NoError(err)
|
||||
require.NotEmpty(pidRaw)
|
||||
|
||||
// Stop
|
||||
require.NoError(d.Stop())
|
||||
|
||||
// Pid file should be gone
|
||||
_, err = os.Stat(pidPath)
|
||||
require.True(os.IsNotExist(err))
|
||||
}
|
||||
|
||||
// Verify the pid file changes on restart
|
||||
|
|
Loading…
Reference in New Issue