Skip to content

Instantly share code, notes, and snippets.

@n37r06u3
Forked from Tatsh/README.md
Created July 24, 2014 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n37r06u3/e1d455808ca856d3c9be to your computer and use it in GitHub Desktop.
Save n37r06u3/e1d455808ca856d3c9be to your computer and use it in GitHub Desktop.

Install virtualenv nginx, Supervisor, PostgreSQL, and uwsgi

I recommend the latest versions for Supervisor and uwsgi. I am using nginx 1.4.7 as that is the latest available on Gentoo (unmasked for ~amd64).

Gentoo

Unmask app-admin/supervisor and www-servers/uwsgi. In the case of x86-64:

app-admin/supervisor ~amd64
www-servers/uwsgi ~amd64

USE flags

www-servers/uwsgi python

NGINX_MODULES

NGINX_MODULES="uwsgi"

I recommend many more such as gzip, gzip_static, etc.

Installation

emerge -av uwsgi nginx supervisor virtualenv dev-db/postgresql-server

Set up a virtualenv for Bloodhound

cd # at $HOME
virtualenv -p python2.7 bloodhound

Clone Bloodhound

Cloning latest stable here:

cd bloodhound
git clone -b 0.7 git://git.apache.org/bloodhound.git app

Install dependencies

cd app/installer
pip install -r requirements-dev.txt
pip install -r pgrequirements.txt

Set up PostgreSQL for use with Bloodhound

Follow steps from Portage to install and enable PostgreSQL server.

You can use createdb and createuser commands but I kind of prefer using psql directly:

CREATE USER bloodhound WITH PASSWORD 'somepass';
CREATE DATABASE bloodhound;
GRANT ALL PRIVILEGES ON DATABASE bloodhound TO bloodhound;

Install Bloodhound

Enter the virtualenv, get into the correct directory and install it:

cd ~/bloodhound
source bin/activate

cd app/installer
mkdir ~/bloodhound-envs
python bloodhound_setup.py \
    -d postgres \
    --database-name=bloodhound \
    -u bloodhound \
    -p somepass \
    --admin-user=admin \
    --admin-password='your_admin_pass' \
    --environments_directory=~/bloodhound-envs

Deploy the site

Still in the virtualenv in this step:

cd ~/bloodhound
trac-admin ~/bloodhound-envs/main deploy ~/bloodhound-envs/main/site

Create the Python script required for uWSGI

cd ~/bloodhound-envs/main/site/cgi-bin
cp trac.wsgi bh_wsgi.py

Get out the virtualenv since it's not longer necessary:

deactivate

Supervisor configuration

Replace nginx with the user nginx runs as. This should not be root.

Replace /home/me/ with your real $HOME.

Adjust options as you like. Note that --http-socket is very important to use (and not --socket).

[program:bloodhound]
killasgroup = true
command = uwsgi
          --plugin python27
          --enable-threads
          --processes 2
          --http-socket /var/run/bloodhound.sock
          --chown-socket nginx:nginx
          --chmod=770
          --chdir /home/me/bloodhound-envs/main/site/cgi-bin
          --virtualenv /home/me/bloodhound
          --module=bh_wsgi:application
user = nginx

Start supervisord as a user with proper privileges (can be root). Gentoo has /etc/init.d/supervisord which reads /etc/supervisord.conf. My file has this (note how you can include files):

[unix_http_server]
file=/var/run/supervisor.sock

[supervisord]
; logfile_backups=1

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock

[include]
files = /etc/supervisor.d/*.conf

nginx configuration

upstream bloodhound_uwsgi {
    server unix:/var/run/bloodhound.sock;
}

server {
#    server_name localhost;

    root /home/me/bloodhound-envs/main/site/cgi-bin;

    
    access_log /var/log/nginx/bh.access_log;
    error_log /var/log/nginx/bh.error_log info;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location @proxy {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_pass http://bloodhound_uwsgi;
    }

    location /chrome {
        alias /home/me/bloodhound-envs/main/site/htdocs;
    }

    location / {
        try_files $uri @proxy;
    }
}

Put this in a file nginx will load.

Restart nginx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment