Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
!docker/coturn/alpine/
!docker/coturn/debian/
!docker/coturn/rootfs/
!docker/coturn/wireapp/

!cmake/
!CMakeLists.txt
Expand Down
20 changes: 20 additions & 0 deletions docker/coturn/wireapp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This image derives from another coturn image, and adds a script which
# polls the Prometheus metrics endpoint until there are no more active
# allocations. This is intended to be used as a pre-stop hook to allow graceful
# termination of the coturn process without disrupting active allocations.

ARG coturn_image=coturn/coturn
ARG coturn_tag=latest

FROM ${coturn_image}:${coturn_tag}

USER root

RUN apt-get update \
&& apt-get install -y --no-install-recommends --no-install-suggests \
curl grep coreutils

COPY docker/coturn/wireapp/pre-stop-hook.sh /usr/local/bin/pre-stop-hook
RUN chmod +x /usr/local/bin/pre-stop-hook

USER nobody:nogroup
35 changes: 35 additions & 0 deletions docker/coturn/wireapp/pre-stop-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# FUTUREWORK: this will break with IPv6. this should be fixed so it works with
# IPv6.

set -uo pipefail

SLEEPTIME=60

host="$1"
port="$2"

url="http://$host:$port/metrics"

echo "Polling coturn status on $url"

while true; do
allocs=$(curl -s "$url" | grep -E '^turn_active_allocations' | cut -d' ' -f2)
if [ "$?" != 0 ]; then
echo "Could not retrieve metrics from coturn!"
exit 1
fi

if [ -z "$allocs" ]; then
echo "No more active allocations, exiting"
exit 0
fi
if [ "$allocs" = 0 ]; then
echo "No more active allocations, exiting"
exit 0
fi

echo "Active allocations remaining, sleeping for $SLEEPTIME seconds"
sleep "$SLEEPTIME"
done