From 48573829695522dba09abdba920fdaec46c74353 Mon Sep 17 00:00:00 2001 From: Felipe Cecagno <fcecagno@gmail.com> Date: Thu, 2 Aug 2018 17:51:38 -0300 Subject: [PATCH] fsesl wait for freeswitch; change links by depends_on; remove freeswitch ipv6 config files; enable wss-binding element on freeswitch; fix kurento listen only --- akka-bbb-fsesl/Dockerfile | 3 +- akka-bbb-fsesl/wait-for-it.sh | 177 ++++++++++++++++++ .../config/custom-environment-variables.yml | 2 + labs/bbb-webrtc-sfu/docker-entrypoint.sh | 4 + labs/docker/docker-compose.yml | 20 +- labs/docker/freeswitch/Dockerfile | 3 +- labs/docker/freeswitch/docker-entrypoint.sh | 7 +- 7 files changed, 203 insertions(+), 13 deletions(-) create mode 100755 akka-bbb-fsesl/wait-for-it.sh diff --git a/akka-bbb-fsesl/Dockerfile b/akka-bbb-fsesl/Dockerfile index f1a7483010..ff06041d93 100644 --- a/akka-bbb-fsesl/Dockerfile +++ b/akka-bbb-fsesl/Dockerfile @@ -15,11 +15,12 @@ RUN apt-get update \ RUN cd /source \ && sbt debian:packageBin -# FROM ubuntu:16.04 FROM openjdk:8-jre-slim-stretch COPY --from=builder /source/target/*.deb /root/ RUN dpkg -i /root/*.deb +COPY wait-for-it.sh /usr/local/bin/ + CMD ["/usr/share/bbb-fsesl-akka/bin/bbb-fsesl-akka"] diff --git a/akka-bbb-fsesl/wait-for-it.sh b/akka-bbb-fsesl/wait-for-it.sh new file mode 100755 index 0000000000..bbe404324b --- /dev/null +++ b/akka-bbb-fsesl/wait-for-it.sh @@ -0,0 +1,177 @@ +#!/usr/bin/env bash +# Use this script to test if a given TCP host/port are available + +cmdname=$(basename $0) + +echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi } + +usage() +{ + cat << USAGE >&2 +Usage: + $cmdname host:port [-s] [-t timeout] [-- command args] + -h HOST | --host=HOST Host or IP under test + -p PORT | --port=PORT TCP port under test + Alternatively, you specify the host and port as host:port + -s | --strict Only execute subcommand if the test succeeds + -q | --quiet Don't output any status messages + -t TIMEOUT | --timeout=TIMEOUT + Timeout in seconds, zero for no timeout + -- COMMAND ARGS Execute command with args after the test finishes +USAGE + exit 1 +} + +wait_for() +{ + if [[ $TIMEOUT -gt 0 ]]; then + echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT" + else + echoerr "$cmdname: waiting for $HOST:$PORT without a timeout" + fi + start_ts=$(date +%s) + while : + do + if [[ $ISBUSY -eq 1 ]]; then + nc -z $HOST $PORT + result=$? + else + (echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1 + result=$? + fi + if [[ $result -eq 0 ]]; then + end_ts=$(date +%s) + echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds" + break + fi + sleep 1 + done + return $result +} + +wait_for_wrapper() +{ + # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692 + if [[ $QUIET -eq 1 ]]; then + timeout $BUSYTIMEFLAG $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & + else + timeout $BUSYTIMEFLAG $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & + fi + PID=$! + trap "kill -INT -$PID" INT + wait $PID + RESULT=$? + if [[ $RESULT -ne 0 ]]; then + echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT" + fi + return $RESULT +} + +# process arguments +while [[ $# -gt 0 ]] +do + case "$1" in + *:* ) + hostport=(${1//:/ }) + HOST=${hostport[0]} + PORT=${hostport[1]} + shift 1 + ;; + --child) + CHILD=1 + shift 1 + ;; + -q | --quiet) + QUIET=1 + shift 1 + ;; + -s | --strict) + STRICT=1 + shift 1 + ;; + -h) + HOST="$2" + if [[ $HOST == "" ]]; then break; fi + shift 2 + ;; + --host=*) + HOST="${1#*=}" + shift 1 + ;; + -p) + PORT="$2" + if [[ $PORT == "" ]]; then break; fi + shift 2 + ;; + --port=*) + PORT="${1#*=}" + shift 1 + ;; + -t) + TIMEOUT="$2" + if [[ $TIMEOUT == "" ]]; then break; fi + shift 2 + ;; + --timeout=*) + TIMEOUT="${1#*=}" + shift 1 + ;; + --) + shift + CLI=("$@") + break + ;; + --help) + usage + ;; + *) + echoerr "Unknown argument: $1" + usage + ;; + esac +done + +if [[ "$HOST" == "" || "$PORT" == "" ]]; then + echoerr "Error: you need to provide a host and port to test." + usage +fi + +TIMEOUT=${TIMEOUT:-15} +STRICT=${STRICT:-0} +CHILD=${CHILD:-0} +QUIET=${QUIET:-0} + +# check to see if timeout is from busybox? +# check to see if timeout is from busybox? +TIMEOUT_PATH=$(realpath $(which timeout)) +if [[ $TIMEOUT_PATH =~ "busybox" ]]; then + ISBUSY=1 + BUSYTIMEFLAG="-t" +else + ISBUSY=0 + BUSYTIMEFLAG="" +fi + +if [[ $CHILD -gt 0 ]]; then + wait_for + RESULT=$? + exit $RESULT +else + if [[ $TIMEOUT -gt 0 ]]; then + wait_for_wrapper + RESULT=$? + else + wait_for + RESULT=$? + fi +fi + +if [[ $CLI != "" ]]; then + if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then + echoerr "$cmdname: strict mode, refusing to execute subprocess" + exit $RESULT + fi + exec "${CLI[@]}" +else + exit $RESULT +fi diff --git a/labs/bbb-webrtc-sfu/config/custom-environment-variables.yml b/labs/bbb-webrtc-sfu/config/custom-environment-variables.yml index 2f5678e207..074de09626 100644 --- a/labs/bbb-webrtc-sfu/config/custom-environment-variables.yml +++ b/labs/bbb-webrtc-sfu/config/custom-environment-variables.yml @@ -3,3 +3,5 @@ kurentoIp: KURENTO_IP redisHost: REDIS_HOST freeswitch: ip: FREESWITCH_IP +log: + level: LOG_LEVEL diff --git a/labs/bbb-webrtc-sfu/docker-entrypoint.sh b/labs/bbb-webrtc-sfu/docker-entrypoint.sh index 5f513af89e..d424e511a1 100755 --- a/labs/bbb-webrtc-sfu/docker-entrypoint.sh +++ b/labs/bbb-webrtc-sfu/docker-entrypoint.sh @@ -4,4 +4,8 @@ CONTAINER_IP=$(hostname -I | awk '{print $1}') sed -i "s|^\(localIpAddress\):.*|\1: \"$CONTAINER_IP\"|g" config/production.yml +if [ ! -z "$KURENTO_NAME" ]; then + export KURENTO_IP=$(getent hosts $KURENTO_NAME | awk '{ print $1 }') +fi + npm start diff --git a/labs/docker/docker-compose.yml b/labs/docker/docker-compose.yml index 44b3d809f1..fc63501a79 100644 --- a/labs/docker/docker-compose.yml +++ b/labs/docker/docker-compose.yml @@ -12,7 +12,7 @@ services: bbb-html5: image: ${TAG_PREFIX}bbb-html5${TAG_SUFFIX} restart: unless-stopped - links: + depends_on: - mongo - redis environment: @@ -24,7 +24,7 @@ services: bbb-webhooks: image: ${TAG_PREFIX}bbb-webhooks${TAG_SUFFIX} restart: unless-stopped - links: + depends_on: - redis environment: REDIS_HOST: redis @@ -33,7 +33,7 @@ services: bbb-freeswitch: image: ${TAG_PREFIX}bbb-freeswitch${TAG_SUFFIX} restart: unless-stopped - links: + depends_on: - coturn volumes: - media-audio:/var/freeswitch/meetings @@ -41,15 +41,16 @@ services: bbb-webrtc-sfu: image: ${TAG_PREFIX}bbb-webrtc-sfu${TAG_SUFFIX} restart: unless-stopped - links: + depends_on: - redis - kurento - bbb-freeswitch environment: - KURENTO_IP: ${EXTERNAL_IP} + KURENTO_NAME: kurento KURENTO_URL: ws://kurento:8888/kurento REDIS_HOST: redis FREESWITCH_IP: bbb-freeswitch + LOG_LEVEL: debug coturn: image: ${TAG_PREFIX}coturn${TAG_SUFFIX} @@ -84,7 +85,7 @@ services: bbb-apps-akka: image: ${TAG_PREFIX}bbb-apps-akka${TAG_SUFFIX} restart: unless-stopped - links: + depends_on: - redis environment: JAVA_OPTS: -Dredis.host=redis @@ -92,16 +93,17 @@ services: bbb-fsesl-akka: image: ${TAG_PREFIX}bbb-fsesl-akka${TAG_SUFFIX} restart: unless-stopped - links: + depends_on: - bbb-freeswitch - redis + command: ["wait-for-it.sh", "bbb-freeswitch:8021", "--timeout=60", "--strict", "--", "/usr/share/bbb-fsesl-akka/bin/bbb-fsesl-akka"] environment: JAVA_OPTS: -Dredis.host=redis -Dfreeswitch.esl.host=bbb-freeswitch bbb-web: image: ${TAG_PREFIX}bbb-web${TAG_SUFFIX} restart: unless-stopped - links: + depends_on: - redis volumes: - bigbluebutton:/var/bigbluebutton @@ -125,7 +127,7 @@ services: nginx: image: ${TAG_PREFIX}nginx${TAG_SUFFIX} restart: unless-stopped - links: + depends_on: - bbb-webhooks - bbb-web - bbb-html5 diff --git a/labs/docker/freeswitch/Dockerfile b/labs/docker/freeswitch/Dockerfile index 8e0636bea9..4e1cb76c74 100644 --- a/labs/docker/freeswitch/Dockerfile +++ b/labs/docker/freeswitch/Dockerfile @@ -8,7 +8,8 @@ RUN apt-get update \ RUN echo "deb http://ubuntu.bigbluebutton.org/xenial-200-dev bigbluebutton-xenial main " | tee /etc/apt/sources.list.d/bigbluebutton.list \ && wget http://ubuntu.bigbluebutton.org/repo/bigbluebutton.asc -O- | apt-key add - \ && apt-get update \ - && apt-get -y install bbb-freeswitch-core + && apt-get -y install bbb-freeswitch-core \ + && find /opt/freeswitch/conf/sip_profiles/ -name "*ipv6*" -prune -exec rm -rf "{}" \; EXPOSE 8021 EXPOSE 5060 diff --git a/labs/docker/freeswitch/docker-entrypoint.sh b/labs/docker/freeswitch/docker-entrypoint.sh index 68472535f6..90e82ba379 100755 --- a/labs/docker/freeswitch/docker-entrypoint.sh +++ b/labs/docker/freeswitch/docker-entrypoint.sh @@ -5,7 +5,10 @@ IP=$(hostname -I | cut -d' ' -f1) xmlstarlet edit --inplace --update '//X-PRE-PROCESS[@cmd="set" and starts-with(@data, "external_rtp_ip=")]/@data' --value "stun:coturn" /opt/freeswitch/conf/vars.xml xmlstarlet edit --inplace --update '//X-PRE-PROCESS[@cmd="set" and starts-with(@data, "external_sip_ip=")]/@data' --value "stun:coturn" /opt/freeswitch/conf/vars.xml xmlstarlet edit --inplace --update '//X-PRE-PROCESS[@cmd="set" and starts-with(@data, "local_ip_v4=")]/@data' --value "${IP}" /opt/freeswitch/conf/vars.xml -xmlstarlet edit --inplace --update '//param[@name="ws-binding"]/@value' --value ":7443" /opt/freeswitch/conf/sip_profiles/external.xml -xmlstarlet edit --inplace --update '//param[@name="ws-binding"]/@name' --value "wss-binding" /opt/freeswitch/conf/sip_profiles/external.xml +# add wss-binding element +xmlstarlet edit --inplace --subnode '//settings' --type elem --name 'newsubnode' --value '' /opt/freeswitch/conf/sip_profiles/external.xml +xmlstarlet edit --inplace --insert '//newsubnode' --type attr --name 'name' --value 'wss-binding' /opt/freeswitch/conf/sip_profiles/external.xml +xmlstarlet edit --inplace --insert '//newsubnode' --type attr --name 'value' --value ':7443' /opt/freeswitch/conf/sip_profiles/external.xml +xmlstarlet edit --inplace --rename '//newsubnode' --value 'param' /opt/freeswitch/conf/sip_profiles/external.xml /opt/freeswitch/bin/freeswitch -- GitLab