You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.9 KiB

  1. #!/usr/bin/env bash
  2. set -o errexit
  3. if [[ -z "${ADMIN_USERNAME}" ]]; then echo "Missing ADMIN_USERNAME environment variable" >&2; exit 1; fi
  4. if [[ -z "${ADMIN_PASSWORD}" ]]; then echo "Missing ADMIN_PASSWORD environment variable" >&2; exit 1; fi
  5. if [[ -z "${ADMIN_EMAIL}" ]]; then echo "Missing ADMIN_EMAIL environment variable" >&2; exit 1; fi
  6. if [[ -z "${PORT}" ]]; then echo "Missing PORT environment variable" >&2; exit 1; fi
  7. if [[ -z "${WORKERS}" ]]; then echo "Missing WORKERS environment variable" >&2; exit 1; fi
  8. if [[ -z "${CELERY_WORKERS}" ]]; then echo "Missing CELERY_WORKERS environment variable" >&2; exit 1; fi
  9. set -o nounset
  10. echo "Making staticfiles"
  11. static_dir=staticfiles
  12. mkdir -p client/dist/static
  13. if [[ ! -d $static_dir ]] || [[ -z $(ls -A $static_dir) ]]; then
  14. echo "Executing collectstatic"
  15. python manage.py collectstatic --noinput;
  16. fi
  17. echo "Initializing database"
  18. python manage.py wait_for_db
  19. python manage.py migrate
  20. python manage.py create_roles
  21. echo "Creating admin"
  22. if [[ -n "${ADMIN_USERNAME}" ]] && [[ -n "${ADMIN_PASSWORD}" ]] && [[ -n "${ADMIN_EMAIL}" ]]; then
  23. python manage.py create_admin \
  24. --username "${ADMIN_USERNAME}" \
  25. --password "${ADMIN_PASSWORD}" \
  26. --email "${ADMIN_EMAIL}" \
  27. --noinput \
  28. || true
  29. fi
  30. echo "Starting django"
  31. gunicorn \
  32. --bind="0.0.0.0:${PORT:-8000}" \
  33. --workers="${WORKERS:-1}" \
  34. --timeout=300 \
  35. --capture-output \
  36. --log-level info \
  37. config.wsgi &
  38. gunicorn_pid="$!"
  39. echo "Starting celery"
  40. celery --app=config worker --loglevel=INFO --concurrency="${CELERY_WORKERS:-1}" &
  41. celery_pid="$!"
  42. echo "Starting flower"
  43. if [[ -n "${FLOWER_BASIC_AUTH:-}" ]]; then
  44. celery --app=config flower --basic_auth="${FLOWER_BASIC_AUTH}" &
  45. fi
  46. while :; do
  47. if [[ ! -e "/proc/${celery_pid}" ]]; then
  48. echo "celery crashed" >&2
  49. exit 1
  50. elif [[ ! -e "/proc/${gunicorn_pid}" ]]; then
  51. echo "gunicorn crashed" >&2
  52. exit 2
  53. else
  54. sleep 10
  55. fi
  56. done