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

Commit

Permalink
Add graceful shutdown via sigterm (#42)
Browse files Browse the repository at this point in the history
* Add graceful shutdown via sigterm

* Add documentation

* minor fixes; search port number

* Add documentation and fix CI

* fix test

Co-authored-by: Cody Lin <clin@ibm.com>
  • Loading branch information
codyjlin and Cody Lin committed Apr 6, 2021
1 parent 1edacdf commit a3d4029
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ USER root
USER presto:presto
# Add Db2 connector
COPY --from=builder --chown=presto:presto presto-db2-* /usr/lib/presto/plugin/db2

CMD ["./run-presto.sh"]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ Then:
```SHELL
docker run -d -p 8080:8080 -v /foo/bar/db2.properties:/usr/lib/presto/default/etc/catalog/db2.properties:ro shawnzhu/prestodb:latest
```

## Features

### Graceful Shutdown

It adds the [graceful shutdown](https://trino.io/docs/current/admin/graceful-shutdown.html) feature from Trino such that on a SIGTERM signal to the container, the worker will have a grace period before interrupting active queries.
23 changes: 23 additions & 0 deletions run-presto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -xeuo pipefail

graceful_shutdown() {
echo "calling graceful shutdown"
PORT=$(grep "^http-server.http.port=" /etc/presto/config.properties | cut -d '=' -f2)
curl -v -X PUT -d '"SHUTTING_DOWN"' -H "Content-type: application/json" http://localhost:$PORT\/v1/info/state -H X-Presto-User:name
}
trap graceful_shutdown TERM

set +e
grep -s -q 'node.id' /etc/presto/node.properties
NODE_ID_EXISTS=$?
set -e

NODE_ID=""
if [[ ${NODE_ID_EXISTS} != 0 ]] ; then
NODE_ID="-Dnode.id=${HOSTNAME}"
fi

exec /usr/lib/presto/bin/launcher run --etc-dir /etc/presto ${NODE_ID} "$@"

2 changes: 1 addition & 1 deletion test_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ metadataTest:
value: /usr/lib/jvm/zulu11
exposedPorts: ["8080"]
cmd:
- /usr/lib/presto/bin/run-presto
- ./run-presto.sh

0 comments on commit a3d4029

Please sign in to comment.