Any user of Version Control System? When I started as a programmer back in the 90’s it was RCS. Then moved to CVS when I joined my first start up. About 5 years ago I moved everything — work projects and personal projects — to Subversion. And these days I use Git for my personal projects. While I could pay someone (GitHub for example, or RepositoryHosting which is quite cheap for unlimited repositories), for a peace of mind I would rather host the shared central repositories myself and organise my own backups.
At the same time I would like to have a bug/enhancement tracking system to track and to prioritize my work. A wiki for documentation would be a bonus (if I ever have time to write docos). Trac fits the bill. I know there is also RedMine but I am a Python developer it’s just easier for me to write plugins for Trac.
This will (hopefully) be a step-by-step guide to install both Git and Trac 0.12 on a Ubuntu 10.04 system. I used my 6 pound/year RackVM VPS in UK to write this HOWTO. 256MB burstable memory is more than enough.
Do note that this is not a tutorial on how to use git or any other distributed version control system. See Git’s website if you wish to learn more about it.
1. Setting up a Low End Box
To get the basics running,
- Get an empty VPS, but feel free to use one that is already deployed for something else — in this case feel free to skip this method and just make sure Nginx is installed.
- Refer to the lowendscript article to set up a low end VPS with Exim4 and Nginx running.
# wget http://github.com/lowendbox/lowendscript/raw/master/setup-debian.sh ... # bash setup-debian.sh system ... # bash setup-debian.sh exim4 ... # bash setup-debian.sh nginx ...
2. Install Git and Set up Master Repository
Make sure git is installed. We are also creating a git user under /home/git
as the home of all repositories.
# apt-get install -y git-core ... # useradd -m -K UMASK=027 git
Now you have a “git” user. You could set it up with git-shell
as restricted login shell (which also needs to be added to /etc/shells
), however I found it’s too restrictive, especially when I also want to be able to copy the repositories around with scp. You will also need to decide how to authenticate it — with password or with pubkeys so you can log in to push/pull the git repositories in there.
For example I want to create copy my lowendscript repository there. I will do this on my home computer (assuming running Linux).
$ cd ~/proj/lowendscript $ git clone --bare . /tmp/lowendscript.git $ scp -r /tmp/lowendscript.git git@my-gitbox: $ git remote add origin git@my-gitbox:lowendscript.git
Replace “my-gitbox” with the hostname of your VPS. scp
would only work after you have set up authentication for user “git” (password or pubkey).
You should now be able to push/pull from the central shared repository.
3. Install Trac
Ubuntu 10.04 LTS only comes with Trac 0.11 but I really wanted to use Trac 0.12 because of better multi-repositories support. So instead of apt-get install trac
, we are going the long way and downloading and installing it manually. The Trac installation guide is a good reference, as well as Git plugin for Trac.
Let’s get some Python dependencies installed first, and then use easy_install
to install Trac and Git plugin. Note that Genshi 0.6 is required for Trac so we won’t be using the 0.5 from Ubuntu repo.
# apt-get install python python-setuptools python-pygments python-tz subversion ... # easy_install Trac ... # easy_install http://trac-hacks.org/svn/gitplugin/0.12 ...
I will now create a trac user to run the standalone instance, and initialize our first Trac project. Note that I am adding user trac into git group so it can have read access to the git repositories.
# useradd -m -K UMASK=077 -G git trac # sudo -u trac trac-admin ~trac/project initenv ...
Just put in your new project’s name (that can be changed later), and use the default for the rest. Done! You have a Trac project created, and it’s time to get the Trac standalone server up and running.
# sudo -u trac tracd -s -p 8000 --pidfile ~trac/project/tracd.pid -d ~trac/project
You should be able to connect to port 8000 on your VPS via your browser to see it up and running. However, a plain vanilla Trac installation is not very useful. We need to get authentication working first so you can administer your Trac install from its web interface. You can find more info on setting up authentication for Trac standalone server here. Need to get apache2-utils installed first so we can use htpasswd.
I’ll also create a “lowendadmin” user with password “12345”.
# apt-get install apache2-utils ... # sudo -u trac htpasswd -bc ~trac/project/htpasswd lowendadmin 12345 Adding password for user lowendadmin
We will also need to grant WebAdmin permission to the user “lowendadmin”. Now restart Trac to use the htpasswd file we have just created.
# [ -e ~trac/project/tracd.pid ] && kill `cat ~trac/project/tracd.pid` # sudo -u trac trac-admin ~trac/project permission add lowendadmin TRAC_ADMIN # sudo -u trac tracd -s -p 8000 --pidfile ~trac/project/tracd.pid -d --basic-auth="*,/home/trac/project/htpasswd,Project" ~trac/project
When you log back into Trac (port 8000 on your VPS), you should be able to see a “Login” link. Click on that to bring out the HTTP Basic Authentication dialog box that prompts for username/password. Once authenticated, you’ll be back at Trac with “Admin” link at the top navigation bar.
4. Adding Git Repository to Trac
Once you have Admin enabled on Trac, it can be all GUI work from now. First you need to enable GitPlugin for Trac.
- Click on “Admin” at top right.
- Click on “Plugins” on the left navigation menu, under “General”
- Click on “TracGit” in the middle of the page, enable “GitConnector” and Save Change
Next, you need to add your repositories using the Admin interface.
- Click on “Repositories” on the left navigation menu, under “Version Control”
- In my lowendscript example, I put
- Name=lowendscript
- Type=git
- Directory=/home/git/lowendscript.git
- Click on Add! And you should now be able to browse your source under “Browse”
That’s pretty much it for Trac. It would be a good idea to put that long tracd
command in /etc/rc.local so it starts everytime you reboot the VPS.
5. SSL + Proxy via Nginx
Now, you do want your latest source code browser + bug tracking system behind SSL, right? I found the easiest way to do it is by putting a Nginx proxy in front. Since we already have Nginx installed in step 1, we just need to
- Get a SSL certificate.
- Add Nginx configuration to do the proxy.
For “free” SSL certificates, I use StartSSL, which works for most modern browsers. However to make it simple, I am going to use self-signed certificate in this tutorial.
# openssl genrsa -out /etc/nginx/ssl.key 1024 Generating RSA private key, 1024 bit long modulus ..............................................++++++ ........................................++++++ e is 65537 (0x10001) # openssl req -new -key /etc/nginx/ssl.key -out /tmp/ssl.csr ... Country Name (2 letter code) [US]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (eg, YOUR name) []:my-gitbox Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: # openssl x509 -req -days 365 -in /tmp/ssl.csr -signkey /etc/nginx/ssl.key -out /etc/nginx/ssl.crt Signature ok subject=/C=US/ST=Some-State/O=Internet Widgits Pty Ltd/CN=my-gitbox Getting Private key # rm -f /tmp/ssl.csr
Done. Your self signed SSL key and certificate are now installed. Time to get Nginx to use it. Save the following file to /etc/nginx/sites-enabled/my-gitbox.conf
:
server { server_name _; listen 443; ssl on; ssl_certificate /etc/nginx/ssl.crt; ssl_certificate_key /etc/nginx/ssl.key; location / { proxy_pass http://localhost:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } location /trac/chrome/site { rewrite /trac/chrome/site/(.*) /htdocs/$1 break; root /home/trac/project; } }
Restart Nginx, and now browse to your VPS’s HTTPS port. You’ll see Trac in its SSL glory (well, after bypass the browser’s security check at least).
Trac also happens to have pretty good Wiki engine, and it has heaps of plugins for customization. With a bit of optimization (most notably reducing the stack size for multi-threaded tracd), you should be able to run the entire stack with less than 80MB on an OpenVZ VPS (and much less on a Xen).
Now with code repository, bug tracking system and documentation wiki ready, I better get back to do more coding :)
Related Posts:
- 5 Reasons Why You Want a Low End Box - May 26, 2021
- Dead Pool January 2012 - February 2, 2012
- exit(0); - January 19, 2012
Wow! very helpful post, I was also thinking this morning to setup Trac on my RackVM (but its a XEN). I use Subversion mostly, how do you compare Subversion with Git? Wanted to hear it from a developer who actually uses it. I on the other hand, only use subversion, never used Git.
Subversion is a strictly centralized repository, and I think it has already passed its hey days. Comparing to git,
– It is a lot slower
– Not distributed so every diff, every branch, every commit etc has to go to server
– .svn/ inside every directory sucks.
– Subversion over HTTP works only Apache + WebDAV = very bloated
– Did I mention *slow*?!
On the other hand you can check out just a sub-tree of Subversion repository, or use svn:externals to connect two different repos. Very useful to put code from all over the place together. No equivalent in Git.
I agree with all points, but the .svn in every directory is history now, and this alone improved speed considerably. But I absolutely agree, git is way superior.
Wouldn’t mind seeing some memory utilisation stats for this, that way we can all work on ‘trimming’ where possible ;).
Nice post. Does this setup allow you to pull/push to the git repository via http with the same credentials that you have with trac?
@FZ — no. Git *can* support HTTP based repository for pulling but not for pushing. SSH-based is probably the best. The set up is probably only good for personal projects or a very small team.
@Hughesey — After a few page views this is my process list:
Note that the tracd process (pid=32275) has much bigger VSZ than RSS, i.e. it allocates a lot more memory than actually uses them. It seems to be common amongst scripting environments (Python). Also it’s a multi-threaded application so each thread would allocate its own stack.
LEA is so damn sexy :-)
I have been thinking in RedMine, unfortunately it runs on Ruby, so it asks for a lot of memory. Have any of you try Indefero, its based on php (http://www.indefero.net/open-source/). What are your opinions about it. (No advertising intended).
Indefero missing Milestone feature of Trac
Hmm interesting project. I will give that a try. With PHP the configuration would be even easier. Thanks.
glad i found this, i seam to have missed it when you first posted it.
just got my repository set up but i have to reference it by its full path when i connect to it any ideas whats causing it (i.e. /home/git/repo rather then just repo)
Trac usually needs to know the full path of the repository before it can connect to it and read the data out. And I think it applies to Subversion under Trac as well.
This is one very useful guide, thanks!
just gave this a try and ran into the following error:
presumably this is because I did this as root which is causing some permissions trouble? how do you suggest avoiding this?
Which command produces the above error?
It was at the step:
# sudo -u trac trac-admin ~trac/project initenv
How about using
# sudo -H -u trac trac-admin ~trac/project initenv
Or replace all the
sudo
withsudo -H
(as I just realised that I have my `sudo` aliased to `sudo -H`).@LEA The -H switch did the trick.
I think that did it?
Another couple things though:
easy_install http://trac-hacks.org/svn/gitplugin/0.12
didn’t work for me following these directions until after I did a
easy_install -U setuptools
In addition, I ran into another error:
sudo -H -u trac htpasswd -bc ~trac/project/htpasswd adminuser adminpassword
htpasswd: cannot create file /home/trac/project/htpasswd
Whooops that other error is a mistake because I made a typo earlier. The instructions are right, and I have fat fingers.
LEA, before I follow your guide (I’m a SVN user), do you need one tracd process per repository or is it one tracd process covering multiple repos? I manage many small projects so being able to create and remove repositories quickly would be very useful.
Plus, is there a way to add repositories purely from Trac alone, or is the creation via command line necessary?
For trac 0.12+ one single tracd can cover multiple repositories. You can go into the admin area to add new repositories (provided the tracd instance can read the directory). You can even add multiple of svn, git or hg directories, provided appropriate plugins are installed.
When you get into Trac,
1) Click on Admin (top navigation bar)
2) Click on Version Control/Repositories on the left navigation bar
3) You can then add new repositories there by giving them name, type (git, svn) and directory
Silly question but what do you use for a windows client for git? I know about tortoisesvn for svn and I see that it has a plugin for git. Does that work ok?
I use msysgit, but I guess you mean a GUI (though gitk and “git gui” both work on msysgit). TortoiseGit certainly seems to be fairly recommended. I’m not sure if it’s a plugin for tortoisesvn, I get the impression it’s more of a standalone “port” to git.
Oh and I get an error with the trac-hacks line:
That command works fine for me, maybe your easy_install (which is part of python setuptools) is out of date? The page mentions bugfixes in 0.6c9 to detect svn urls better. You can update setuptools with ‘easy_install -U setuptools’, but that might not work / might cause problems with your distribution’s package manager (unless you’re using a virtualenv).
You could also try installing pip, which is a popular (and really nice) alternative to the easy_install script that comes with setuptools. pip should be able to identify that url as an svn repo better, and you can use ‘pip install svn+http://trac-hacks.org/svn/gitplugin/0.12’ to be sure it does. Pip is probably available in a package for your distribution (mine calls the package python-pip) for a system-wide install.
I think pip is also installed by default into python virtualenvs, if you’re using one. If you aren’t, you might want to consider it. They keep all your python packages separate and let you have a set of them installed ‘locally’ for just a specific package (like Trac), and then update them without affecting any of the other versions of the modules for other packages. They’ve kind of become the recommended way to work on or install anything python these days, though I haven’t ever checked if Trac works in one.
Yes these days I have switched to python-virtualenv + pip. Here’s my current setup:
Thanks. I gave up after a couple of hours of beating my head against the table and went with a free service for the time being.
You should also know about Fossil, http://fossil-scm.org .
Kind of like git/trac/wiki all rolled into one, written in C and uses sqlite, so more suited for LEB hosting. It has shortcomings compared to git, but some people really like it.
Will it run on Nginx?
Never mind. Just looked it over.
Thanks. Will take a look. Trac was used for its wealth of plugins and ease of development (easier to hack in Python than in C), but you are right that a simple C based backend would probably use less memory.
I installed it and have been playing with it and looking at the code. It was very easy to get running, it is responsive serving pages from my AlienVPS 192mb OpenVZ, and it has its own embedded httpd (or you can run it as a cgi under nginx or whatever). The process footprint when running a clone of the fossil-scm.org site (they let you do that with a “fossil clone” operation) is about 1MB, not bad at all. The code looks pretty hackable since most of the heavy lifting is done by sqllite and so the C code is mostly a wrapper around a bunch of SQL calls. There are some things I’d have done differently but overall it’s a very clever program.
@LowEndAdmin you should add this to the howto.
nginx as a ssl proxy is mostly working, but sometimes is trac going back to http. for example:
https://my-gitbox/prefs
if I click on “save changes” the page is sending request over http and it stays there. I have to manually correct it again.
to solve that change following settings in /home/trac/projects/conf/trac.ini
base_url = https://my-gitbox
use_base_url_for_redirect = true
I have learned lot of things from it on the topic of blogging. thanks.BDWEBIT.COM