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.

55 lines
1.8 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. celery --app=config worker --loglevel=INFO --concurrency="${CELERY_WORKERS:-1}" &
  35. celery_pid="$!"
  36. while :; do
  37. if [[ ! -e "/proc/${celery_pid}" ]]; then
  38. echo "celery crashed" >&2
  39. exit 1
  40. elif [[ ! -e "/proc/${gunicorn_pid}" ]]; then
  41. echo "gunicorn crashed" >&2
  42. exit 2
  43. else
  44. sleep 10
  45. fi
  46. done