Skip to content

Instantly share code, notes, and snippets.

@Andrej1A
Created July 13, 2020 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andrej1A/7b1bad417a3c011a61900c0d072e546b to your computer and use it in GitHub Desktop.
Save Andrej1A/7b1bad417a3c011a61900c0d072e546b to your computer and use it in GitHub Desktop.
entry point for Django application
#!/bin/bash
set -e
cmd="$@"
function postgres_ready(){
python << END
import sys
import psycopg2
try:
# conn = psycopg2.connect(dbname="$POSTGRES_USER", user="$POSTGRES_USER", password="$POSTGRES_PASSWORD", host="postgres")
conn = psycopg2.connect(dbname="postgres", user="postgres", password="", host="db")
except psycopg2.OperationalError:
sys.exit(-1)
sys.exit(0)
END
}
until postgres_ready; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - continuing..."
# export REDIS_URL=redis://redis:6379/0
export DATABASE_URL=postgres://postgres:@db:5432/postgres
exec $cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment