-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
Handling of SIGTERM in kiwix-serve #488
Conversation
@rgaudin Would you be able to check please that the handling in Docker works now please? |
I'd like to but I am having difficulties buidling a static kiwix-serve. @veloman-yunkan can you share a static linux build that I could try? |
|
@veloman-yunkan, thank you. kiwix-serve now properly shuts down on docker stop and docker restart works as expected. Unfortunately, it doesn't react anymore to FROM alpine
RUN mkdir -p /data && wget -O /data/archlinux_en_all_maxi_2021-05.zim https://download.kiwix.org/zim/other/archlinux_en_all_maxi_2021-05.zim
VOLUME /data
RUN wget https://github.com/kiwix/kiwix-tools/files/7324533/kiwix-serve.gz && \
gunzip kiwix-serve.gz && \
mv kiwix-serve /usr/local/bin/ && \
chmod +x /usr/local/bin/kiwix-* && \
rm -rf /kiwix-serve.gz
CMD ["/usr/local/bin/kiwix-serve", "/data/archlinux_en_all_maxi_2021-05.zim"] docker build . -t kst && docker run -p 9999:80 -it kst |
LGTM. |
76baede
to
6f12d0d
Compare
@rgaudin The fix is easy - For some reason I cannot upload the new build to github. Please let me know if you want to test it too. |
@mgautierfr Since the full change is small, I amended my fix and force pushed it without using a temporary fix-up commit. |
What about all the other standard singals which were working. I think in particular to SiGSTP which is really useful? |
This fix addresses handling of signals in kiwix-serve when it is executed with PID=1 (see https://petermalmgren.com/signal-handling-docker/). Otherwise, all other signals work as before. I don't think that suspending a process with PID=1 on SIGSTP makes any sense. |
For what I understand, the root cause of all this is that we are running the process with PID=1. So no default signal handler are used by the kernel. (@veloman-yunkan do you confirm ?) Instead of re implement them wouldn't be better to use tools like https://github.com/Yelp/dumb-init or https://github.com/krallin/tini ? |
Agrees with @mgautierfr. I've tested dumb-init quickly and it seems to work fine in all of my scenarios. Preparing a PR |
Following-up on discussion in #488, now using https://github.com/Yelp/dumb-init as entrypoint so our kiwix-* tools properly receives signals
Following-up on discussion in #488, now using https://github.com/Yelp/dumb-init as entrypoint so our kiwix-* tools properly receives signals
See #489, for an alternative using dumb-init |
Following-up on discussion in #488, now using https://github.com/Yelp/dumb-init as entrypoint so our kiwix-* tools properly receives signals
I confirm that.
For kiwix docker images that solution will work too. However it won't render this fix meaningless, since the latter provides a clean way of shutting down the server. |
Following-up on discussion in #488, now using https://github.com/Yelp/dumb-init as entrypoint so our kiwix-* tools properly receives signals
src/server/kiwix-serve.cpp
Outdated
@@ -79,7 +79,7 @@ void usage() | |||
<< std::endl; | |||
} | |||
|
|||
bool waiting = true; | |||
volatile sig_atomic_t waiting = true; |
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.
Nice catch !
I agree. And I wonder if we should not reset the signal handling to the default one after we handle it (or correctly handle a second signal). If something goes wrong during the This is less important for |
9c3b1f4
to
4faaa97
Compare
@mgautierfr In I implemented the handling of a second SIGINT or SIGTERM signal (or the first signal before the server loop is entered) without resorting to the default method. Then this fix keeps working for PID=1 processes too without relying on dumb-init or a similar workaround. |
Yes, we agree. |
Fixes #482