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

Commit a3d4029

Browse files
codyjlinCody Lin
andauthored
Add graceful shutdown via sigterm (#42)
* 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>
1 parent 1edacdf commit a3d4029

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ USER root
3232
USER presto:presto
3333
# Add Db2 connector
3434
COPY --from=builder --chown=presto:presto presto-db2-* /usr/lib/presto/plugin/db2
35+
36+
CMD ["./run-presto.sh"]

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,9 @@ Then:
4040
```SHELL
4141
docker run -d -p 8080:8080 -v /foo/bar/db2.properties:/usr/lib/presto/default/etc/catalog/db2.properties:ro shawnzhu/prestodb:latest
4242
```
43+
44+
## Features
45+
46+
### Graceful Shutdown
47+
48+
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.

run-presto.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -xeuo pipefail
4+
5+
graceful_shutdown() {
6+
echo "calling graceful shutdown"
7+
PORT=$(grep "^http-server.http.port=" /etc/presto/config.properties | cut -d '=' -f2)
8+
curl -v -X PUT -d '"SHUTTING_DOWN"' -H "Content-type: application/json" http://localhost:$PORT\/v1/info/state -H X-Presto-User:name
9+
}
10+
trap graceful_shutdown TERM
11+
12+
set +e
13+
grep -s -q 'node.id' /etc/presto/node.properties
14+
NODE_ID_EXISTS=$?
15+
set -e
16+
17+
NODE_ID=""
18+
if [[ ${NODE_ID_EXISTS} != 0 ]] ; then
19+
NODE_ID="-Dnode.id=${HOSTNAME}"
20+
fi
21+
22+
exec /usr/lib/presto/bin/launcher run --etc-dir /etc/presto ${NODE_ID} "$@"
23+

test_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ metadataTest:
1919
value: /usr/lib/jvm/zulu11
2020
exposedPorts: ["8080"]
2121
cmd:
22-
- /usr/lib/presto/bin/run-presto
22+
- ./run-presto.sh

0 commit comments

Comments
 (0)