Skip to content
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

Add tini to allow termination signal handling #3320

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

shikharbhardwaj
Copy link

@shikharbhardwaj shikharbhardwaj commented Mar 16, 2023

Description

  • Adds tini as the PID1 process in opensearch and opensearch-dashboards container to allow for termination signal handling.

Issues Resolved

Test plan

  1. Build and push opensearch image to dockerhub
./build-image-multi-arch.sh -f dockerfiles/opensearch.al2.dockerfile -v '1.3.9'  -p opensearch -a 'x64,arm64' -r bluefog/opensearch-test
  1. Test signal handling with new image vs old image (more details in this gist)
docker run --mount type=bind,source="$(pwd)"/.idea/opensearch.yml,target=/usr/share/opensearch/config/opensearch.yml,readonly --pull=always bluefog/opensearch-test:1.3.9

# Send SIGTERM/SIGINT to the container
docker kill --signal="SIGTERM" <container id>
  1. Opensearch container exits with the following logs
[2023-04-29T15:06:05,691][INFO ][o.o.n.Node               ] [c7ab96ede963] stopping ...
[2023-04-29T15:06:05,731][INFO ][o.o.n.Node               ] [c7ab96ede963] stopped
[2023-04-29T15:06:05,732][INFO ][o.o.n.Node               ] [c7ab96ede963] closing ...
[2023-04-29T15:06:05,744][INFO ][o.o.n.Node               ] [c7ab96ede963] closed

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: shikharbhardwaj <shikhar.bhardwaj@instabase.com>
Copy link
Member

@peterzhuamazon peterzhuamazon left a comment

Choose a reason for hiding this comment

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

Hi @shikharbhardwaj ,

Thanks very much for this PR.
Would you mind send some test results/logs if possible?
Showcasing the before/after of the change?

Also, not sure if this can be considered as a major change.
Since this is the first time we are changing how the process is being started.
So probably a good timing to merge this fix is when 3.x launch?

cc: @bbarani

Thanks.


# Update packages
# Install the tools we need: tar and gzip to unpack the OpenSearch tarball, and shadow-utils to give us `groupadd` and `useradd`.
# Install which to allow running of securityadmin.sh
RUN yum update -y && yum install -y tar gzip shadow-utils which && yum clean all

# Add tini to use as init (PID1) process.
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /bin/tini
Copy link
Member

Choose a reason for hiding this comment

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

This wont work as this download is only the x64 version, will crash on the arm64 here.

tini: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=a3f773dca5734fef07e2ea80c0450b3c60bbaf74, stripped

Copy link
Member

Choose a reason for hiding this comment

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

Need code to handle download for x64 vs arm64.

Copy link
Author

Choose a reason for hiding this comment

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

Updated the download source according to the TARGETARCH supplied by docker

Copy link
Member

Choose a reason for hiding this comment

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

TARGETARCH seems only support multi-arch building?
Tried on the single arch build script and it could not figure out arch.
https://docs.docker.com/desktop/extensions-sdk/extensions/multi-arch/#adding-multi-arch-binaries


Step 20/39 : ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${TARGETARCH} /bin/tini
ADD failed: failed to GET https://github.com/krallin/tini/releases/download/v0.19.0/tini- with status 404 Not Found: <!DOCTYPE html>
<html lang="en" data-color-mode="auto" data-light-theme="light" data-dark-theme="dark" data-a11y-animated-images="system">

Although we release for multi-arch we also want to support single-arch if people want to build in their local.
Probably add this in the build-image-single-arch.sh?

--build-arg TARGETARCH=${arch_uname}

@@ -93,5 +98,5 @@ LABEL org.label-schema.schema-version="1.0" \
org.label-schema.build-date="$BUILD_DATE"

# CMD to run
ENTRYPOINT ["./opensearch-dashboards-docker-entrypoint.sh"]
ENTRYPOINT ["tini", "--", "./opensearch-dashboards-docker-entrypoint.sh"]
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to use ENTRYPOINT + CMD together?


ENTRYPOINT ["/tini", "--"]

# Run your program under Tini
CMD ["/your/program", "-and", "-its", "arguments"]

Copy link
Author

@shikharbhardwaj shikharbhardwaj Apr 29, 2023

Choose a reason for hiding this comment

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

Not sure about this since this may change behavior for existing invocations, but AFAICS non-opensearch command invocations will just exec the supplied command with a couple of env var exports

Copy link
Member

Choose a reason for hiding this comment

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

Seems like you add this now?


# Update packages
# Install the tools we need: tar and gzip to unpack the OpenSearch tarball, and shadow-utils to give us `groupadd` and `useradd`.
# Install which to allow running of securityadmin.sh
RUN yum update -y && yum install -y tar gzip shadow-utils which && yum clean all

# Add tini to use as init (PID1) process.
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /bin/tini
RUN chmod +x /bin/tini
Copy link
Member

Choose a reason for hiding this comment

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

I kinda prefer to not make it globally available, and add full path in the entrypoint.
Tho I am not strongly against it.

Copy link
Member

Choose a reason for hiding this comment

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

probably use 755 specifically instead of +x so it is precise?

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good, updated the chmod to 755. Open to path suggestions where we can keep this binary

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

As of path, just use WORKDIR? It is the home dir of os or osd on docker.
So instead of using /bin/tini just use ./tini?

Copy link
Member

@peterzhuamazon peterzhuamazon left a comment

Choose a reason for hiding this comment

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

Add a block to this PR now just in case it get accidentally merged.
Thanks.

Signed-off-by: shikharbhardwaj <shikharbhardwaj68@gmail.com>
shikharbhardwaj and others added 2 commits April 29, 2023 21:06
Signed-off-by: shikharbhardwaj <shikharbhardwaj68@gmail.com>
Signed-off-by: Shikhar Bhardwaj <shikharbhardwaj@users.noreply.github.com>
@shikharbhardwaj
Copy link
Author

@peterzhuamazon sorry for the delay on turning this around, made some updates here along with the steps I did to test this. Let me know if there's a better set of steps to test this PR.

Not exactly sure about the major version requirement, since this is more of a fix than a new feature, but it is possible something downstream depends on this behavior.

@codecov-commenter
Copy link

codecov-commenter commented Apr 30, 2023

Codecov Report

Merging #3320 (e31832a) into main (68a2fe7) will increase coverage by 0.28%.
The diff coverage is n/a.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main    #3320      +/-   ##
==========================================
+ Coverage   91.44%   91.72%   +0.28%     
==========================================
  Files         172      172              
  Lines        4991     4991              
==========================================
+ Hits         4564     4578      +14     
+ Misses        427      413      -14     

see 2 files with indirect coverage changes

@@ -58,7 +58,8 @@ function setupPerformanceAnalyzerPlugin {
echo "Disabling execution of $OPENSEARCH_HOME/bin/$PERFORMANCE_ANALYZER_PLUGIN/performance-analyzer-agent-cli for OpenSearch Performance Analyzer Plugin"
else
echo "Enabling execution of OPENSEARCH_HOME/bin/$PERFORMANCE_ANALYZER_PLUGIN/performance-analyzer-agent-cli for OpenSearch Performance Analyzer Plugin"
$OPENSEARCH_HOME/bin/opensearch-performance-analyzer/performance-analyzer-agent-cli > $OPENSEARCH_HOME/logs/PerformanceAnalyzer.log 2>&1 &
# Launch performance plugin and disown to PID1 (tini).
$OPENSEARCH_HOME/bin/opensearch-performance-analyzer/performance-analyzer-agent-cli > $OPENSEARCH_HOME/logs/PerformanceAnalyzer.log 2>&1 & disown
Copy link
Member

Choose a reason for hiding this comment

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

Good catch, tho I never try to use disown after a command tho.
I think it does the same thing as nohup in front.

Copy link
Member

Choose a reason for hiding this comment

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

I will add this change into another PR so this PR of yours only focused on tini.
If we need to revert later on we dont have to revert the entire tini implementation.
Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

@peterzhuamazon
Copy link
Member

Thanks @shikharbhardwaj I have reviewed for another pass.
Please take a look at the comments.

Thanks!

@peterzhuamazon
Copy link
Member

You might also want to rebase after #3479 merged to consume all the CVE fixes, so that security scan can pass.
Thanks.

@jordarlu
Copy link
Contributor

Hello, @shikharbhardwaj , would you be able to rebase and resolve the conflct to have the WhiteSource Security Check to validate again? thanks !

Signed-off-by: Shikhar Bhardwaj <shikharbhardwaj@users.noreply.github.com>
@peterzhuamazon
Copy link
Member

Hi @shikharbhardwaj welcome back and would you mind check the follow up comments I added in previous callouts?
Thanks.

@jordarlu
Copy link
Contributor

Greetings, @shikharbhardwaj , since it has been a while, wondering if you got time to comment on the feedback from @peterzhuamazon yet? thanks ..

@bbarani
Copy link
Member

bbarani commented Oct 27, 2023

Hi @shikharbhardwaj, can you please take a look at the comments and provide your feedback?

@dblock
Copy link
Member

dblock commented Jul 22, 2024

@peterzhuamazon Let's close if this is not going to be merged?

[Catch All Triage w/ 1, 2, 3]

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.

[BUG] OpenSearch container does not allow for graceful termination
6 participants