run 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. set -e
  3. if [[ "$DATABASE_HOST" =~ '_SERVICE_HOST' ]]; then
  4. DATABASE_HOST=$(echo "$DATABASE_HOST" | tr '[:lower:]' '[:upper:]')
  5. export DATABASE_HOST=${!DATABASE_HOST}
  6. echo "---> DATABASE_HOST: ${DATABASE_HOST} ..."
  7. fi
  8. if [[ "$DATABASE_PORT" =~ '_SERVICE_PORT' ]]; then
  9. DATABASE_PORT=$(echo "$DATABASE_PORT" | tr '[:lower:]' '[:upper:]')
  10. export DATABASE_PORT=${!DATABASE_PORT}
  11. echo "---> DATABASE_PORT: ${DATABASE_PORT} ..."
  12. fi
  13. if [ -z "${DO_NOT_CREATE_DATABASE}" ]; then
  14. echo "---> Creating database ..."
  15. bundle exec rake db:create
  16. fi
  17. if [ -z "${DO_NOT_MIGRATE}" ]; then
  18. echo "---> Migrating database ..."
  19. bundle exec rake db:migrate
  20. fi
  21. if [ -z "${DO_NOT_SEED}" ]; then
  22. echo "---> Seeding database ..."
  23. set +e
  24. bundle exec rake db:seed
  25. set -e
  26. fi
  27. # Configure the unicorn server
  28. mv config/unicorn.rb.example config/unicorn.rb
  29. sed -ri 's/^listen .*$/listen ENV["PORT"]/' config/unicorn.rb
  30. sed -ri 's/^stderr_path.*$//' config/unicorn.rb
  31. sed -ri 's/^stdout_path.*$//' config/unicorn.rb
  32. export RACK_ENV=${RACK_ENV:-"production"}
  33. WORKER_CMD="${WORKER_CMD:-"unicorn -c ./deployment/heroku/unicorn.rb --listen 0.0.0.0:8080"}"
  34. echo "---> Executing command: ${WORKER_CMD}"
  35. exec bundle exec ${WORKER_CMD}