Skip to content

Instantly share code, notes, and snippets.

@digi9ten
Created February 17, 2017 01:51
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 digi9ten/65d07a42233502114aa7757be6e602bb to your computer and use it in GitHub Desktop.
Save digi9ten/65d07a42233502114aa7757be6e602bb to your computer and use it in GitHub Desktop.
For Kong users, on Postgres. Checks if the postgres DB exists, then creates it if need be. Creates a pgpass file for the ec2-user, just in case.
function setup_database_if_needed {
##
## Since Kong does not actually create the DB automatically, we need to do that here...
##
if [ ! -f ~/.pgpass ]; then
echo "*:*:*:${KONG_RDS_USER}:${KONG_RDS_PASS}" | tee -a ~/.pgpass
chmod 0600 ~/.pgpass
fi
does_db_exist=$(psql -lqt -h ${KONG_RDS_ENDPOINT} -U ${KONG_RDS_USER} | cut -d \| -f 1 | grep -c ${KONG_RDS_DB_NAME})
if [ 0 -eq $does_db_exist ]; then
createdb -h ${KONG_RDS_ENDPOINT} -U ${KONG_RDS_USER} ${KONG_RDS_DB_NAME}
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment