Skip to content

Commit

Permalink
Support for env vars-driven Postgresql connection setup
Browse files Browse the repository at this point in the history
  • Loading branch information
zozlak committed Jun 3, 2020
1 parent 2a1a57e commit d43c682
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions root/home/www-data/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,22 @@ su -l www-data -c 'cp /home/www-data/vendor/acdh-oeaw/arche-core/index.php /home
su -l www-data -c 'cp /home/www-data/vendor/acdh-oeaw/arche-core/.htaccess /home/www-data/docroot/api/.htaccess'

# Database connection config
PG_CONN=""
su -l www-data -c 'echo "" > /home/www-data/.pgpass && chmod 600 /home/www-data/.pgpass'
if [ ! -z "$PG_HOST" ]; then
PG_PORT=${PG_PORT:=5432}
PG_USER=${PG_USER:=postgres}
PG_DBNAME=${PG_DBNAME:=postgres}
echo "$PG_HOST:$PG_PORT:$PG_DBNAME:$PG_USER:PG_PSWD" >> /home/www-data/.pgpass
PG_CONN="-h '$PG_HOST' -p $PG_PORT -U '$PG_USER' '$PG_DBNAME'"
export PG_CONN2="-h '$PG_HOST' -p $PG_PORT -U '$PG_USER'"
export PG_EXTERNAL=1
else
PG_USER=www-data
PG_DBNAME=www-data
fi
export PG_HOST=${PG_HOST:=127.0.0.1}
export PG_PORT=${PG_PORT:=5432}
export PG_USER=${PG_USER:=postgres}
export PG_DBNAME=${PG_DBNAME:=postgres}
export PG_CONN="-h $PG_HOST -p $PG_PORT -U $PG_USER $PG_DBNAME"
su -l www-data -c 'echo "" > /home/www-data/.pgpass && chmod 600 /home/www-data/.pgpass'
if [ ! -z "$PG_EXTERNAL" ]; then
echo "$PG_HOST:$PG_PORT:$PG_DBNAME:$PG_USER:$PG_PSWD" >> /home/www-data/.pgpass
echo "$PG_HOST:$PG_PORT:$PG_USER:$PG_USER:$PG_PSWD" >> /home/www-data/.pgpass
fi
export PG_CONN

# User init scripts
rm -f /home/www-data/postgresql/postmaster.pid
Expand Down

0 comments on commit d43c682

Please sign in to comment.