bootstrap.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash -e
  2. source /tmp/.env
  3. echo DATABASE_HOST=${DATABASE_HOST}
  4. # start mysql server if ${DATABASE_HOST} is the .env.example default
  5. if [ "${START_MYSQL}" = "true" ]; then
  6. if [ "${DATABASE_ADAPTER}" = "postgresql" ]; then
  7. echo "DATABASE_ADAPTER 'postgresql' is not supported internally. Please provide DATABASE_HOST."
  8. exit 1
  9. fi
  10. # initialize MySQL data directory
  11. if [ ! -d /var/lib/mysql/mysql ]; then
  12. mysql_install_db --user=$(whoami) --datadir=/tmp/mysql
  13. mv -f /tmp/mysql/* /var/lib/mysql/
  14. fi
  15. echo "Starting mysql server..."
  16. supervisorctl start mysqld >/dev/null
  17. # wait for mysql server to start (max 120 seconds)
  18. timeout=120
  19. while ! mysqladmin -u root status >/dev/null 2>&1 && ! mysqladmin -u root --password="${DATABASE_PASSWORD}" status >/dev/null 2>&1
  20. do
  21. (( timeout = timeout - 1 ))
  22. if [ $timeout -eq 0 ]; then
  23. echo "Failed to start mysql server"
  24. exit 1
  25. fi
  26. echo -n .
  27. sleep 1
  28. done
  29. if ! echo "USE ${DATABASE_NAME}" | mysql -u${DATABASE_USERNAME:-root} "${DATABASE_PASSWORD:+-p$DATABASE_PASSWORD}" >/dev/null 2>&1; then
  30. echo "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('${DATABASE_PASSWORD}');" | mysql -u root
  31. fi
  32. fi
  33. supervisorctl start foreman >/dev/null