Skip to content

Instantly share code, notes, and snippets.

@thanhson1085
Last active November 19, 2016 14:07
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 thanhson1085/aded4c9c1ccc7938da0ddf256fc6472e to your computer and use it in GitHub Desktop.
Save thanhson1085/aded4c9c1ccc7938da0ddf256fc6472e to your computer and use it in GitHub Desktop.
Docker Entrypoint waits Mysql Started before running App
#!/bin/bash
set -e
host="$1"
password="$MYSQL_ROOT_PASSWORD"
until mysql -h "$host" -uroot -p$password; do
>&2 echo "MYSQL is unavailable - sleeping"
sleep 1
done
>&2 echo "MYSQL is up - executing command"
# start service
>&2 echo "Start Service ...!"
cd /build && python3 run.py
#!/bin/bash
set -e
host="$1"
password="$MYSQL_PASS"
until mysql -h "$host" -uadmin -p$password; do
>&2 echo "MYSQL is unavailable - sleeping"
sleep 1
done
while 1
do
SQL_IS_RUNNING=$(mysql -h db_slave -upolsat -p$password -e "SHOW SLAVE STATUS\G" | grep "Slave_SQL_Running" | awk '{ print $2 }')
if [ "$SQL_IS_RUNNING" == "Yes" ]
then
break
fi
>&2 echo "MYSQL SLave is unavailable - sleeping"
sleep 1
done
>&2 echo "MYSQL is up - executing command"
# run cron service
>&2 echo "Start Cron ...!"
cron
# run upgrade database
>&2 echo "Upgrade/Downgrade Db Schema...!"
cd /build && python3 manage.py db upgrade
# start service
>&2 echo "Start Service ...!"
cd /build && python3 run.py
#uwsgi --ini /build/wsgi.ini --uid root --gid www-data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment