Bladeren bron

Waiting for database to come up.

master
Dan Helfman 1 jaar geleden
bovenliggende
commit
a6178ee7e6
3 gewijzigde bestanden met toevoegingen van 84 en 0 verwijderingen
  1. 1
    0
      Dockerfile
  2. 4
    0
      run.sh
  3. 79
    0
      wait-for

+ 1
- 0
Dockerfile Bestand weergeven

@@ -33,6 +33,7 @@ RUN install_packages \
COPY mediagoblin_local.ini.template /app/mediagoblin_local.ini.template
COPY uwsgi.yaml /etc/uwsgi/apps-enabled/mediagoblin.yaml
COPY nginx.conf /etc/nginx/sites-enabled/mediagoblin.conf
COPY wait-for /sbin/wait-for
COPY run.sh /sbin/run.sh

RUN addgroup --system mediagoblin \

+ 4
- 0
run.sh Bestand weergeven

@@ -7,6 +7,10 @@ envsubst < /app/mediagoblin_local.ini.template > /app/mediagoblin_local.ini
chown mediagoblin.www-data /app/mediagoblin_local.ini
su - mediagoblin --command "cd /app && gmg dbupdate"

# Wait for the database to come up.
database_host=$(echo $DATABASE_URL | cut -d @ -f 2 | cut -d / -f 1)
/sbin/wait-for ${database_host}:5432

# Run uWSGI and Nginx.
chown mediagoblin.www-data /app/user_dev
/usr/bin/uwsgi --uid mediagoblin --gid www-data --master --workers 3 /etc/uwsgi/apps-enabled/mediagoblin.yaml \

+ 79
- 0
wait-for Bestand weergeven

@@ -0,0 +1,79 @@
#!/bin/sh

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() {
for i in `seq $TIMEOUT` ; do
nc -z "$HOST" "$PORT" > /dev/null 2>&1
result=$?
if [ $result -eq 0 ] ; then
if [ $# -gt 0 ] ; then
exec "$@"
fi
exit 0
fi
sleep 1
done
echo "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 "$@"

Laden…
Annuleren
Opslaan