mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 01:25:16 +00:00
e2e8714155
* Enable graceful shutdown of rq workers * Use `exec` in the `worker` command of the entrypoint to propagate the `TERM` signal * Allow rq processes managed by supervisor to exit without restart on expected status codes * Allow supervisorctl to contact the running supervisor * Add a `shutdown_worker` command that will send `TERM` to all running worker processes and then sleep. This allows orchestration systems to initiate a graceful shutdown before sending `SIGTERM` to supervisord * Use Heroku worker as the BaseWorker This implements a graceful shutdown on SIGTERM, which simplifies external shutdown procedures. * Fix imports based upon review * Remove supervisorctl config
129 lines
2.8 KiB
Bash
Executable File
129 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
scheduler() {
|
|
echo "Starting RQ scheduler..."
|
|
|
|
exec /app/manage.py rq scheduler
|
|
}
|
|
|
|
dev_scheduler() {
|
|
echo "Starting dev RQ scheduler..."
|
|
|
|
exec watchmedo auto-restart --directory=./redash/ --pattern=*.py --recursive -- ./manage.py rq scheduler
|
|
}
|
|
|
|
worker() {
|
|
echo "Starting RQ worker..."
|
|
|
|
export WORKERS_COUNT=${WORKERS_COUNT:-2}
|
|
export QUEUES=${QUEUES:-}
|
|
|
|
exec supervisord -c worker.conf
|
|
}
|
|
|
|
dev_worker() {
|
|
echo "Starting dev RQ worker..."
|
|
|
|
exec watchmedo auto-restart --directory=./redash/ --pattern=*.py --recursive -- ./manage.py rq worker $QUEUES
|
|
}
|
|
|
|
server() {
|
|
# Recycle gunicorn workers every n-th request. See http://docs.gunicorn.org/en/stable/settings.html#max-requests for more details.
|
|
MAX_REQUESTS=${MAX_REQUESTS:-1000}
|
|
MAX_REQUESTS_JITTER=${MAX_REQUESTS_JITTER:-100}
|
|
exec /usr/local/bin/gunicorn -b 0.0.0.0:5000 --name redash -w${REDASH_WEB_WORKERS:-4} redash.wsgi:app --max-requests $MAX_REQUESTS --max-requests-jitter $MAX_REQUESTS_JITTER
|
|
}
|
|
|
|
create_db() {
|
|
exec /app/manage.py database create_tables
|
|
}
|
|
|
|
help() {
|
|
echo "Redash Docker."
|
|
echo ""
|
|
echo "Usage:"
|
|
echo ""
|
|
|
|
echo "server -- start Redash server (with gunicorn)"
|
|
echo "worker -- start a single RQ worker"
|
|
echo "dev_worker -- start a single RQ worker with code reloading"
|
|
echo "scheduler -- start an rq-scheduler instance"
|
|
echo "dev_scheduler -- start an rq-scheduler instance with code reloading"
|
|
echo ""
|
|
echo "shell -- open shell"
|
|
echo "dev_server -- start Flask development server with debugger and auto reload"
|
|
echo "debug -- start Flask development server with remote debugger via ptvsd"
|
|
echo "create_db -- create database tables"
|
|
echo "manage -- CLI to manage redash"
|
|
echo "tests -- run tests"
|
|
}
|
|
|
|
tests() {
|
|
export REDASH_DATABASE_URL="postgresql://postgres@postgres/tests"
|
|
|
|
if [ $# -eq 0 ]; then
|
|
TEST_ARGS=tests/
|
|
else
|
|
TEST_ARGS=$@
|
|
fi
|
|
exec pytest $TEST_ARGS
|
|
}
|
|
|
|
case "$1" in
|
|
worker)
|
|
shift
|
|
worker
|
|
;;
|
|
server)
|
|
shift
|
|
server
|
|
;;
|
|
scheduler)
|
|
shift
|
|
scheduler
|
|
;;
|
|
dev_scheduler)
|
|
shift
|
|
dev_scheduler
|
|
;;
|
|
dev_worker)
|
|
shift
|
|
dev_worker
|
|
;;
|
|
celery_healthcheck)
|
|
shift
|
|
echo "DEPRECATED: Celery has been replaced with RQ and now performs healthchecks autonomously as part of the 'worker' entrypoint."
|
|
;;
|
|
dev_server)
|
|
export FLASK_DEBUG=1
|
|
exec /app/manage.py runserver --debugger --reload -h 0.0.0.0
|
|
;;
|
|
debug)
|
|
export FLASK_DEBUG=1
|
|
export REMOTE_DEBUG=1
|
|
exec /app/manage.py runserver --debugger --no-reload -h 0.0.0.0
|
|
;;
|
|
shell)
|
|
exec /app/manage.py shell
|
|
;;
|
|
create_db)
|
|
create_db
|
|
;;
|
|
manage)
|
|
shift
|
|
exec /app/manage.py $*
|
|
;;
|
|
tests)
|
|
shift
|
|
tests $@
|
|
;;
|
|
help)
|
|
shift
|
|
help
|
|
;;
|
|
*)
|
|
exec "$@"
|
|
;;
|
|
esac
|