diff --git a/camunda-lib.sh b/camunda-lib.sh new file mode 100644 index 00000000..248dd43c --- /dev/null +++ b/camunda-lib.sh @@ -0,0 +1,19 @@ +wait_for_it() { + if [ -n "${WAIT_FOR}" ]; then + found=0 + for host_port in $(echo "${WAIT_FOR}" | tr ',' '\n'); do + if wait-for-it.sh "$host_port" -s -t ${WAIT_FOR_TIMEOUT} ; then + echo "$host_port available" + found=1 + break + else + echo "$host_port not available" + fi + done + if [ "$found" -eq 0 ] ; then + echo "No connection available in WAIT_FOR=$WAIT_FOR" + exit 1 + fi + fi +} + diff --git a/camunda-run.sh b/camunda-run.sh index 85d8e3b6..9002f912 100755 --- a/camunda-run.sh +++ b/camunda-run.sh @@ -3,6 +3,8 @@ set -Eeu trap 'Error on line $LINENO' ERR +source $(dirname "$0")/common-lib.sh + # Set Password as Docker Secrets for Swarm-Mode if [[ -z "${DB_PASSWORD:-}" && -n "${DB_PASSWORD_FILE:-}" && -f "${DB_PASSWORD_FILE:-}" ]]; then export DB_PASSWORD="$(< "${DB_PASSWORD_FILE}")" @@ -30,9 +32,7 @@ fi CMD="/camunda/internal/run.sh start" -if [ -n "${WAIT_FOR}" ]; then - CMD="wait-for-it.sh ${WAIT_FOR} -s -t ${WAIT_FOR_TIMEOUT} -- ${CMD}" -fi +wait_for_it # shellcheck disable=SC2086 exec ${CMD} "$@" diff --git a/camunda-tomcat.sh b/camunda-tomcat.sh index 51b1d5d2..847c68fd 100755 --- a/camunda-tomcat.sh +++ b/camunda-tomcat.sh @@ -3,6 +3,8 @@ set -Eeu trap 'Error on line $LINENO' ERR +source $(dirname "$0")/common-lib.sh + # Use existing tomcat distribution if present.. CATALINA_HOME="${CATALINA_HOME:-/camunda}" @@ -58,9 +60,7 @@ fi CMD+=" run" -if [ -n "${WAIT_FOR}" ]; then - CMD="wait-for-it.sh ${WAIT_FOR} -s -t ${WAIT_FOR_TIMEOUT} -- ${CMD}" -fi +wait_for_it # shellcheck disable=SC2086 exec ${CMD} diff --git a/camunda-wildfly.sh b/camunda-wildfly.sh index ded70e94..f2bd7ca6 100755 --- a/camunda-wildfly.sh +++ b/camunda-wildfly.sh @@ -3,6 +3,8 @@ set -Eeu trap 'Error on line $LINENO' ERR +source $(dirname "$0")/common-lib.sh + # Set default values for DB_ variables # Set Password as Docker Secrets for Swarm-Mode if [[ -z "${DB_PASSWORD:-}" && -n "${DB_PASSWORD_FILE:-}" && -f "${DB_PASSWORD_FILE:-}" ]]; then @@ -80,9 +82,7 @@ if [ "$JMX_PROMETHEUS" = "true" ] ; then export PREPEND_JAVA_OPTS="${PREPEND_JAVA_OPTS} -javaagent:/camunda/javaagent/jmx_prometheus_javaagent.jar=${JMX_PROMETHEUS_PORT}:${JMX_PROMETHEUS_CONF}" fi -if [ -n "${WAIT_FOR}" ]; then - CMD="wait-for-it.sh ${WAIT_FOR} -s -t ${WAIT_FOR_TIMEOUT} -- ${CMD}" -fi +wait_for_it # shellcheck disable=SC2086 exec ${CMD}