Ash Berlin

Nesting LVM for resizeable VMs

Posted on Feb 6 2011

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 2010

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.

ash@home:~$ 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:

ash@home:~$ 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 2010

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.

Running JSGI Multiple Apps in One Process

Posted on Feb 10 2010

Good idea or bad?

‘App’ in this case is talking about running two different Pressed (a blog engine for Juice) apps. More generally this question could apply to any application written in a scripting language.

Well on the one hand, if the apps use a lot of common modules, the memory footprint will be reduced. And using less memory is always hand for resource-starved virtual servers.

However more seriously this turns out to be a horrendously bad idea. Who knew? (Clearly not me). Even when you control all the apps in question and can set aside the security concerns, there are other reasons to not do this. Well just one really: its far to easy to unintentionally share state between the apps apps, even when you know about this danger and thought you’ve worked around it.

This is just a post of the “Remember Ash, Don’t Do That” variety. Some approach like this node.js patch might be a suitable alternative, and it gives other fuzzy warm benefits too.

Markdown's List Handling

Posted on Jan 23 2010

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 »