Archives: April 2007

Lighttpd mod_rewrite

I've migrated my teeny-weenie Xen web/mail server to Debian/etch. It hasn't even been rebooted (it would be a shame to spoil the uptime :-) ):

$ uprecords
     #               Uptime | System                                     Boot up
->   1   198 days, 06:16:44 | Linux      Thu Oct 12 10:12:51 2006
     2    99 days, 19:25:00 | Linux 2.6.12-xenU         Sun Oct  9 03:58:58 2005

It runs Lighttpd, a small and fast little webserver, popular in the Rails world. Lighttpd with PHP-fastcgi is probably faster than apache, and uses much less RAM.

With etch, I've finally been able to get mod_rewrite to work. So my Zapiro archive has nice URLs now :-)

Lighttpd has a very nice configuration style:

    # No WWW
    $HTTP["host"] =~ "^www\.((.+\.)?rivera\.za\.net)$" {
      url.redirect = ( ".*" => "http://%1$1" )
    # Add WWW:
    $HTTP["host"] =~ "^((foobar|someclient)\.co\.za)$" {
      url.redirect = ( ".*" => "http://www.%1$0" )
    # PHP Apps:
    $HTTP["host"] =~ "^(zapiro\.rivera\.za\.net)$" {
      url.redirect = ( "^/\?/(.*)" => "http://%1/$1" )
      url.rewrite-once = ( "^/(feed)$" => "/index.php?/$1",
                           "^/([0-9]+/[0-9]+/[0-9]+)$" => "/index.php?/$1" )

It's more logical than apache, but you have to watch out for rewrite->redirect->rewrite loops. So if you change to a clean URL syntax, you can't put in rewrites from index.php?/uglurl to /uglyurl because /uglyurl rewrites back to /index.php?/uglyurl, and you get a loop :-)

Cell phone "up"grade

My old (hand-me-down) Sony Ericsson P900 has been dieing for a while. The screen was scratched to death, the stylus missing, and the keypad cracked. (The Top row of buttons didn’t work, and the rest occasionally returned the wrong number). Oh, and the phone was crashing a lot.

I don’t do spending money on cellphones (because the ones I’d like cost a fortune, and I would never buy something that I don’t want), I’ve upgraded to a “new” hand-me-down SE P910i from my brother :-). It came Orange-branded, and after I firmware-updated it, it Orange-locked, grr.

I wish there was a free way to sort this out, but I couldn’t find one, so I paid my £16, and used Total Multi Server. It doesn’t require any cables beyond the docking station, and most importantly it worked.

Overall, the P910i is much like the P900, but better. The keypad is sturdier, the phone has more RAM, more applications, and it seems to get better reception.

I “bluetoothed” all my contacts across (because if you do it the syncing route, you loose information when a contact has more than one cell phone number, etc.).

I’ve installed a few apps, that I like:

  • Opera Mini - the best web browser for a phone
  • GMail - this may come in handy (all my incoming mail gets CCed to GMail)
  • Handy Day 2004 - It makes the phone much more usable as a PIM, and I had a copy lying around.
  • MGMaps - I’ve tried using maps in opera on my P900, and it was a pain.
  • MidpSSH - Never needed it, but just in case, and anyway, it’s cool :-)
  • Mxit - I rarely use it, but it’s jabber-peering makes it occasionally nice to have.
  • quirc - Who ever wants to be stuck without IRC?

Finally I got it to synchronise with Google Calendar. The phone only does proprietary (windows) syncs or SyncML over GPRS. But Google Calendar doesn’t do SyncML. The OpenSource SyncML server is a Java monster which I wasn’t going to install on any of my servers, So I opted for ScheduleWorld as an intermediary. (don’t you love their shameless google-style website? :-) ) It works really nicely.

There is also a midp Java program for syncing to Google calendar, gcalsync, but it requires “JSR 75: PDA Optional Packages for the J2ME Platform”, which the P910i doesn’t have :-(

4 days on the Orange River

I’ve just got back from a week away, rafting down the Orange river. (Yes it was term time at UCT, I bunked classes :-) )

We went with Gravity, on the recommendation of my sister, who is an ex-guide. If you want to not be going with strangers, you need numbers, so we got a group of friends together, and my brother came down from London especially for it.

It isn’t the cheapest way to spend a week (1200kms of petrol and ZAR 2k for the trip), but it was well worth it. Gravity specialise in the Orange river Gorge, and don’t have a permanent base on the Richtersveld section of the river, which we requested to do. But they hired a local camp site, and brought the equipment down for us. Our guide, Ant, was very experienced, a good river-cook, and generally good fun. He even persuaded a friend of his, who was about to go home on leave, to come down with us, as a hard-working assistant, “on holiday”. The food they produced for us was, while made from simple ingredients, phenomenal. There was always too much, and we had a cooler-box per day for us to bring our own cold beer (and other drinks). The ice just lasted to keep everything cold for 4 days.

The scenery in the Richtersveld is spectacular. The river is a strip of incredibly fertile land, down the middle of a barren desert. You are surrounded by a mountain range of loose, rocky mountains, brimming with Quartz seams. While it feels like the middle of nowhere, there are goats, fisherman, and mining activity around, which is a pity — when I’ve been there in the past, it was far more barren. Fortunately, there was no (South African) cell phone reception, and my laptop stayed at home. :-)

I took quite a few photographs (in-between rapids, when my camera had to be packed away in a waterproof container). I didn’t expect it’s battery to last for the whole trip, but it did, which was great as I don’t have a spare :-). Taking panoramas seems to be all the rage these days, so I took quite a few, but I haven’t managed to stitch them together yet…

The river is of course the border between South Africa and Namibia, so on our way, we had to go through the border, get stamped into Namibia, then come back (without getting stamped), and go to our base camp on the South African side (while officially being in Nambia). Then, at the end of the trip, we got picked up from the Namibian side and driven back through the border (getting stamped this time). Fortunately, once you get away from the border post and onto the river, no one cares about borders any more :-)

The day is phenomenally hot (even in this calm time of the year), and so you constantly jump into the water for a swim. Or find someone who you can splash, so that you can start a water fight, and end up soaked :-)

There was quite a bit of paddling to do every day (as the water was low), but it was quite relaxing, and not very stressful. We even had a tail wind one day, and could put up kekoi sails. All in all, we covered 75km in 4 days.

The nights weren’t too cold (thank god, because I forgot my sleeping bag, and had to borrow a rather thin one from the Felix Unite camp), but clear and dew & mosquito-free. It was new moon, and the stars every night were spectacularly bright and plentiful — I wish I’d taken a star-map with me.

All in all, I highly recommend that everyone do this trip. Gravity are great, and our guide, Ant, is worth requesting :-)

etch upgrades

I’ve done etch upgrades in the past (i.e. before etch came out), and they were sometimes quite hairy. Especially the transition from ssh to openssh-server and openssh-client. I had a few broken upgrades…

Since etch has come out, I’ve been upgraded a few machines, and it’s a piece of cake. In fact the CLUG webserver and backup-server have been upgraded.

My servers tend to use custom kernels without initrds, so upgrading is quite simple. The release notes seem to cover it pretty well. There are only a couple of gotchas I’ve had:

Upgrade vim with an aptitude install vim before you do any dist-upgrading. Personally, I like to use vimdiff for configuration file changes. This means I can keep the configuration file format and comments of the latest package, and my configuration changes from when the machine was originally set up. If vim is half installed, you can’t run vimdiff

When you are done, you might need to purge hotplug:

# aptitude purge hotplug

You can also remove non-US from your sources.list.

Linux on-line Software RAID reshaping

I first read about on-line Software RAID reshaping a year ago on LWN. Today I tried it on a live system (that's too big to be backed-up first :-))

I added 2 250GB drives to my existing RAID5 array of 4, making for a 1.2TiB array. The reshape took a while...:

md0 : active raid5 sdb1[4] sda1[5] sdf1[2] sde1[3] sdd1[1] sdc1[0]
      732587712 blocks super 0.91 level 5, 64k chunk, algorithm 2 [6/6] [UUUUUU]
      [>....................]  reshape =  1.9% (4800784/244195904) finish=397.4min speed=10034K/sec

But when it was done:

$ df -h
/dev/md0              1.2T  657G  509G  57% /mnt/storage

This is one of the reasons why I love software RAID, while you have a kak load more I/O through the PCI(E) bus than you would with hardware RAID, you get the flexibility of the highest-end hardware controllers on a normal PC motherboard.

And of course, should things go pear-shaped, I don't need to find an identical controller, I just have to find a box with 6 SATA sockets.

HOWTO reshape

Lets say you have 4 SATA drives, /dev/sda to /dev/sdd, and you are adding a new one /dev/sde.

Check that everything is happy:

$ cat /proc/mdstat
md0 : active raid5 sdd1[3] sdc1[1] sdb1[2] sda1[0]
      937705728 blocks level 5, 128k chunk, algorithm 2 [4/4] [UUUU]

Partition the new drive (clone sdas partition table onto sde):

# sfdisk -d /dev/sda | sfdisk /dev/sde

Add the new drive:

# mdadm -a /dev/md0 /dev/sde1

Grow the RAID:

# mdadm --grow -n5 /dev/md0

Watch the progress:

$ watch cat /proc/mdstat

Grow the filesystem:

# resize_reiserfs /dev/md0

See the extra space:

$ df -h