Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Cleanup on stopping agent #382

Merged
merged 5 commits into from
Oct 1, 2019
Merged

fix: Cleanup on stopping agent #382

merged 5 commits into from
Oct 1, 2019

Conversation

wwilsman
Copy link
Contributor

@wwilsman wwilsman commented Oct 1, 2019

Purpose

This started out as a fix for #340, to ensure that when agent is terminated, the PID file is always cleaned up. The approach made it easy to preemptively fix a couple of other bugs as well.

Approach

The start and exec commands shared similar startup behavior, but exec had better stop behavior by ensuring it is only ever stopped once (due to multiple events). The better behavior from the exec command was DRY'd up and moved into the base PercyCommand class.

We can then take advantage of inheritance to clean up the PID file whenever the new stop method is called. This created an error when the PID file was already cleaned up, so I split up the existing logic to suppress file-not-found errors.

The common start and stop methods made it possible for the static snapshot command to also gracefully stop the server upon receiving termination events.

Since it seemed relevant, I added a missing child process error handler as per #381. According to Node docs, it should only be triggered when the child process can not be spawned or killed.

Both of these commands start and stop in the same way, and all
commands can benefit from handling termination events
When sigterm and friends are recieved, the server gets stopped but leaves behind
the PID file which causes future runs to think there is already a running
agent. With the recent adjustments to how termination events are handled, we can
safely cleanup that file in the stop method.
@wwilsman wwilsman requested a review from Robdel12 October 1, 2019 18:55
@wwilsman wwilsman changed the title Agent stop fixes fix: Cleanup on stopping agent Oct 1, 2019
Copy link
Contributor

@Robdel12 Robdel12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice work 🏁 we should reach out to the folks that reported #340 too

@wwilsman wwilsman merged commit cc28320 into master Oct 1, 2019
@wwilsman wwilsman deleted the ww/stop-fixes branch October 1, 2019 19:23
djones pushed a commit that referenced this pull request Oct 1, 2019
## [0.16.2](v0.16.1...v0.16.2) (2019-10-01)

### Bug Fixes

* Cleanup on stopping agent ([#382](#382)) ([cc28320](cc28320)), closes [#340](#340)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants