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.

61 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 --bind="0.0.0.0:${PORT:-8000}" --workers="${WORKERS:-4}" app.wsgi --timeout 300
  32. gunicorn --bind="0.0.0.0:${PORT:-8000}" --workers="${WORKERS:-1}" config.wsgi --timeout=300 &
  33. gunicorn_pid="$!"
  34. echo "Starting celery"
  35. celery --app=config worker --loglevel=INFO --concurrency="${CELERY_WORKERS:-1}" &
  36. celery_pid="$!"
  37. echo "Starting flower"
  38. if [[ -n "${FLOWER_BASIC_AUTH:-}" ]]; then
  39. celery --app=config flower --basic_auth="${FLOWER_BASIC_AUTH}" &
  40. fi
  41. while :; do
  42. if [[ ! -e "/proc/${celery_pid}" ]]; then
  43. echo "celery crashed" >&2
  44. exit 1
  45. elif [[ ! -e "/proc/${gunicorn_pid}" ]]; then
  46. echo "gunicorn crashed" >&2
  47. exit 2
  48. else
  49. sleep 10
  50. fi
  51. done