Wiki

Clone wiki

WONKA / Ubuntu server

#Setting up a Ubuntu WONKA gunicorn, nginx and Django stack.

This assumes you have set up WONKA as outlined in this tutorial

Massive thank you to Michał Karzyński for this wonderful blogpost. The following is largely based on that.

Firstly make this file in ~/CHOC/src/WebApp/gunicornstart.bash

#!bash
#!/bin/bash
NAME="Cocoa"                                  # Name of the application
DJANGODIR=~/CHOC/src/WebApp        # Django project directory
SOCKFILE=~/CHOC/src/WebApp/run/gunicorn.sock  # we will communicte using this unix socket
USER=abradley                                       # the user to run as
GROUP=abradley                                    # the group to run as
NUM_WORKERS=5                                    # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=WebApp.wsgisettings             # which settings file should Django use
DJANGO_WSGI_MODULE=WebApp.wsgi                     # WSGI module name
TIMEOUT=60
echo "Starting $NAME as `whoami`"


cd $DJANGODIR
# Activate the environment
export RDBASE=~/RDKit/rdkit
export LD_LIBRARY_PATH=$RDBASE/lib:$LD_LIBRARY_PATH
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH

# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR

# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --log-level=debug \
  --bind=unix:$SOCKFILE\
  --timeout $TIMEOUT
You can start the server now by
bash ~/CHOC/src/WebApp/gunicornstart.bash

You will need to change the databse setting in wsgisettings.py to wherever you're .db file is.

Create a file in /home/abradley/CHOC/src/WebApp/personalsettings.py and enter the full path of the database file as below:

#!python
import os, sys
name = /home/abradley/CHOC/src/WebApp/data/WONKA_db'
user = ''
password = ''
host = ''            # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
port = ''
extra_apps = ['IOhandle',
    'Pharmacophore',
    'MMPMaker',
    'Group',
    'Viewer',
    'gunicorn',
    'OOMMPPAA',
    'jfu',
    'south',
    "WONKA",
    "PLIFS"]
You could configure a Postgres or MySQL database by altering these settings if you would prefer a different engine

Now lets start up the nginx server

#!bash
mkdir ~/CHOC/logs/
Make the nginx config file:

sudo vim /etc/nginx/sites-available/Cocoa
The full paths are required so replace /home/anthony with whatever your home directory is
#!bash
upstream Cocoa_server {
  # fail_timeout=0 means we always retry an upstream even if it failed
  # to return a good HTTP response (in case the Unicorn master nukes a
  # single worker for timing out).

  server unix:/home/abradley/CHOC/src/WebApp/run/gunicorn.sock fail_timeout=0;
}

server {

    listen   80;
    server_name localhost;

    client_max_body_size 4G;

    access_log /home/abradley/CHOC/logs/nginx-access.log;
    error_log /home/abradley/CHOC/logs/nginx-error.log;

    location /static/ {
        alias   /home/abradley/CHOC/src/WebApp/data/static/;
    }

    location /media/ {
        alias  /home/abradley/CHOC/src/WebApp/data/data/media/;
    }

    location / {
        # an HTTP header important enough to have its own Wikipedia entry:
        #   http://en.wikipedia.org/wiki/X-Forwarded-For
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # enable this if and only if you use HTTPS, this helps Rack
        # set the proper protocol for doing redirects:
        # proxy_set_header X-Forwarded-Proto https;

        # pass the Host: header from the client right along so redirects
        # can be set properly within the Rack application
        proxy_set_header Host $http_host;

        # we don't want nginx trying to do something clever with
        # redirects, we set the Host: header above already.
        proxy_redirect off;

        # set "proxy_buffering off" *only* for Rainbows! when doing
        # Comet/long-poll stuff.  It's also safe to set if you're
        # using only serving fast clients with Unicorn + nginx.
        # Otherwise you _want_ nginx to buffer responses to slow
        # clients, really.
        # proxy_buffering off;

        if (!-f $request_filename) {
            proxy_pass http://Cocoa_server;
            break;
        }
    }
}
Simlink this to sites-enabled and remove the default simlink
#!bash
sudo ln -s /etc/nginx/sites-available/Cocoa /etc/nginx/sites-enabled/Cocoa
sudo rm /etc/nginx/sites-enabled/default
Restart the server
#!bash
sudo service nginx restart
bash ~/CHOC/src/WebApp/gunicornstart.bash

Updated