2017-03-03 06:37:46 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2018-03-25 08:25:33 +00:00
|
|
|
# Check that a .ctfd_secret_key file or SECRET_KEY envvar is set
|
|
|
|
if [ ! -f .ctfd_secret_key ] && [ -z "$SECRET_KEY" ]; then
|
|
|
|
if [ $WORKERS -gt 1 ]; then
|
|
|
|
echo "[ ERROR ] You are configured to use more than 1 worker."
|
|
|
|
echo "[ ERROR ] To do this, you must define the SECRET_KEY environment variable or create a .ctfd_secret_key file."
|
|
|
|
echo "[ ERROR ] Exiting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check that the database is available
|
2017-07-13 06:43:17 +00:00
|
|
|
if [ -n "$DATABASE_URL" ]
|
|
|
|
then
|
2018-03-25 08:25:33 +00:00
|
|
|
database=`echo $DATABASE_URL | awk -F[@//] '{print $4}'`
|
|
|
|
echo "Waiting for $database to be ready"
|
|
|
|
while ! mysqladmin ping -h $database --silent; do
|
2017-07-13 06:43:17 +00:00
|
|
|
# Show some progress
|
|
|
|
echo -n '.';
|
|
|
|
sleep 1;
|
|
|
|
done
|
2018-03-25 08:25:33 +00:00
|
|
|
echo "$database is ready"
|
2017-07-13 06:43:17 +00:00
|
|
|
# Give it another second.
|
2017-03-03 06:37:46 +00:00
|
|
|
sleep 1;
|
2017-07-13 06:43:17 +00:00
|
|
|
fi
|
2017-03-03 06:37:46 +00:00
|
|
|
|
2018-06-18 01:51:34 +00:00
|
|
|
# Initialize database
|
|
|
|
python manage.py db upgrade
|
|
|
|
|
2018-03-27 16:20:58 +00:00
|
|
|
if [ -z "$WORKERS" ]; then
|
|
|
|
WORKERS=1
|
|
|
|
fi
|
|
|
|
|
2018-03-25 08:25:33 +00:00
|
|
|
# Start CTFd
|
2017-03-03 06:37:46 +00:00
|
|
|
echo "Starting CTFd"
|
2018-02-11 08:52:21 +00:00
|
|
|
gunicorn 'CTFd:create_app()' \
|
|
|
|
--bind '0.0.0.0:8000' \
|
2018-03-25 08:25:33 +00:00
|
|
|
--workers $WORKERS \
|
2018-02-11 08:52:21 +00:00
|
|
|
--worker-class 'gevent' \
|
|
|
|
--access-logfile "${LOG_FOLDER:-/opt/CTFd/CTFd/logs}/access.log" \
|
|
|
|
--error-logfile "${LOG_FOLDER:-/opt/CTFd/CTFd/logs}/error.log"
|