entrypoint.sh 3.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/bin/sh
set -e

# SYSTEM OPTIONS (set on Docker build)
RNACENTRAL_HOME=$RNACENTRAL_HOME

# External database settings
DB_HOST=${DB_HOST:-'hh-pgsql-public.ebi.ac.uk'}
DB_NAME=${DB_NAME:-'pfmegrnargs'}
DB_USER=${DB_USER:-'reader'}
DB_PORT=${DB_PORT:-'5432'}
DB_PASSWORD=${DB_PASSWORD:-'NWDMCE5xdipIjRrp'}

# RNAcentral specific settings
carlosribas's avatar
carlosribas committed
15
SECRET_KEY=${SECRET_KEY:-$(python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())')}
carlosribas's avatar
carlosribas committed
16
DJANGO_DEBUG=${DJANGO_DEBUG:-'False'}
17
EBI_SEARCH_ENDPOINT=${EBI_SEARCH_ENDPOINT:-'http://www.ebi.ac.uk/ebisearch/ws/rest/rnacentral'}
carlosribas's avatar
carlosribas committed
18 19 20
S3_HOST=${S3_HOST}
S3_KEY=${S3_KEY}
S3_SECRET=${S3_SECRET}
21

carlosribas's avatar
carlosribas committed
22
# Supervisor
carlosribas's avatar
carlosribas committed
23
SUPERVISOR_CONF_DIR=${SUPERVISOR_CONF_DIR:-"/srv/rnacentral/supervisor"}
carlosribas's avatar
carlosribas committed
24

25
# Entrypoint variable
carlosribas's avatar
carlosribas committed
26
LOGS=/srv/rnacentral/log
27 28

# Add local_settings file
29
if [ -f "${RNACENTRAL_HOME}"/rnacentral/rnacentral/local_settings.py ]
30 31 32 33
then
	echo "INFO: RNAcentral local_settings.py file already provisioned"
else
	echo "INFO: Creating RNAcentral local_settings.py file"
34
	cat <<-EOF > "${RNACENTRAL_HOME}"/rnacentral/rnacentral/local_settings.py
carlosribas's avatar
carlosribas committed
35
		import os
carlosribas's avatar
carlosribas committed
36
		from .utils import get_environment
37
		SECRET_KEY = "$SECRET_KEY"
38
		EBI_SEARCH_ENDPOINT = "$EBI_SEARCH_ENDPOINT"
39 40 41
		ENVIRONMENT = get_environment()
		INTERNAL_IPS = ('127.0.0.1', '192.168.99.1')
		COMPRESS_ENABLED = False
carlosribas's avatar
carlosribas committed
42 43 44 45 46 47
		S3_SERVER = {
        "HOST": "$S3_HOST",
        "KEY": "$S3_KEY",
        "SECRET": "$S3_SECRET",
        "BUCKET": "ebi-rnacentral",
    }
carlosribas's avatar
carlosribas committed
48 49 50 51 52 53 54 55 56 57
		CACHES = {
        "default": {
            "BACKEND": "django.core.cache.backends.memcached.MemcachedCache",
            "LOCATION": "memcached",
        },
        "sitemaps": {
            "BACKEND": "rnacentral.utils.cache.SitemapsCache",
            "LOCATION": os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'rnacentral', 'sitemaps')
        }
    }
58 59
		RQ_QUEUES = {
        "default": {
60
            "HOST": "redis",
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
            "PORT": 8051,
            "DB": 0,
            "DEFAULT_TIMEOUT": 360,
            "REMOTE_SERVER": None,
        }
    }
		DATABASES = {
        "default": {
            "ENGINE": "django.db.backends.postgresql_psycopg2",
            "NAME": "$DB_NAME",
            "USER": "$DB_USER",
            "PASSWORD": "$DB_PASSWORD",
            "HOST": "$DB_HOST",
            "PORT": "$DB_PORT",
        }
    }
	EOF
78 79
	sed -i "3 a DEBUG = ${DJANGO_DEBUG}" "${RNACENTRAL_HOME}"/rnacentral/rnacentral/local_settings.py
	chown -R rnacentral "${RNACENTRAL_HOME}"/rnacentral/rnacentral/local_settings.py
80 81
fi

carlosribas's avatar
carlosribas committed
82
# Supervisor setup
carlosribas's avatar
carlosribas committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96
if [ -f "${SUPERVISOR_CONF_DIR}"/supervisord.conf ]
then
	echo "INFO: Supervisord configuration file already provisioned"
else
	echo "INFO: Creating Supervisord configuration file"
	cat <<-EOF > "${SUPERVISOR_CONF_DIR}"/supervisord.conf
		[supervisord]
		pidfile=${SUPERVISOR_CONF_DIR}/supervisord.pid
		logfile=${LOGS}/supervisord.log
		user=rnacentral
		logfile_maxbytes=50MB
		logfile_backups=2
		loglevel=info
		nodaemon=true
carlosribas's avatar
carlosribas committed
97

carlosribas's avatar
carlosribas committed
98
		[program:rqworkers]
99 100
		command=python $RNACENTRAL_HOME/rnacentral/manage.py rqworker
		directory=$RNACENTRAL_HOME/rnacentral
carlosribas's avatar
carlosribas committed
101
		numprocs=1
carlosribas's avatar
carlosribas committed
102 103 104 105 106
		process_name=%(program_name)s_%(process_num)s
		autorestart=true
		autostart=true
		stderr_logfile=${LOGS}/rqworkers.err.log
		stdout_logfile=${LOGS}/rqworkers.out.log
carlosribas's avatar
carlosribas committed
107

carlosribas's avatar
carlosribas committed
108
		[program:rnacentral]
109
		command=gunicorn --chdir $RNACENTRAL_HOME/rnacentral --bind 0.0.0.0:8000 rnacentral.wsgi:application
carlosribas's avatar
carlosribas committed
110 111 112 113 114 115 116
		user=rnacentral
		autostart=true
		autorestart=true
		stderr_logfile=${LOGS}/rnacentral.err.log
		stdout_logfile=${LOGS}/rnacentral.out.log
		environment=HOME="$RNACENTRAL_HOME"
	EOF
carlosribas's avatar
carlosribas committed
117
	chown -R rnacentral "${SUPERVISOR_CONF_DIR}"/supervisord.conf
carlosribas's avatar
carlosribas committed
118
fi
carlosribas's avatar
carlosribas committed
119

carlosribas's avatar
carlosribas committed
120 121
# Run collectstatic
echo "INFO: Copying the static files"
122
python "${RNACENTRAL_HOME}"/rnacentral/manage.py collectstatic --noinput
carlosribas's avatar
carlosribas committed
123

124
exec "$@"