mrts/docker-postgresql-multiple-databases

Does not run script on initialization

bonjefir opened this issue · 6 comments

Hi

This is my .sh file

#!/bin/bash

set -e
set -u

create_user_and_database() {
	local database=$1
	echo "  Creating user and database '$database'"
	psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
		CREATE USER $POSTGRES_USER;
	    CREATE DATABASE $database;
	    GRANT ALL PRIVILEGES ON DATABASE $database TO $POSTGRES_USER;
		CREATE USER grafana;
	    GRANT SELECT ON ALL TABLES IN SCHEMA public TO grafana;
EOSQL
}


echo "-------------- $POSTGRES_MULTIPLE_DATABASES"

if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
	echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"
	for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do
		create_user_and_database $db
	done
	echo "Multiple databases created"
fi

using docker exec command(after running docker-compose) I can confirm that it is on the right path with mentioned content(/docker-entrypoint-initdb.d/create-multiple-postgresql-databases.sh)

But when I run docker-compose, it does not run the .sh file. docker-compose output:

Recreating db ... 
Recreating db ... done
Attaching to db
db        | LOG:  database system was shut down at 2018-07-22 06:36:27 UTC
db        | LOG:  MultiXact member wraparound protections are now enabled
db        | LOG:  database system is ready to accept connections
db        | LOG:  autovacuum launcher started

It stopped at this state and does not run .sh file and other containers...

I can't find "create-multiple-postgresql-databases.sh" in its specified path inside the container "/docker-entrypoint-initdb.d/create-multiple-postgresql-databases.sh"

Any help will be appreciated. Thank you.

Got same problem, help pls.

Got same problem, help pls.

Same problem, in the sense? are you also facing the problem in finding the file in it's location.

When I build/rebuild the image it goes to this state(i.e prints above logs and stops there, since I run it in a docker-compose, docker-compose does not run other containers).
My problem solved with running docker-compose with rebuild my db container and afterwards running it without build. Fist just for building the databases and running script(it stops as mentioned above) and second to use it.

mrts commented

Alright, seems to be resolved then. Thanks for reporting back!