-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
make lf-app container shutdown properly #1421
Conversation
Change the docker-compose file to use a separate shell script that properly handles SIGTERM. This results in a clean and fast shutdown of the lf-app container.
Tried using this approach in the LfMerge container, and ran into the problem that lfmerge spends almost all of its time in |
LfMerge version 2.0.123 has an update to use tini as its PID 1 process, which will allow it to respond to SIGTERM and shut down fast as well. Might as well include it in this PR.
I've created LfMerge version 2.0.123 with So I've included a commit in this PR that updates the lfmerge container to 2.0.123. |
Needed so init process will run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this doesn't work. Shell scripts are pretty simple-minded and do not pass on signals to their child processes; instead, when the shell script receives SIGTERM it waits for the current command to finish before processing the signal and exiting. But since the current command is apache2-foreground
, that doesn't ever exit, so the shell script never gets to handle SIGTERM. And therefore apache2-foreground
never receives SIGTERM either.
See https://github.com/sillsdev/LfMerge/pull/275/files for how we'll need to handle this: install tini
in the Dockerfile, and set it as the entrypoint. Also, the -g
option to tini is probably required, as that sends the received signal to all the process group, which means that not only will the run-with-wait.sh
script receive SIGTERM, but so will any child processes it launched, like apache2-foreground
.
BTW, I verified that it doesn't work by running |
Note the `-g` option, necessary so tini will forward signals to entire process *groups*. Without the `-g`, apache2-foreground never receives the SIGTERM signal and doesn't know it should exit.
With my latest commit, this PR works. But now that it's mostly code that I've written, I think someone else needs to review it. |
@rmunn hmm, this is frustrating since "it works for me" TM. Here's a screenshot of my original commit working. I deleted the lf-app and rebuilt it on this commit (not shown). It takes 0.0 seconds to shutdown. The two that take 10 seconds are lfmerge and lf-next-app. I wonder why it's not working for you? Did you make clean and rebuild the image? I guess it's disappointing that we are getting different results - but I don't want to get hung up on something small like this. I would like to have a standard way make all our docker containers behave on shutdown. I think tini is a legit solution to this problem. @rmunn wrote:
Not sure I agree with this conclusion. My shell script explicitly traps SIGTERM and |
https://stackoverflow.com/questions/26858344/trap-not-working-in-shell-script shows a minimal reproduction script that can be used to test it, and also quotes the Bash manual that says, "If bash is waiting for a command to complete and receives a signal for which a trap has been set, the trap will not be executed until the command completes." I suspect the reason you saw it working is because you ran Anyway, I'll submit a new commit or two that moves the installation of |
Have now moved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I approve of these changes however GH won't let me approve my own PR. Go ahead and merge Robin.
Change the docker-compose file to use a separate shell script that properly handles SIGTERM. This results in a clean and fast shutdown of the lf-app container.
I also looked into making the lf-next-app container shutdown properly and cleanly, however it looks like the way that SvelteKit is being run (with node-adapter?) doesn't contain code to specifically handle SIGTERM which is required for a docker clean shutdown.
References:
Other examples of running SvelteKit inside Docker have it running nginx infront of SveltKit (nginx provides proper SIGTERM handling). I'm not exactly sure the best way to make our next-app implementation properly handle SIGTERM. I really like the suggestions in the above referenced article. I wondered if wrapping the SvelteKit node start command in a shell script that handles SIGTERM would be an easy solution. Thoughts @longrunningprocess ?
Fixes # (issue)
Type of Change
Screenshots
Testing on your branch
Please describe how to test and/or verify your changes. Provide instructions so we can reproduce. Please also provide relevant test data as necessary. These instructions will be used for QA testing below.
Checklist
qa.languageforge.org testing
Reviewers: add/replace your name below and check the box to sign-off/attest the feature works as expected on qa.languageforge.org