Page MenuHome

entrypoint.sh
No OneTemporary

File Metadata

Created
Sat, Dec 14, 9:07 AM

entrypoint.sh

#!/bin/bash
set -e
echo -n "Starting up at "
date -Iseconds
if [ ! -e /etc/nginx/ssl/dhparams.pem ]; then
# We don't generate it automatically, because it should be mounted from
# the Docker host and generated only once, rather than every time a new
# container is created.
echo "/etc/nginx/ssl/dhparams.pem missing, generate with:"
echo
echo " openssl dhparam -out dhparams.pem 4096"
echo
echo "GENERATING TEMPORARY INSECURE FILE"
openssl dhparam -out /etc/nginx/ssl/dhparams.pem 512
fi
# Start nginx first, so that it can at least serve a "we'll be right back" page.
echo "Starting nginx"
nginx
# Do this before we start Postgres so we shut that down
# even when something else doesn't want to start.
function shutdown {
echo "Shutting down"
set +e
nginx -s stop
[ -e $ELASTIC_PID ] && kill $(<$ELASTIC_PID)
pg_ctlcluster 10 main stop
}
trap shutdown EXIT
# Configure and start Postgres.
if [ ! -e $PGDATA ]; then
echo "$PGDATA does not exist, initialising database"
. /create_db.sh
else
echo "Starting postgresql"
pg_ctlcluster 10 main start
fi
mkdir -p /var/log/{apps,uwsgi,nginx,postgresql}/
chgrp django /var/log/apps
chmod g+ws /var/log/apps
chown opendata:django /var/log/apps/opendata.log
chown mydata:django /var/log/apps/mydata.log
echo "Starting ElasticSearch"
chown -R elastic:elastic /opt/elasticsearch/{data,logs}
su elastic -c "/opt/elasticsearch/bin/elasticsearch --daemonize --pidfile $ELASTIC_PID"
echo "Running migrations"
cd /var/www/mydata
pipenv run python3 manage.py migrate
cd /var/www/opendata
pipenv run python3 manage.py migrate
echo "Starting Redis"
mkdir -m 755 -p /var/run/redis/ # directory for unix-domain socket
mkdir -m 750 -p /var/log/redis/
chown redis:redis /var/run/redis/ /var/log/redis/
su redis -c 'cd /var/lib/redis/; /usr/bin/redis-server /etc/redis/redis-mydata.conf'
(sleep 2; echo -n 'Clearing Redis cache: '; echo FLUSHALL | redis-cli -s /var/run/redis/redis.sock) &
echo "Starting uWSGI"
uwsgi /etc/uwsgi/apps-enabled/mydata.ini
uwsgi /etc/uwsgi/apps-enabled/opendata.ini
echo "Waiting for stuff"
set +e
tail -f /dev/null &
KILLPID=$!
function finish {
echo "Finishing Docker image"
set -x
kill $KILLPID
}
trap finish QUIT
trap finish TERM
trap finish INT
wait
echo "Done waiting, shutting down some stuff cleanly"

Event Timeline