1
0

bootstrap.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. mysqld --initialize-insecure --user=$(whoami) --datadir=/tmp/mysql
  13. mv -f /tmp/mysql/* /var/lib/mysql/
  14. fi
  15. echo "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '${DATABASE_PASSWORD}';" > /app/tmp/mysql_init.sql
  16. echo "Starting mysql server..."
  17. supervisorctl start mysqld >/dev/null
  18. # wait for mysql server to start (max 120 seconds)
  19. timeout=120
  20. while ! mysqladmin -u root status >/dev/null 2>&1 && ! mysqladmin -u root --password="${DATABASE_PASSWORD}" status >/dev/null 2>&1
  21. do
  22. (( timeout = timeout - 1 ))
  23. if [ $timeout -eq 0 ]; then
  24. echo "Failed to start mysql server"
  25. exit 1
  26. fi
  27. echo -n .
  28. sleep 1
  29. done
  30. fi
  31. supervisorctl start foreman >/dev/null