Comment and indent app entrypoint (#182)

This commit is contained in:
Kyâne Pichou 2017-10-14 16:47:44 +02:00 committed by GitHub
parent 5cc50eb522
commit 29bff18001

View File

@ -1,9 +1,11 @@
#!/bin/bash #!/bin/bash
# Function to generate a random salt
generate_salt() { generate_salt() {
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 48 | head -n 1 cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 48 | head -n 1
} }
# Read environment variables or set default values
DB_HOST=${DB_HOST:-db} DB_HOST=${DB_HOST:-db}
DB_PORT_NUMBER=${DB_PORT_NUMBER:-5432} DB_PORT_NUMBER=${DB_PORT_NUMBER:-5432}
MM_USERNAME=${MM_USERNAME:-mmuser} MM_USERNAME=${MM_USERNAME:-mmuser}
@ -16,6 +18,7 @@ if [ "${1:0:1}" = '-' ]; then
fi fi
if [ "$1" = 'platform' ]; then if [ "$1" = 'platform' ]; then
# Check CLI args for a -config option
for ARG in $@; for ARG in $@;
do do
case "$ARG" in case "$ARG" in
@ -24,9 +27,9 @@ if [ "$1" = 'platform' ]; then
esac esac
done done
if [ ! -f $MM_CONFIG ] if [ ! -f $MM_CONFIG ]
then then
# If there is no configuration file, create it with some default values
echo "No configuration file" $MM_CONFIG echo "No configuration file" $MM_CONFIG
echo "Creating a new one" echo "Creating a new one"
# Copy default configuration file # Copy default configuration file
@ -51,6 +54,7 @@ if [ "$1" = 'platform' ]; then
echo "Using existing config file" $MM_CONFIG echo "Using existing config file" $MM_CONFIG
fi fi
# Configure database access
if [ -z "$MM_SQLSETTINGS_DATASOURCE" ] if [ -z "$MM_SQLSETTINGS_DATASOURCE" ]
then then
echo -ne "Configure database connection..." echo -ne "Configure database connection..."
@ -60,13 +64,15 @@ if [ "$1" = 'platform' ]; then
echo "Using existing database connection" echo "Using existing database connection"
fi fi
# Wait for database to be reachable
echo "Wait until database $DB_HOST:$DB_PORT_NUMBER is ready..." echo "Wait until database $DB_HOST:$DB_PORT_NUMBER is ready..."
until nc -z $DB_HOST $DB_PORT_NUMBER until nc -z $DB_HOST $DB_PORT_NUMBER
do do
sleep 1 sleep 1
done done
# Wait to avoid "panic: Failed to open sql connection pq: the database system is starting up" # Wait another second for the database to be properly started.
# Necessary to avoid "panic: Failed to open sql connection pq: the database system is starting up"
sleep 1 sleep 1
echo "Starting platform" echo "Starting platform"