The Third Bear

Just Right.

Trac and Gitolite: System Setup

egj trac , gitolite , sysadmin

First we install some packages:

apt-get update
apt-get install build-essential python-dev emacs git-core subversion rsync apache2 libapache2-mod-wsgi postgresql libpq-dev postfix

Next is Gitolite installation. This blog post by Phil Whelan, "Gitolite Installation Step by Step", helped me get it working; the following is just a distillation of Phil's very helpful post, which provides more contextual explanation of what's happening and some extra tips.

On your local machine, create an SSH keypair called "gitolite" and then `scp` to the server's `/tmp/` directory. Then:

adduser --system --shell /bin/bash --gecos 'git version control' --group --disabled-password --home /home/git git
chown git:git /tmp/ && mv /tmp/ ~git/
su - git
mkdir bin
cd /tmp && git clone git:// && cd
/tmp/gitolite/install -to /home/git/bin/
/home/git/bin/gitolite setup -pk /home/git/

You should now have gitolite installed and working properly. To double check, from your local machine, run:

ssh-add /path/to/ssh_keys/gitolite
cd /tmp && git clone

If this prompts you for a password, something's wrong. :-/  Running `ssh -v` is a good starting point for debugging.


I installed Trac in a virtualenv under a dedicated system user's homedir, with each Trac instance living in a subdirectory of `$HOME/sites/`.

adduser --system --shell /bin/bash --gecos 'trac project management' --group --disabled-password --home /home/trac trac
su - trac
git clone git://
mkdir bin
ln -s /home/trac/virtualenv/ ./bin/
mkdir web
./bin/ web/ve
echo "Trac" > web/requirements.txt
web/ve/bin/pip install -r web/requirements.txt
mkdir sites
echo "import sys
sys.stdout = sys.stderr

import os
os.environ['TRAC_ENV_PARENT_DIR'] = '/home/trac/sites'

import trac.web.main

application = trac.web.main.dispatch_request
" > web/

I then set up an Apache virtual host to serve Trac with mod_wsgi at like so:

a2enmod wsgi
echo "<VirtualHost *:80>

  WSGIDaemonProcess site-trac user=trac group=trac threads=5 python-path=/home/trac/web/ve/lib/python2.7/site-packages
  WSGIProcessGroup site-trac

  WSGIScriptAlias / /home/trac/web/

</VirtualHost>" > /tmp/apache.conf
mv /tmp/apache.conf /etc/apache2/sites-enabled/
service apache2 reload

If you visit ​ in a browser, it should display an "Available Projects" landing page with no projects listed.

Let's create a throwaway project (using sqlite, because it's quicker) to check that everything's working; just press enter a few times at the prompts:

su - trac
./web/ve/bin/trac-admin ./sites/test initenv
./web/ve/bin/trac-admin ./sites/test permission add anonymous TRAC_ADMIN

Now if you reload the ​ homepage in your browser, a "My Project" link should show up. Click it; Trac's homepage should appear, with no errors.

We'll keep the testing environment around for now, so that we can use it to test Git/Trac commit integration next.

Related Posts