You know, when you start coding you always (don’t you?) end up looking for a safe-and-easy way to track code changes, code commit log and manage the “back-to-the-past” feature (for example when you start coding a new feature and end up in a completely not working app)
Sometimes I used free services for repositories (like GitHub, BitBucket, SourceForge) to store my open-source projects (BitBucket plans allow you also to setup a single private repository with 1Gb of free space).
Now I’m setting up something like that for my Lab, allowing students to work from home and share their code with co-workers and professors. I’m happy with Mercurial, so I’ve installed on our web-server (latest Ubuntu Server) all the stuff for serving mercurial repositories with SSH authentication.
Following Ekkes tutorial let’s setup the mercurial-server in Ubuntu, we don’t have any X server, so everything is done in a shell:
$ sudo apt-get install mercurial-server
All our repo will be stored in “/etc/lib/mercurial-server/repos” and a special repository called “hgadmin” have been created to manage users and permissions, read on Mercurial-Server docbook for further details. In short: adding myself to “root” group and refreshing users permissions in mercurial-server:
$ sudo mkdir /etc/mercurial-server/keys/root/thepanz $ sudo cp my_ssh_key.pub /etc/mercurial-server/keys/root/thepanz $ sudo -u hg /usr/share/mercurial-server/refresh-auth
For repository serving I’ll use Apache and mod_wsgi, I’ve adapted what presented on mercurial-server blog post and what I’ve found on Mercurial documentation on modwsgi. I’m going to install the latest mod_wsgi release, the 3.3 version, instead of the (1year old) 2.8 that’s packaged into Ubuntu 10.4, I’m going to use the 3.3 release provided from Debian Packages for wsgi mod. Please follow the download page to obtain the correct download link. In the following we’ll first install the Ubuntu mod_wsgi package and then upgrade with the newest one.
$ sudo apt-get install libapache2-mod-wsgi $ wget WSGI_DOWNLOAD_LINK $ sudo dpkg -i libapache2-mod-wsgi_3.3-1_i386.deb
Apache will be set to serve the repository using a VirtualHost listening to the 8080 port, here is the “/etc/apache2/sites-available/hgwebsite” file:
<VirtualHost *:8080> ServerAdmin webmaster@localhost # ServerName hg.exampleserver.netDocumentRoot /var/www/sites/hg LogLevel warn ErrorLog /var/log/apache2/error-sites-hg.log CustomLog /var/log/apache2/access-sites-hg.log combinedWSGIScriptAliasMatch ^(.*)$ /var/www/sites/hg/cgi-bin/hgweb.wsgi$1<Directory /var/www/sites/hg> DirectoryIndex index.html Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from all </Directory><Directory /var/www/sites/hg/cgi-bin> Options ExecCGI FollowSymlinks AddHandler wsgi-script .wsgi AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost>
As attachment you’ll find the scripts for the server setup:
- hgweb.wsgi to be placed in “/var/www/sites/hg/cgi-bin/” with the Python script for repository serving
- hgweb.conf to be placed in “/var/lib/mercurial-server/” containing the repositories configuration