Skip to content

Commit

Permalink
Add signal-handling ENTRYPOINT, cancel on QUIT
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrisbin committed May 27, 2021
1 parent 57200fb commit 54d9c64
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ ENV [email protected]
VOLUME /code
WORKDIR /code

ENTRYPOINT ["/bin/restyler"]
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["--help"]
32 changes: 32 additions & 0 deletions bin/check-cancellation
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail

docker build --tag restyled/restyler:test .

export AWS_PROFILE=restyled

echo "Launching Restyler"
(restyled promote --image restyled/restyler:test stable |& ts >/tmp/run.log) &
pid=$!
echo "PID $pid"

cid=

echo "Waiting for Container"
while [ -z "$cid" ]; do
sleep 1
cid=$(docker ps | awk '/restyled\/restyler:test/ { print $1 }')
done
echo "Container Id: $cid"
echo "Letting run..."
sleep 15

echo "Sending SIGQUIT..."
docker kill --signal SIGQUIT "$cid"
# echo "Sending SIGSTOP..."
# docker kill --signal SIGSTOP "$cid"
# echo "Sending USR1..."
# docker kill --signal USR1 "$cid"

wait "$pid"
echo "Restyler stopped."
15 changes: 15 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
: "${RESTYLER_CANCEL_SIGNAL:=QUIT}"

for signal in $(kill -l); do
if [ "$signal" != "$RESTYLER_CANCEL_SIGNAL" ]; then
# Best-effort forward all signals we don't handle
trap 'kill -'"$signal"' "$restyler_pid" 2>/dev/null' "$signal"
fi
done

trap 'echo "Build canceled."; exit 0' "$RESTYLER_CANCEL_SIGNAL"

/bin/restyler "$@" &
restyler_pid=$!
wait "$restyler_pid"

0 comments on commit 54d9c64

Please sign in to comment.