#!/bin/sh
set -e

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
	set -- php-fpm "$@"
fi

mkdir -p var/cache var/log
if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
	echo "Waiting for db to be ready..."
	bin/console ilios:wait-for-database
	echo "The db is now ready and reachable"
	bin/console cache:warmup
	bin/console doctrine:migrations:migrate --no-interaction

	setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var
	setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
fi

exec docker-php-entrypoint "$@"
#!/bin/sh
set -e

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
	set -- php-fpm "$@"
fi

mkdir -p var/cache var/log
if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
	
	if [ "$ILIOS_DATABASE_URL" ]; then
		echo "Waiting for db to be ready..."
		bin/console ilios:wait-for-database
		echo "The db is now ready and reachable"

		bin/console cache:warmup
		bin/console doctrine:migrations:migrate --no-interaction
	fi

	setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var
	setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
fi

exec docker-php-entrypoint "$@"
Check for database to be setup during container boot
Check for database to be setup during container boot

It's required and nothing is going to work without it, but checking
first means the container can be booted without a DB for testing or
extending.
