Skip to content

Conversation

@Vanlightly
Copy link
Contributor

Motivation

Current official docker images do not handle the SIGTERM sent by the docker runtime and so get killed after the timeout. No graceful shutdown occurs.

The reason is that the entrypoint does not use exec when executing the bin/bookkeeper shell script and so the BookKeeper process cannot receive signals from the docker runtime.

Changes

Use exec when calling the bin/bookkeeper shell script.

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@nicoloboschi nicoloboschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

chmod -R +x ${SCRIPTS_DIR}
echo "This is root, will use user $BK_USER to run command '$@'"
sudo -s -E -u "$BK_USER" /bin/bash "$@"
exec sudo -s -E -u "$BK_USER" /bin/bash "$@"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a similar problem here that the process gets wrapped by bash and doesn't receive the sigterm?

I would change this to something like this

exec sudo -s -E -u "$BK_USER" /bin/bash -c 'exec "$@"' -- "$@"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested it as is and it works. Sudo passes on the SIGTERM to the bin/bookkeeper script which itself uses exec when kicking off java.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true that it "works" from the SIGTERM signalling point of view. My comments are more about the existing solution that was in place.
It just seems odd that there isn't a symmetry to the other execution path where sudo isn't used. sudo -s -E -u "$BK_USER" /bin/bash "$@" expects that the command is always a bash script.
the equivalent of exec "$@" with sudo would be something like exec sudo -s -E -u "$BK_USER" /bin/bash -c 'exec "$@"' -- "$@" . It probably doesn't make difference in this context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I see your point. I'l update it.

Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dlg99 dlg99 added this to the 4.15.0 milestone Feb 14, 2022
@dlg99 dlg99 merged commit 4710fed into apache:master Feb 14, 2022
StevenLuMT pushed a commit to StevenLuMT/bookkeeper that referenced this pull request Feb 16, 2022
### Motivation

Current official docker images do not handle the SIGTERM sent by the docker runtime and so get killed after the timeout. No graceful shutdown occurs.

The reason is that the entrypoint does not use `exec` when executing the `bin/bookkeeper` shell script and so the BookKeeper process cannot receive signals from the docker runtime.

### Changes

Use `exec` when calling the `bin/bookkeeper` shell script.

Reviewers: Nicolò Boschi <boschi1997@gmail.com>, Enrico Olivelli <eolivelli@gmail.com>, Lari Hotari <None>, Matteo Merli <mmerli@apache.org>

This closes apache#2857 from Vanlightly/docker-image-handle-sigterm
Ghatage pushed a commit to sijie/bookkeeper that referenced this pull request Jul 12, 2024
### Motivation

Current official docker images do not handle the SIGTERM sent by the docker runtime and so get killed after the timeout. No graceful shutdown occurs.

The reason is that the entrypoint does not use `exec` when executing the `bin/bookkeeper` shell script and so the BookKeeper process cannot receive signals from the docker runtime.

### Changes

Use `exec` when calling the `bin/bookkeeper` shell script.

Reviewers: Nicolò Boschi <boschi1997@gmail.com>, Enrico Olivelli <eolivelli@gmail.com>, Lari Hotari <None>, Matteo Merli <mmerli@apache.org>

This closes apache#2857 from Vanlightly/docker-image-handle-sigterm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants