start.sh 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. set -eu -o pipefail
  3. # create data and logging directories
  4. mkdir -p /app/data /run/supervisor
  5. echo ".. check redash locations"
  6. if [ ! -d "/run/redash/" ]; then
  7. echo "... moving redash to run (directory '/run/redash/' not found)"
  8. mkdir -p /run/redash/current
  9. cp -r /app/code/redash/current/* /run/redash/current
  10. else
  11. echo "... redash exists in run, continuing"
  12. fi
  13. echo ".. check environment configs"
  14. if [ ! -f "/app/data/.env" ]; then
  15. echo "... creating environment configs (/app/data/.env not found)"
  16. # always recreate env
  17. touch /app/data/.env
  18. COOKIE_SECRET=$(pwgen -1s 32)
  19. # app domain
  20. echo "export REDASH_HOST=\"${APP_DOMAIN}\"" >> /app/data/.env
  21. # redis, database, cookie
  22. echo "export REDASH_LOG_LEVEL=\"INFO\"" >> /app/data/.env
  23. echo "export REDASH_REDIS_URL=\"redis://:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}/0\"" >> /app/data/.env
  24. echo "export REDASH_DATABASE_URL=\"postgresql://${POSTGRESQL_USERNAME}:${POSTGRESQL_PASSWORD}@${POSTGRESQL_HOST}:${POSTGRESQL_PORT}/${POSTGRESQL_DATABASE}\"" >> /app/data/.env
  25. echo "export REDASH_COOKIE_SECRET=$COOKIE_SECRET" >> /app/data/.env
  26. # main server config
  27. echo "export REDASH_MAIL_SERVER=\"${MAIL_SMTP_SERVER}\"" >> /app/data/.env
  28. echo "export REDASH_MAIL_PORT=\"${MAIL_SMTP_PORT}\"" >> /app/data/.env
  29. echo "export REDASH_MAIL_USE_TLS=false" >> /app/data/.env
  30. echo "export REDASH_MAIL_USE_SSL=false" >> /app/data/.env
  31. echo "export REDASH_MAIL_USERNAME=\"${MAIL_SMTP_USERNAME}\"" >> /app/data/.env
  32. echo "export REDASH_MAIL_PASSWORD=\"${MAIL_SMTP_PASSWORD}\"" >> /app/data/.env
  33. echo "export REDASH_MAIL_DEFAULT_SENDER=\"${MAIL_FROM}\"" >> /app/data/.env
  34. # @TODO Implement Cloudron LDAP --> https://github.com/getredash/redash/pull/1836
  35. cd /run/redash/current
  36. ln -fs /app/data/.env /run/redash/current/.env
  37. # setup redash db if required
  38. cd /run/redash/current
  39. ./bin/run ./manage.py database create_tables
  40. else
  41. echo "... re-creating environment configs (/app/data/.env !found!)"
  42. # always recreate env
  43. rm /app/data/.env && touch /app/data/.env
  44. COOKIE_SECRET=$(pwgen -1s 32)
  45. echo "export REDASH_LOG_LEVEL=\"INFO\"" >> /app/data/.env
  46. echo "export REDASH_REDIS_URL=\"redis://:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}/0\"" >> /app/data/.env
  47. echo "export REDASH_DATABASE_URL=\"postgresql://${POSTGRESQL_USERNAME}:${POSTGRESQL_PASSWORD}@${POSTGRESQL_HOST}:${POSTGRESQL_PORT}/${POSTGRESQL_DATABASE}\"" >> /app/data/.env
  48. echo "export REDASH_COOKIE_SECRET=$COOKIE_SECRET" >> /app/data/.env
  49. cd /run/redash/current
  50. ln -fs /app/data/.env /run/redash/current/.env
  51. fi
  52. cd /run/redash/current
  53. ln -fs /app/data/.env /run/redash/current/.env
  54. echo ".. finished environment configs"
  55. echo ".. spawning redash"
  56. #This mode can be used to identify the files being modified by your application - often required to debug situations where your app does not run on a readonly rootfs.
  57. #Run your app using cloudron exec and use find / -mmin -30 to find file that have been changed or created in the last 30 minutes.
  58. #You can turn off debugging mode using cloudron configure --no-debug.
  59. #/run/redash/current/bin/run gunicorn -b 0.0.0.0:5000 --name redash -w 4 --max-requests 1000 redash.wsgi:app
  60. exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Redash