Using update-alternatives with Subversion and Apache

3 September, 2007

One of the complications I have had with Apache and Subversion is working out the best way of switching between branches and making them visible in Apache. At first, I was checking out a branch, deleting and replacing it in the same location so that Apache could pick up the branch I wanted. This was really slow and could be problematic if some of a directory was not committed for whatever reason.

My original solution to this was to maintain virtual hosts for every branch, using a separate port for each one. However, this meant that I then had to keep an index of which branch was on which port, and updating all of this each time I created/checked out a branch was a big overhead.

I have now found a neat solution using the Debian/Ubuntu program update-alternatives. This program is very easy to configure, and scales well for what I am trying to do. It also allows me to put all branches for a website project on a single port. These instructions assume you already have a working Subversion repository and have a basic understanding of how to use Subversion and Apache in Debian/Ubuntu:

1. Create a Subversion workspace for your projects, if you do not already have one. NOT “/var/www”, we will be using that for something else. Use something like “/home/myself/workspace”.

2. Check-out your trunk/branches in this workspace directory, try to keep each project contained in a sub-directory for clarity:

$ mkdir ~/workspace/myproject; cd ~/workspace/myproject
$ svn co /path/to/repo/trunk
$ svn co /path/to/repo/branches/testing
$ svn co /path/to/repo/branches/1.x-release

2. You should now have a project directory containing the project trunk, and some of your branches:

~
| -workspace
|- myproject
| – trunk
| – testing
| – 1.x-release

3. Install each project branch into update alternatives, using “/var/www” as the target for the alias. Note the numbers at the end, they represent the priority of each entry (how far up the list they are); incrementing them by 10 leaves you space to include entries further up the list more easily:

$ sudo update-alternatives --install /var/www/myproject myproject /home/myself/workspace/myproject/trunk 10
$ sudo update-alternatives --install /var/www/myproject myproject /home/myself/workspace/myproject/testing 20
$ sudo update-alternatives --install /var/www/myproject myproject /home/myself/workspace/myproject/1.x-release 30
$ sudo update-alternatives --config myproject

There are 2 alternatives which provide `myproject’.

Selection Alternative
———————————————–
* 1 /home/myself/workspace/myproject/trunk
+ 2 /home/myself/workspace/myproject/testing
+ 3 /home/myself/workspace/myproject/1.x-release

Press enter to keep the default[*], or type selection number:

— PRESS ENTER AT THIS POINT FOR NOW —

4. Hopefully you should be starting to see the advantages of this approach. At any time, you can type “sudo update-alternatives –config myproject” and you will be able to select which project branch will be provided to Apache.

5. Configure Apache to look at /var/www/myproject. That’s it.

When you want to add a new branch, you need to check it out as described above, and use the “update-alternatives –install” command to include it in the list.


Extending Nautilus

9 March, 2007

I was getting tired of having to switch to command-line every time I was using the Nautilus file manager and wanted to do something that required superuser permissions. It was becoming a real limitation for me, but instead of just switching to another file manager (which usually means less seamless integration with the desktop environment) I looked into how I could extend Nautilus to do what I wanted it to do.

I came across the site http://g-scripts.sourceforge.net, which provides scripts that Nautilus can offer in it’s right-click menu. This is an amazing feature that really hasn’t been talked about nearly enough. You can essentially download or make a shell script that performs any actions on the directory that Nautilus has open, or files or directories that you have selected. You can get Nautilus to do anything from mounting an ISO, to changing the file permissions of a batch of files in a directory at once.

The script that helped me was http://g-scripts.sourceforge.net/nautilus-scripts/ Execute/Misc/root-nautilus-here. This script allowed me to right-click inside a directory window, and select an option I called “Open Root Window”, this requested my password, and opened a new Nautilus window in my current directory with superuser privileges. Exactly what I needed.

To add a script to Nautilus, you need to copy the script and paste it into a file inside the /home/[yourname]/.gnome2/nautilus-scripts/ directory. The name you give the file will become the name in the right-click menu, so make it a readable one. You can also put the scripts into sub-directories, which is useful if you end up with a lot of them. Once you have done that, you need to make it executable for your user. This could be done using the Right-click->Properties->Permissions in Nautilus, or via the command-line (chmod 700 ~/.gnome2/nautilus-scripts/[scriptname]).

That should be it! Right-click on a file and you should see your script appear in the “Scripts” sub-menu that appears.

If you decide to make any scripts, look to the G-Scripts site to help you get started. Often you can just tweak the scripts offered by the site to do what you want. Remember the script will be invisible, so use ” zenity –info –text=”debug text” ” commands throughout your script to debug it until everything works properly.


God, not another one!

27 February, 2007

Here’s my new blog, hopefully I’ll start putting some interesting stuff in it soon.

My attempts at installing Xen on Ubuntu have been fruitless so far. Hopefully I will hear from the Ubuntu Xen team soon to clear up the issues I’m having with missing files in the kernel headers, but until then I’ll stick with the safer VMWare server. Been taking a look at KVM (a kernel-level virtualisation module that has been signed off recently by Linus), it looks very new and theres not a whole lot of documentation behind it yet, but sounds very promising.

I decided to give SymphonyOS another try today, a bit of a disappointment as far as I’m concerned, I was expecting it to have got much further since the last time I tried it out. Not sure if I’m just not giving it enough of a chance. I’m thinking if I get chance I might attempt to try out a new distro each week and give it a review here, but maybe I’m jumping ahead of myself here ;)

Finally, here are some  screenshots of my new desktop! I’ve recently changed to a dark theme, hopefully it will help me focus in the later hours ;)

Desktop screenshot 1   Desktop screenshot 2   Desktop screenshot 3