Forward SIGTERM and SIGINT down to java process in wrapper script #880
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.
This patch adds trap handlers to the sh wrapper script, so that the Java process terminates when the sh process receives either SIGTERM or SIGINT.
I observed that the Java process kept running when the wrapper process gets killed by Ctrl-C or a signal sent over another way.
The trap handler makes sure that it forwards the signal to the Java child process, which does not happen otherwise in sh compatible shells.
The only drawback I see is that SIGKILL is not handled as it is not possible to intercept it.
As the python lib (https://github.com/AutomatedTester/browsermob-proxy-py) is using SIGKILL this unfortunately does not solve the problem there (AutomatedTester/browsermob-proxy-py#76).
An even simpler solution would be to just run the Java process with exec.
However in that case the JAVACMD check would have to happen before and it would need to be made without invoking the browsermod-proxy code.
So I decided that this would change less in the script.
I am happy to provide an alternative version if that is desireable.