From edd1ef62127dcf8aa791c83a637a925dd45cb3fc Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sun, 11 Dec 2022 06:29:12 -0800 Subject: [PATCH] add wrapper script for a clean startup in container --- wait-for-synapse.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 wait-for-synapse.sh diff --git a/wait-for-synapse.sh b/wait-for-synapse.sh new file mode 100755 index 0000000..afb3a79 --- /dev/null +++ b/wait-for-synapse.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# wait-for-synapse.sh +# +# based on an exmaple from https://docs.docker.com/compose/startup-order/ +# +# command: ["./wait-for-synapse.sh", "synapse", "python", "/usr/src/app/pnut-matrix.py", "-d"] + +set -e + +host="$1" +# Shift arguments with mapping: +# - $0 => $0 +# - $1 => +# - $2 => $1 +# - $3 => $2 +# - ... +# This is done for `exec "$@"` below to work correctly +shift + +until [ "200" == $(curl -s -o /dev/null --head -w "%{http_code}" https://${host}/_matrix/client/versions) ]; do + >&2 echo "synapse is unavailable - sleeping" + sleep 3 +done + +>&2 echo "synapse is up - executing command" +exec "$@"