diff options
author | Sylvain Desbureaux <sylvain.desbureaux@orange.com> | 2017-10-23 10:28:46 +0200 |
---|---|---|
committer | Sylvain Desbureaux <sylvain.desbureaux@orange.com> | 2017-10-25 08:52:00 +0200 |
commit | a63074068fee5b76cc877bda88dcdc3e3f9a35c1 (patch) | |
tree | 3d388b883b534dd47338e098a33e27a266f7273e /packages/docker/src | |
parent | cb81b55dd9505499ff3facbaeec1a6a8bacb6b3c (diff) |
Add wait-for.sh to control container boot order
also install nc in order to make wait-for script
works
Change-Id: Id21f96bbf546542bf930c3faf33117a1434eeeee
Issue-ID: SO-208
Signed-off-by: Sylvain Desbureaux <sylvain.desbureaux@orange.com>
Diffstat (limited to 'packages/docker/src')
-rw-r--r-- | packages/docker/src/main/docker/docker-files/Dockerfile.mso-chef-final | 4 | ||||
-rwxr-xr-x | packages/docker/src/main/docker/docker-files/wait-for.sh | 85 |
2 files changed, 88 insertions, 1 deletions
diff --git a/packages/docker/src/main/docker/docker-files/Dockerfile.mso-chef-final b/packages/docker/src/main/docker/docker-files/Dockerfile.mso-chef-final index f471caa340..4b7bbaf776 100644 --- a/packages/docker/src/main/docker/docker-files/Dockerfile.mso-chef-final +++ b/packages/docker/src/main/docker/docker-files/Dockerfile.mso-chef-final @@ -18,7 +18,7 @@ ENV CHEF_CONFIG_NAME="mso-config" ### Downloading dependencies USER root -RUN apt-get install -y curl && curl -LO https://packages.chef.io/stable/ubuntu/12.04/chefdk_0.17.17-1_amd64.deb && curl -LO http://central.maven.org/maven2/org/mariadb/jdbc/mariadb-java-client/1.5.4/mariadb-java-client-1.5.4.jar && apt-get remove --purge -y curl && apt-get autoremove -y +RUN apt-get install -y netcat curl && curl -LO https://packages.chef.io/stable/ubuntu/12.04/chefdk_0.17.17-1_amd64.deb && curl -LO http://central.maven.org/maven2/org/mariadb/jdbc/mariadb-java-client/1.5.4/mariadb-java-client-1.5.4.jar && apt-get remove --purge -y curl && apt-get autoremove -y ### Install Chef RUN dpkg -i chefdk_0.17.17-1_amd64.deb @@ -81,6 +81,8 @@ COPY ./maven/artifacts/* $JBOSS_HOME/standalone/deployments/ RUN mkdir -p /etc/mso/config.d/ASDC && chown -R jboss:jboss /etc/mso/config.d/ASDC && chmod u+xrw /etc/mso/config.d/ASDC +COPY wait-for.sh / + ## Install heatbridge #RUN apt-get install -y python && apt-get install -y python-pip && echo 'PIP Installed, doing upgrade' && pip install --upgrade pip #RUN mkdir /opt/mso/heatbridge diff --git a/packages/docker/src/main/docker/docker-files/wait-for.sh b/packages/docker/src/main/docker/docker-files/wait-for.sh new file mode 100755 index 0000000000..2525821878 --- /dev/null +++ b/packages/docker/src/main/docker/docker-files/wait-for.sh @@ -0,0 +1,85 @@ +#!/bin/sh +# https://github.com/Eficode/wait-for.git +# MIT License + +TIMEOUT=15 +QUIET=0 + +echoerr() { + if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi +} + +usage() { + exitcode="$1" + cat << USAGE >&2 +Usage: + $cmdname host:port [-t timeout] [-- command args] + -q | --quiet Do not 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 "$exitcode" +} + +wait_for() { + command="$*" + if [ "$QUIET" -ne 1 ]; then echo "$0: probing host $HOST port $PORT"; fi + for i in `seq $TIMEOUT` ; do + nc -z "$HOST" "$PORT" > /dev/null 2>&1 + result=$? + if [ $result -eq 0 ] ; then + if [ "$QUIET" -ne 1 ]; then echo "$0: operation succeeded on try $i"; fi + if [ -n "$command" ] ; then + if [ "$QUIET" -ne 1 ]; then echo "$0: exec-ing command $command"; fi + exec $command + fi + exit 0 + fi + if [ "$QUIET" -ne 1 ]; then echo "$0: sleeping after try $i"; fi + sleep 1 + done + echo "$0: Operation timed out" >&2 + exit 1 +} + +while [ $# -gt 0 ] +do + case "$1" in + *:* ) + HOST=$(printf "%s\n" "$1"| cut -d : -f 1) + PORT=$(printf "%s\n" "$1"| cut -d : -f 2) + shift 1 + ;; + -q | --quiet) + QUIET=1 + shift 1 + ;; + -t) + TIMEOUT="$2" + if [ "$TIMEOUT" = "" ]; then break; fi + shift 2 + ;; + --timeout=*) + TIMEOUT="${1#*=}" + shift 1 + ;; + --) + shift + break + ;; + --help) + usage 0 + ;; + *) + echoerr "Unknown argument: $1" + usage 1 + ;; + esac +done + +if [ "$HOST" = "" -o "$PORT" = "" ]; then + echoerr "Error: you need to provide a host and port to test." + usage 2 +fi + +wait_for "$@" |