agent/proxy: delete pid file on Stop

This commit is contained in:
Mitchell Hashimoto 2018-05-04 09:44:59 -07:00
parent aaca1fbcf5
commit de3f49a880
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 21 additions and 0 deletions

View File

@ -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 {

View File

@ -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