+ the desired user is a member of the www-data group.
+
+1. Configure nginx with a `proxy_pass` to port 8000 (or whatever port gunicorn
+ will be running the site on) and any virtual hosting that is desired.
+ Here is an example server file to put into `/etc/nginx/sites-available/`
+
+ server {
+ listen 80;
+ server_name localhost;
+ return 301 https://$host$request_uri;
+ }
+
+ server {
+ listen 443;
+ ssl on;
+ server_name localhost;
+ client_max_body_size 20M;
+
+ location / {
+ # pass traffic through to gunicorn
+ proxy_pass http://127.0.0.1:8000;
+ # pass HTTP(S) status through to Django
+ proxy_set_header X-Forwarded-SSL $https;
+ proxy_set_header X-Forwarded-Protocol $scheme;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ # pass nginx site back to Django
+ proxy_set_header Host $http_host;
+ }
+ }
+
+1. Configure the system to start supervisor on boot. An init script for
+ supervisor is in the repo at `{project_root}/karmaworld/confs/supervisor`.
+ `update-rc.d supervisor defaults` is the Debian command to load the init
+ script into the correct directories.
+
+1. Make sure `{project_root)/var/log` and `{project_root}/var/run` exist and
+ may be written to, or else put the desired logging and run file paths into
+ `{project_root}/confs/prod/supervisord.conf`
+
+1. Create a virtualenv under `/var/www/karmaworld/venv`
+
+1. Change into the virtualenv with `. /var/www/karmaworld/venv/bin/activate`.
+ Within the virtualenv:
+
+ 1. Update the Python depenencies with `pip -i {project_root}/reqs/prod.txt`
+ * If you want debugging on a production-like system:
+ 1. run `pip -i {project_root}/reqs/vmdev.txt`
+ 1. change `{project_root}/manage.py` to point at `vmdev.py`
+ instead of `prod.py`
+ 1. ensure firefox is installed on the system (such as by
+ `sudo apt-get install firefox`)
+
+ 1. Setup the database with `python {project_root}/manage.py syncdb --migrate`
+
+ 1. Collect static resources and put them in the static hosting location with
+ `python {project_root}/manage.py collect_static`
+
+1. The database needs to be populated with schools. A list of accredited schools
+ may be found on the US Department of Education website:
+ http://ope.ed.gov/accreditation/GetDownloadFile.aspx
+
+ Alternatively, use the built-in scripts while in the virtualenv:
+
+ 1. Fetch USDE schools with
+ `python {project_root}/manage.py fetch_usde_csv ./schools.csv`
+
+ 1. Upload the schools into the database with
+ `python {project_root}/manage.py import_usde _csv ./schools.csv`
+
+ 1. Clean up redundant information with
+ `python {project_root}/manage.py sanitize_usde_schools`
+
+1. Startup `supervisor`, which will run `celery` and `gunicorn`. This may be
+ done from within the virtualenv by typing
+ `python {project_root}/manage.py start_supervisord`
+
+1. If everything went well, gunicorn should be running the website on port 8000
+ and nginx should be serving gunicorn on port 80.
+
+# Update a deployed system
+
+Once code has been updated, the running web service will need to be updated
+to stay in sync with the code.
+
+## Fabric
+
+Run the `deploy` fab command. For example:
+`fab -H 127.0.0.1 deploy`
+
+## By Hand
+
+1. pull code in from the repo with `git pull`
+1. If any Python requirements have changed, install/upgrade them:
+ `pip install -r --upgrade reqs/prod.txt`
+1. If the database has changed, update the database with:
+ `python manage.py syncdb --migrate`
+1. If any static files have changed, synchornize them with;
+ `python manage.py collectstatic`
+1. Django will probably need a restart.
+ * For a dev system, ctrl-c the running process and restart it.
+ * For a production system, there are two options.
+ * `python manage.py restart_supervisord` if far reaching changes
+ have been made (that might effect celery, beat, etc)
+ * `python manage.py restart_gunicorn` if only minor Django changes
+ have been made
+ * If you are uncertain, best bet is to restart supervisord.