Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Add graceful shutdown via sigterm #42

Merged
merged 6 commits into from
Apr 6, 2021
Merged

Conversation

codyjlin
Copy link
Contributor

@codyjlin codyjlin commented Apr 5, 2021

Closes #41.

Customizes the container entrypoint to initiate graceful shutdown for the Presto worker on a SIGTERM signal.

run-presto.sh Outdated

graceful_shutdown() {
echo "calling graceful shutdown"
curl -v -X PUT -d '"SHUTTING_DOWN"' -H "Content-type: application/json" http://localhost:8081/v1/info/state -H X-Presto-User:name
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should the address be passed as some kind of argument (depending on how worker is set up downstream like here)?

Copy link
Contributor

Choose a reason for hiding this comment

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

The address localhost is correct.

It just need to find the correct port number configured in /etc/presto/config.properties like:

grep "^http-server.http.port=" /etc/presto/config.properties | cut -d'=' -f2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wow didn't know you could do this, thanks for sharing!

Copy link
Contributor

@shawnzhu shawnzhu left a comment

Choose a reason for hiding this comment

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

Please also use STOPSIGNAL instruction as well

Dockerfile Outdated
@@ -32,3 +32,6 @@ USER root
USER presto:presto
# Add Db2 connector
COPY --from=builder --chown=presto:presto presto-db2-* /usr/lib/presto/plugin/db2

RUN chmod +x ./run-presto.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

this line can be removed if the file run-presto.sh has mod 755

Dockerfile Outdated
@@ -32,3 +32,6 @@ USER root
USER presto:presto
# Add Db2 connector
COPY --from=builder --chown=presto:presto presto-db2-* /usr/lib/presto/plugin/db2

RUN chmod +x ./run-presto.sh
ENTRYPOINT ["./run-presto.sh"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mind using CMD instead of ENTRYPOINT? it will be consistent with upstream image:

https://github.com/trinodb/trino/blob/93e5485aab0a7c49cd02343af0f14901f8511071/core/docker/Dockerfile#L35

run-presto.sh Outdated

graceful_shutdown() {
echo "calling graceful shutdown"
curl -v -X PUT -d '"SHUTTING_DOWN"' -H "Content-type: application/json" http://localhost:8081/v1/info/state -H X-Presto-User:name
Copy link
Contributor

Choose a reason for hiding this comment

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

The address localhost is correct.

It just need to find the correct port number configured in /etc/presto/config.properties like:

grep "^http-server.http.port=" /etc/presto/config.properties | cut -d'=' -f2

run-presto.sh Outdated
echo "calling graceful shutdown"
curl -v -X PUT -d '"SHUTTING_DOWN"' -H "Content-type: application/json" http://localhost:8081/v1/info/state -H X-Presto-User:name
}
trap graceful_shutdown SIGTERM
Copy link
Contributor

Choose a reason for hiding this comment

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

run-presto.sh Outdated
@@ -0,0 +1,22 @@
#!/bin/bash

# set -xeuo pipefail
Copy link
Contributor

Choose a reason for hiding this comment

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

uncomment this please

run-presto.sh Outdated
}
trap graceful_shutdown SIGTERM

# set +e
Copy link
Contributor

Choose a reason for hiding this comment

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

uncomment this please

Copy link
Contributor

@shawnzhu shawnzhu left a comment

Choose a reason for hiding this comment

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

looks good.

Would you please add some document to highlight this feature?

@shawnzhu shawnzhu merged commit a3d4029 into IBM:master Apr 6, 2021
@codyjlin codyjlin deleted the graceful-shutdown branch April 7, 2021 14:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Graceful Shutdown feature
2 participants