Sunday, April 11, 2010

Bash if statements

I'm constantly forgetting the bash if statement syntax, and it takes a while to find the right example on the web or to read the man page. Some examples below.

One liner to get the number of seconds since a file was modified:
if [ -f /var/lib/puppet/state/puppetdlock ] ; \
then echo $[`date +%s` - `stat -c %Y /var/lib/puppet/state/puppetdlock`] ; else echo 0 ; fi

The same if statement with line breaks:
if [ -f /var/lib/puppet/state/puppetdlock ]
then
echo $[`date +%s` - `stat -c %Y /var/lib/puppet/state/puppetdlock`]
else
echo 0
fi

Thursday, April 8, 2010

Microsoft's attempt to fix windows packaging: The Common Opensource Application Publishing Platform (CoApp)

I read about Garrett Serack's project to fix the mess that is windows packaging (or lack of packaging) with The Common Opensource Application Publishing Platform (CoApp) and was pretty surprised. It seems Garrett is a long time linux user who has somehow found himself working at Microsoft, and has come up with this project to try and fix things. His post is a pretty good description of just how bad packaging is on windows, and provides good background on how a lack of standardisation has got us into dependency hell. In his words:
Frankly it's taken an extremely long time to convince the powers-that-be at Microsoft that Linux's package management is stellar compared to Windows.

and
My intent is to completely do away with the [current Windows application] practice of everybody shipping every damn shared library.

Reading some of his responses to the slashdot comments, some interesting tidbits came out. He is planning to use WiX to chain MSI's together to handle dependencies, and Windows SxS to handle multiple versions of libraries.

Will it work? Who knows, it is a massive undertaking. I imagine some open-source community members might have to do some soul searching to figure out if they want to contribute to a project that will make windows better, and presumably make Microsoft more money.

Django formset.as_table() displays vertically only

Like other people, I want to be able to display a formset as an ordinary 'horizontal' table, i.e. where all headings are in their own row, separate from the data:
<table>
<thead>
<tr><th>column1</th><th>column2</th></tr>
</thead>
<tbody>
<tr><td>form1.value1</td><td>form1.value2</td></tr>
...
</tbody>
</table>

Whereas the django formset.as_table() method displays as below, with the heading on the same row as the data:
<table>
<tr><th>column1</th><td>form1.value1</td></tr>
<tr><th>column2</th><td>form1.value2</td></tr>
</table>


The solution is a pretty nasty gob of template code, since to fix it you need to make all the error handling and form magic explicit. Django devs: Let's have a new method or parameter to display the formset horizontal rather than vertical.

Wednesday, April 7, 2010

OpenLDAP completely broken on install under Karmic

I hate OpenLDAP. Thanks to a stupid decision by OpenLDAP packagers, the server is completely unusable after install on Ubuntu. We went from a working debconf on jaunty to a completely broken install on karmic (and it doesn't look like it will be fixed in lucid either).

An OpenLDAP install on karmic no longer creates a database, installs schemas, or creates an admin user. There are basically no good HOWTOs for this initial configuration, and all the official documentation is wrong - it says to use dpkg-reconfigure, which no longer works. A thread on the ubuntu forums is the best you will get.

All I wanted to do was move my existing (working) ldap database to another server, which should have been a 5-minute job with slapcat, slapadd.

I finally got it working using the instructions in the thread to create a database, then added the users using 'slapadd -n1' as originally intended (I never got to import the original config '-n0' successfully). There is a whole lot of black magic involved: I don't understand what installing the schemas does, and I only vaguely understand what the ldif file does. The error messages provided by openldap might as well be in another language because they are completely uninformative.

Once I had a working setup I was getting a prompt with 'I have no name!'@box. Despite there being a lot of bullshit about this being caused by permissions on ldap config files in forums, it turns out if you install 'nscd' it magically goes away. I have no idea why, but nscd also seems to be the antidote to other ldap bugs, so you might as well have it :)

It's enough to make me want to use a windows DC and likewise....

Update: according to a bug report, this doco is now up-to-date, with the same information as in the thread.

Tuesday, April 6, 2010

A quick LVM HOWTO for Ubuntu linux and SAN disk LUNs

First get your luns in order using multipath-tools.

If you have a whole bunch of LUNs presented to the same box, it can be hard to figure out which one is which. I found that multipath-tools creates devices like '/dev/disk/by-id/scsi-3600342349827399729' where the big number is the same as the WWID in the HP management console. If worst comes to worst you can present LUNs one-by-one and use the WWID to match them with what is in the HP management console.

Be aware that restarting multipath-tools didn't refresh the /dev/mapper/ list properly for me (and also threw out some segfaults, yay). I couldn't remove the kernel module because it was in use, so a reboot was the only way to ensure the /dev/mapper list was accurate.

Once you know which LUN you need to work on (in this example it is mpath0), create a LVM partition on your LUN, selecting '8e' as the partition type:
fdisk /dev/mapper/mpath0

Create your physical volume:
pvcreate /dev/mapper/mpath0-part1

At this point I noticed I had two identical devices: "/dev/mapper/mpath0p1" and "/dev/mapper/mpath0-part1". You should use "mpath0-part1" - the p1 partition disappeared for me after a reboot. Before I rebooted I tried restarting multipath-tools to see if that would remove the extra partition, but no dice (partprobe would be another thing to try...). While this partition exists, pvscan will give you an error like this (but it doesn't seem to cause any problems):
Found duplicate PV xKBwhsdfssdfkshdfkdfgdfDGiRj: using /dev/mapper/mpath0p1 not /dev/mapper/mpath0-part

Now create your volume group:
vgcreate myvgname /dev/mapper/mpath0-part1

Create your logical volume specifying size:
lvcreate -L 10G -n mylvname myvgname

OR
lvcreate -l 100%FREE -n mylvname myvgname

Slap on a filesystem:
mkfs -t ext4 /dev/myvgname/mylvname

and it is ready to be mounted. Grab the UUID for your fstab entry:
blkid /dev/myvgname/mylvname

Monday, April 5, 2010

MythTV scanning for new videos now less intuitive

In MythTV 0.22, adding new videos to the playback list is far less intuitive. You need to hit the menu key ('m') in the watch videos screen, which will bring up a menu with a 'scan for changes' option.