Ash Berlin

Nesting LVM for resizeable VMs

Posted on Feb 6

As part of my role wearing the DevOps hat at DigiResults I'm in charge of setting up new machines; since I'm terminally lazy I clearly want to automate this. My first attempt used the ubuntu-vm-builder (which is a ubuntu-provided wrapper around the more generic vmbuilder script and was good enough for the first version but not without its drawbacks - namely I got bitten by making the VM disk too small.

vmbuilder will happily write to a 'raw' partition, which in my case was a LVM logical volume. The easiest way to show what I mean is by utilising my stunning ASCII-art skills. Running (not the complete command):

ubuntu-vm-builder kvm --raw /dev/mapper/vms-my_vm --hostname=my_vm

produces as disk layout the looks something like this (the PV and VGs aren't shown as they just complicate matters

--- LVM on Host -------------------
| /dev/mapper/vms/my_vm (LV)      | 
|                                 | 
|    ----- VM ------------------- | 
|    | /dev/sda*                | | 
|    |                          | | 
|    |                          | | 
|    |                          | | 
|    |                          | | 
|    ---------------------------- | 

Read the rest »

Colorful Ubuntu init.d scripts

Posted on Aug 24

Writing init.d scripts is fun. So much fun that its really easy to fall down rabbit holes >_>.

Looking in /lib/lsb/init-functions at the various log functions available I noticed that the status reports should be in colour - after all I'm using a terminal that is reporting as xterm-color. It turns out that the log_use_fancy_output function doesn't care about that variable (so long as TERM isn't reported as "dumb") but instead looks at tput and various capabilities from the terminfo database, and more specifically hpa which sets the horizontal position to an absolute value.

And horror of horrors its missing from the standard terminfo database. If this prints something for you then you can stop reading now - HPA is working on your terminal.

$ tput hpa 20 && echo a

Luckily its easy enough to add by running this command:

(infocmp; printf '\thpa=\\E[%sG,\n' %i%p1%d) > tmp-$$.tic && \
  tic -s tmp-$$.tic && rm tmp-$$.tic

What this does is dumps the current terminfo, adds the capability for moving the cursor horizontally to an absolute position, and then compiles the entry descriptions to a format usable by ncurses and tput. (I used printf since the echo binary on OSX doesn't support the -e flag to escape input.)

(If you want to do this system wide, and a -o/etc/terminfo option to the tic command.)

Now lets test it:

$ echo -n b && tput hpa 20 && echo a
b                   a

With any luck the init.d scripts on Ubuntu will now print [ OK ] in colour on the right hand side of your terminal.

Host header with nginx proxy_pass

Posted on Mar 31

I recently moved this blog and evilstreak's to a VM on my stonking new server from Hetzner: 24GB. Woo!

But I made a booboo in switching from lighttpd to nginx. It turns out that the proxy_pass directive for nginx overwrites the Host header from the request with the proxy host. This in turn means that jsgi-vhost will fallback to the default host: in this case it happened to be evilstreak's blog. Oops. The correct config invocation for nginx to preserve the host header from the request is:

server {
    listen 80;
    server_name ashberlin.co.uk;

    location /blog/ {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $http_host;
    }
}

So to those of you who read my RSS feed - sorry for the confusing posts over night. That's what I get for playing at being a sysadmin late at night.

Markdown's List Handling

Posted on Jan 23

Jeff Atwood of codinghorror.com recently posted a rant/diatribe against Markdown, whilst at the same time declaring his love for it...

I agree 99% - the 1% where I don't agree is point #3 is a non-issue for me.

When evilstreak and I wrote markdown-js recently we spent hours ranting against the fact that the 'specification' for Markdown is the broken implementation of Markdown.pl. (As for why we wrote a new implementation, well thats a whole other story. Main reason being needed an intermediate representation to play with.) Take this particular gem:

Read the rest »