-
Notifications
You must be signed in to change notification settings - Fork 94
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
Signal broadcasting #173
Signal broadcasting #173
Conversation
My proposal to broadcast SIGHUP, SIGINT and SIGTERM to `crond` and `borgmatic`
Looks good.
|
@psi-4ward, thanks for your PR. May I ask what is the desired effect of the |
|
@psi-4ward, thanks a lot for your explanation! 👍 |
This is how open source works 😉 |
@psi-4ward Would adding tini be a simpler solution for this as it would deal with PIDs and sending/receiving signals within the container processes. |
Afair forwards tini signals only to child-process (entry.sh) My Test:
|
Ah, this could be resolved by having tini installed directly into the container which'd allow us greater control, as from my understanding the init implementation of Docker is rather simple. E.g. ARG TINI_VERSION='v0.19.0'
ADD --link --chmod=755 https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
SHELL ["/bin/bash", "-c"]
CMD ["/tini", "-g", "--", "/entry.sh"] Note the
|
I like that solution @modem7 |
@modem7, just read that there is a Alpine package for tini. Is there any reason to not install it from there? |
Mostly so that we can control where it installs. I've tried installing it via the package manager and things get.......weird. This would also allow us to control + (Docker build) cache which version we use (granted, hasn't been updated in some time, so probably not really much of an issue). However - my above statement needs testing vs your question - if the apk version works as expected, then let's use that, it's a cleaner solution. I'll do a quick test now. |
@toastie89 - I've done a test and it seems that the apk installed one is absolutely fine. # syntax = docker/dockerfile:latest
FROM python:3.11.0-alpine3.16
LABEL mainainer='modem7'
RUN <<EOF
set -x
apk add --no-cache -U \
tzdata \
sshfs \
openssl \
fuse \
ca-certificates \
logrotate \
lz4-libs \
libacl \
postgresql-client \
mariadb-client \
mongodb-tools \
curl \
findmnt \
tini \
bash \
bash-completion \
bash-doc
EOF
COPY --link requirements.txt /
RUN --mount=type=cache,id=pip,target=/root/.cache,sharing=locked python3 -m pip install -Ur requirements.txt
RUN <<EOF
set -x
borgmatic --bash-completion > /usr/share/bash-completion/completions/borgmatic
echo "source /etc/profile.d/bash_completion.sh" > /root/.bashrc
EOF
COPY --chmod=755 --link entry.sh /
VOLUME /mnt/source
VOLUME /mnt/borg-repository
VOLUME /root/.borgmatic
VOLUME /etc/borgmatic.d
VOLUME /root/.config/borg
VOLUME /root/.ssh
VOLUME /root/.cache/borg
ENTRYPOINT ["/sbin/tini", "-g", "--", "/entry.sh"] Which gives us: UID PID PPID C STIME TTY TIME CMD
root 4026113 4026087 0 19:24 pts/0 00:00:00 /sbin/tini -g -- /entry.sh
root 4026168 4026113 0 19:24 pts/0 00:00:00 /bin/bash /entry.sh
root 4026333 4026168 0 19:24 pts/0 00:00:00 crond -f -L /dev/stdout |
Tested tini with
=> eventually running borgmatic process don't have time to do a graceful exit See: krallin/tini#180 So tini seems not to be an option. |
See if https://github.com/Yelp/dumb-init would do it appropriately. I haven't tried this solution myself, but apparently there's a few differences when it comes to stop signals. But yes, the issue may be that the entrypoint script itself isn't sending suitable signals. If we can have a repeatable testing method, we can test different potential solutions. |
I think to remember that supervisord worked but it is long time ago since we played around with. At the end we used some bash traps cause it worked and we didn't have more dependencies |
A potentially dumb suggestion (as I don't quite have your test setup yet, so you'd be best to replicate): In the entrypoint script, try replacing (alongside with having tini/init):
Source: https://hynek.me/articles/docker-signals/ point number 2 The posts here: krallin/tini#72 and krallin/tini#78 seem to back this thought up. The command On another note @grantbevis, during testing, it seems that crond is using /bin/ash not /bin/bash. We should investigate resolving this (Simplest solution may be just to do |
|
Think is doesn't matter. If one puts "scripts" in crontab he can still use |
From my brief test, it didn't seem to replace PID1 when execed with tini as tini called the shell, and the shell called cron, but I did a pretty basic test calling echo then sleep. Nothing overly fancy. Now, the reason I suspect this is occurring on my end is that I'm calling tini as the entrypoint, then calling the script as the cmd which could potentially be a solution.
|
Of course this is the expected result if u use tini.
So case 1: no tini => Case 2: tini => Hope I could make it clear now? |
That's correct Yup. So in the 2nd scenario, are you still getting the same behaviour or is it a potential solution? Otherwise, do we need to investigate something such as calling a script the cron rather than calling the borgmatic executable directly via cron itself? Docker by standard gives a SIGTERM signal as well, but there are ways we can change the signal if borgmatic requires as such. |
Imho does not make any difference cause tini does not give the childs time to shutdown
Does not make any difference cause cron does not forward signals to childs |
Is there a workaround we can implement now ourselves until this issue is resolved? |
Just an additional note, seems that this/a similar behaviour has also been picked up in the moby repo with And a pending PR at: moby/moby#41548 |
Why do you dislike my solution? It's simple and works (for me 😄) |
Heya, it's not that I dislike your particular solution, but it's more that it's a workaround (a good one at that, don't misunderstand). If we can find a solution that actually deals with the issue at hand (preferably a process manager or Docker actually doing its job), then that would allow for additional work further down the line without having to refractor in the workarounds, especially as in many cases, it's not just borg(matic) that is running, but also database clients, filesystem packages, docker in docker etc (something that @toastie89 and @grantbevis would be better at elaborating on). Ultimately, the final decision is up to the two chaps above as to what we do and how, as it's their baby. But I'm definitely not ignoring this as a potential solution to the problem. Are you able to find a way to test if one solution or other works in a way that's reproduceable so that we can test multiple solutions? I'm somewhat swamped my end. |
Can we simplify this and reiterate the exact problem we're trying to solve with this PR please? I don't personally see the issue |
Okay, I'll try. If one stopps the container ( In the current implementation Furthermore, crond could have started a borgmatic action so the process-list would look something like
In this scenario not only crond gets killed but also borgmatic and some-database-backup.sh. borgmatic has no chance to do graceful actions like aborting the backup and release the lock. Hopefully it gets clear?
This is correct, it's a workaround but in fact that tini wont wait for child-process-exists tini is not an option. Of course one could try s6-daemon-tools, initd, systemd or whatever bot I think it's over-bloated. Your mention that we could/should also abort childs of borgmatic itself we could rewrite the signal-broadcasting to simply all process in the container and iterate (signal) it in descending order. Reproduction setup:
|
I would opt to go for the script prepared by @psi-4ward for now. We could still move to tini, in case it further devolops to solve the issue in future. |
As a side question, is Alpine cron really the best tool to use here I wonder? *moved discussion to #177 as not to detract from/confuse this PR. |
Tbh, usually one would use cron from the system or K8s jobs to trigger borgmatic inside the container. But I don't know how many ppl here use borg and don't have much possibilities (ie symbology Nas) |
supercronic sounds like we should give it a try |
Declining in favour of #186 |
So I'm sorry but for me this is not solved! |
My proposal to broadcast SIGHUP, SIGINT and SIGTERM to
crond
andborgmatic