add updated 'start_up.sh' script for streamline-emr docker image

This modified script replaces adds a wait condition on startup before attempting
to interact with the database. This is done with 'mariadb-admin ping' run in a
loop at 1s intervals, ultimately timing out after 30s if unsuccessful. Other
minor updates to the script print additional info the docker logs during
startup.
This commit is contained in:
2025-04-02 15:44:52 -07:00
parent 72d3c83455
commit 886b364b55
2 changed files with 86 additions and 1 deletions
+1
View File
@@ -1 +1,2 @@
FROM streamlinehealth/streamline:signalytic FROM streamlinehealth/streamline:signalytic
COPY ./start_up.sh /var/www/html/start_up.sh
+84
View File
@@ -0,0 +1,84 @@
#! /bin/sh
# Required script variables
APP_NAME=${APP_NAME:-'streamline'}
export MYSQL_DATABASE=${DB_DATABASE:-'streamline'}
export MYSQL_USER=${DB_USERNAME:-'root'}
export MYSQL_PASSWORD=${DB_PASSWORD:-'streamline'}
export MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD:-'streamline'}
# execute run.sh script for MySQL initialisation
chmod +x .docker/mysql/mysql-init.sh
# run the MariaDB initialization script
echo "[info] running mariadb init script"
./.docker/mysql/mysql-init.sh
if [ $? -eq 0 ]; then
echo "[info] waiting for DB to start..."
for i in $(seq 1 30); do
mariadb-admin ping -u $MYSQL_USER -p$MYSQL_PASSWORD &>/dev/null
if [ $? -eq 0 ]; then
echo "[info] DB ready"
break
fi
sleep 1
done
mariadb-admin ping -u $MYSQL_USER -p$MYSQL_PASSWORD
if [ $? -ne 0 ]; then
echo "[info] timed out waiting for DB"
exit 1
fi
echo "[info] MySQL server started. checking for '$MYSQL_DATABASE' database. "
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -e "use streamline;"
# Guard condition to re-check existence of database schema
# If it doesnt exist, create it and import streamline_initial.sql file
if [ $? -eq 1 ]; then
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -e "CREATE DATABASE $MYSQL_DATABASE;"
if [ $? -eq 0 ]; then
echo "[info] Database: $MYSQL_DATABASE created."
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE < ./.docker/mysql/scripts/streamline_initial.sql
if [ $? -eq 0 ]; then
echo "[info] populated database."
else
echo "[error] database not populated."
fi
else
echo "[error] database not created."
fi
else
echo "[info] Database: $MYSQL_DATABASE exists. "
fi
echo "[info] starting $APP_NAME ..."
echo "[info] artisan migrate"
php /var/www/html/artisan migrate
echo "[info] migrate result: $?"
echo "[info] seed: PermissionTableSeeder"
php /var/www/html/artisan db:seed --class=PermissionTableSeeder
echo "[info] seed result: $?"
echo "[info] seed: PermissionsCategoryTableSeeder"
php /var/www/html/artisan db:seed --class=PermissionsCategoryTableSeeder
echo "[info] seed result: $?"
echo "serving app..."
php /var/www/html/artisan serve --host=0.0.0.0 --port=80
else
echo "[error] MariaDB server couldnt be started."
# terminate script if database isnt running
exit 1;
fi