Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andexec
commands shared similar startup behavior, butexec
had better stop behavior by ensuring it is only ever stopped once (due to multiple events). The better behavior from theexec
command was DRY'd up and moved into the basePercyCommand
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
andstop
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.