foreman.sh 992 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/bash -e
  2. source /tmp/.env
  3. # The database may need to start up for a bit first
  4. if [ -n "${INTENTIONALLY_SLEEP}" ]; then
  5. echo "Intentionally sleeping ${INTENTIONALLY_SLEEP}"
  6. sleep ${INTENTIONALLY_SLEEP}
  7. fi
  8. if [ -n "${DATABASE_INITIAL_CONNECT_MAX_RETRIES}" ]; then
  9. max=${DATABASE_INITIAL_CONNECT_MAX_RETRIES}
  10. count=0
  11. while ! rake database_test:ping > /dev/null 2>&1 && [[ $count -le $max ]] ; do
  12. count=$[$count+1]
  13. echo "Retry $count of $max attempting to connect to $DATABASE_HOST. Sleeping ${DATABASE_INITIAL_CONNECT_SLEEP:5}"
  14. sleep ${DATABASE_INITIAL_CONNECT_SLEEP:5}
  15. done
  16. fi
  17. # We may need to try and create a database
  18. if [ -z "${DO_NOT_CREATE_DATABASE}" ]; then
  19. bundle exec rake db:create
  20. fi
  21. # Assuming we have a created database, run the migrations and seed it idempotently.
  22. if [ -z "${DO_NOT_MIGRATE}" ]; then
  23. bundle exec rake db:migrate
  24. fi
  25. if [ -z "${DO_NOT_SEED}" ]; then
  26. bundle exec rake db:seed
  27. fi
  28. # Start huginn
  29. exec bundle exec foreman start