Skip to content
Paweł Olejniczak edited this page Mar 5, 2014 · 10 revisions

This is work in progress, feel free to submit feedback.

Shortcut (danger zone!)

If you don't care about messing the server, try running puppet manifests. Here is how I deployed app on cheap VPS.

su
git clone --recurse-submodules https://github.com/Eyjafjallajokull/gunnery.git /var/gunnery
cd /var/gunnery/puppet
bash ./install.sh
FACTER_environment=production puppet apply manifests/base.pp --hiera_config manifests/hiera.yaml --modulepath=modules
cd /var/gunnery/gunnery
export DJANGO_SETTINGS_MODULE="gunnery.settings.production"
source /var/gunnery/virtualenv/production/bin/activate
python manage.py syncdb
python manage.py collectstatic

Installation

Gunnery may seem simple app, but it depends on few components. This document will guide you through process of installing all of them. For the sake of simplicity it's assumed that host machine is debian based, and all services are running on a single machine.

          Nginx
            |
            v
          Uwsgi
            |
            v
          Gunnery <----> Database <----> Celery
            |                              |
            +----------> Queue <-----------+

Database

Postgresql is recommended database for Django projects, although other types can be used too.

In short:

sudo apt-get install postgresql postgresql-contrib
sudo -u postgres psql postgres
\password postgres
sudo -u postgres createuser -D -A -P gunnery
sudo -u postgres createdb -O gunnery gunnery

Application

Get gunnery application, recommended path is /var/gunnery:

sudo mkdir /var/gunnery
sudo git clone [email protected]:Eyjafjallajokull/gunnery.git /var/gunnery
sudo cd /var/gunnery

Install required python packages. Under requirements folder you will find lists of packages for different environments.

pip install -r requirements/production.txt

Now adjust settings inside gunnery/settings/production.py file.

In the next step we setup database, create first user and prepare static files.

export DJANGO_SETTINGS_MODULE="gunnery.settings.production"
python manage.py syncdb
python manage.py collectstatic

Uwsgi

Uwsgi is a service that manages python processes. First lets define init.d script, I have no idea why its not part of uwsgi. Copy this file example file, and adjust variables (search for <% ... %>)

sudo cp /var/gunnery/puppet/modules/component/templates/uwsgi.erb /etc/init.d/uwsgi
sudo vim /etc/init.d/uwsgi
sudo chmod u+x /etc/init.d/uwsgi

Next setup application specific configuration:

sudo mkdir -p /etc/uwsgi/apps-enabled
sudo cp /var/gunnery/puppet/modules/component/templates/uwsgi.ini.erb /etc/uwsgi/apps-enabled/gunnery.ini
sudo vim /etc/uwsgi/apps-enabled/gunnery.ini

Try to start it and check logs for errors, validate if sock file is present.

sudo service uwsgi start

Nginx

No magic here. Again install, copy template, customize.

sudo apt-get install nginx
sudo mkdir -p /etc/uwsgi/apps-enabled
sudo cp /var/gunnery/puppet/modules/component/templates/nginx.django.conf.erb /etc/nginx/sites-enabled/gunnery
sudo vim /etc/nginx/sites-enabled/gunnery
sudo service nginx reload

By now you have working frontend. Let's get backend running.

Queue

Celery requires queue service for it's operation. Rabbitmq is recommended choice, but refer to celery documentation about using alternatives.

sudo apt-get install rabbitmq

Celery

In fact celery was already installed in one of previous steps (pip install). All we need to do is configure it.

sudo cp /var/gunnery/puppet/modules/component/files/celery.initd /etc/init.d/celeryd
sudo cp /var/gunnery/puppet/modules/component/templates/celery.default.erb /etc/default/celeryd
sudo vim /etc/default/celeryd
sudo service celeryd start
Clone this wiki locally