init-phylodb.sh 3.74 KB
Newer Older
1
#!/usr/bin/env bash
2
set -e
3

Bruno Bzeznik's avatar
Bruno Bzeznik committed
4 5
LIB_DIR=/var/lib
PHYLODB_DIR=$LIB_DIR/phyloalps/phylodb
6
PHYLODUMP_DIR=$LIB_DIR/phyloalps/phylodump
Bruno Bzeznik's avatar
Bruno Bzeznik committed
7

8
# Config
Bruno Bzeznik's avatar
Bruno Bzeznik committed
9 10
echo 'GEOS_LIBRARY_PATH = "/run/current-system/sw/lib/libgeos_c.so"' >> $PHYLODB_DIR/phylodb/settings.py
echo 'GDAL_LIBRARY_PATH = "/run/current-system/sw/lib/libgdal.so"' >> $PHYLODB_DIR/phylodb/settings.py
11

12 13 14
# Disable CSRF cookie as we will use non-secure http
perl -pi -e "s/CSRF_COOKIE_SECURE.*=.*/CSRF_COOKIE_SECURE = False/" $PHYLODB_DIR/phylodb/settings.py

15 16
# For the fake authentication to work
perl -pi -e "s/django.contrib.auth.middleware.AuthenticationMiddleware',$/django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.auth.middleware.RemoteUserMiddleware',/" $PHYLODB_DIR/phylodb/settings.py
17
#echo "AUTHENTICATION_BACKENDS = [ 'django.contrib.auth.backends.RemoteUserBackend' ]" >> $PHYLODB_DIR/phylodb/settings.py
18

19
# Django install
Bruno Bzeznik's avatar
Bruno Bzeznik committed
20
cd $LIB_DIR/django
21 22 23 24
if [ \! -d phylodbenv ]
then
  virtualenv -p python3 phylodbenv
fi
25 26 27 28 29 30
source phylodbenv/bin/activate
pip install django
pip install ply
pip install sparqlwrapper
pip install django-debug-toolbar
pip install django-widget-tweaks
31
pip install django-role-permissions
32
pip install crc64iso
33
pip install -I gunicorn
34

35 36 37 38
# Create the postgis extension into DBs (must be superuser)
sudo -u postgres psql -d editor_db -c "CREATE EXTENSION IF NOT EXISTS postgis"
sudo -u postgres psql -d browser_db -c "CREATE EXTENSION IF NOT EXISTS postgis"

39
# Create the databases schema
Bruno Bzeznik's avatar
Bruno Bzeznik committed
40
cd $PHYLODB_DIR
41
echo "Make migrations..."
42
python3 manage.py makemigrations
43
echo "Migrate..."
44
python3 manage.py migrate
45
echo "Migrate browser..."
46
python3 manage.py migrate --database=browser_db
Bruno Bzeznik's avatar
Bruno Bzeznik committed
47

48 49 50 51 52
# Database initial data
if [ \! -f $PHYLODB_DIR/initdb.done ]
then
  # Init the superuser
  echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', 'gridmaster@univ-grenoble-alpes.fr', 'phylodev')" | python3 manage.py shell
Bruno Bzeznik's avatar
Bruno Bzeznik committed
53

54
  # Load data
Bruno Bzeznik's avatar
Bruno Bzeznik committed
55
  if [ -f $PHYLODUMP_DIR/editor_db.json ]
56 57 58
  then
    ## Loading from a dump
    echo "Dump found, loading it..."
Bruno Bzeznik's avatar
Bruno Bzeznik committed
59 60
    python3 manage.py loaddata $PHYLODUMP_DIR/editor_db.json
    python3 manage.py loaddata --database=browser_db $PHYLODUMP_DIR/browser_db.json
61 62 63 64 65 66
  else
    ## Direct loading
    # Load sample data
    latest_sample=`ls samples/*[0-9].csv|sort -n|tail -1`
    sudo -u phyloalps python3 install/load_sampling_data.py $latest_sample browser_db phylobrowser
    sudo -u phyloalps python3 install/load_sampling_data.py $latest_sample editor_db phyloeditor
67

68 69 70
    # Reverse geocode the samples GPS coordinates
    #sudo -u phyloalps python3 install/reverse_geocode.py browser_db phylobrowser
    #sudo -u phyloalps python3 install/reverse_geocode.py editor_db phyloeditor
71

72 73 74 75 76 77
    # Load the genomic data
    #sudo -u phyloalps python3 install/load_genomic_data.py browser_db phylobrowser
    #sudo -u phyloalps python3 install/load_genomic_data.py editor_db phyloeditor
  fi
  touch $PHYLODB_DIR/initdb.done
fi
78

Bruno Bzeznik's avatar
Bruno Bzeznik committed
79
# Download the project dependencies
80 81 82 83 84
if [ \! -d phylodb/static/deps/bulma* ]
then
  cd phylodb/static/deps
  source deps.sh
fi
Bruno Bzeznik's avatar
Bruno Bzeznik committed
85 86 87

# Generate CSS files from SASS files
cd $PHYLODB_DIR
88 89 90 91
if [ \! -f phylobrowser/static/css/browser.css ]
then
  sass phylobrowser/static/sass/browser.sass phylobrowser/static/css/browser.css
  sass phyloeditor/static/sass/editor.sass phyloeditor/static/css/editor.css
92
  #sass phylohome/static/sass/home.sass phylohome/static/css/home.css
93
fi
94 95

# Copy static files and grant permissions to httpd
96 97 98 99 100 101
if [ \! -f $PHYLODB_DIR/static/css/home.css ]
then
  python3 manage.py collectstatic
  chown -R wwwrun:wwwrun $PHYLODB_DIR/static
  chmod -R 775 $PHYLODB_DIR/static
fi
102 103

# Start Gunicon WSGI server on port 8888
104
ps awux |grep gunicorn|grep -v grep|awk '{print "kill " $2}'|bash
Bruno Bzeznik's avatar
Bruno Bzeznik committed
105
gunicorn -D -e REMOTE_USER=admin -b :8888 phylodb.wsgi