<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title>ashberlin.co.uk - blog</title>
  <link href="http://ashberlin.co.uk/blog/" />
  <updated>2013-08-22T20:59:51+01:00</updated>
  <author>
    <name>Ash Berlin</name>

  </author>
  <id>http://ashberlin.co.uk/blog/feed</id>

  
    <entry>
      <title>Nesting LVM for resizeable VMs</title>
      <link href="http://ashberlin.co.uk/blog/2011/02/06/nesting-lvm" />
      <id>tag:ashberlin.co.uk:2011-02-06:</id>
      <updated>2011-02-06T14:24:19+00:00</updated>
      <published>2011-02-06T14:24:19+00:00</published>
      <summary type="html">&lt;p&gt;As part of my role wearing the DevOps hat at DigiResults I&amp;#8217;m in charge of setting up new machines; since I&amp;#8217;m terminally lazy I clearly want to automate this. My first attempt used the &lt;code&gt;ubuntu-vm-builder&lt;/code&gt; (which is a ubuntu-provided wrapper around the more generic &lt;code&gt;vmbuilder&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;vmbuilder&lt;/code&gt; will happily write to a &amp;#8216;raw&amp;#8217; 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):&lt;/p&gt;

&lt;pre class='bash'&gt;&lt;code&gt;ubuntu-vm-builder kvm --raw /dev/mapper/vms-my_vm --hostname=my_vm&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;produces as disk layout the looks something like this (the PV and VGs aren&amp;#8217;t shown as they just complicate matters&lt;/p&gt;

&lt;pre class='no-highlight'&gt;&lt;code&gt;--- LVM on Host -------------------
| /dev/mapper/vms/my_vm (LV)      |
|                                 |
|    ----- VM ------------------- |
|    | /dev/sda*                | |
|    |                          | |
|    |                          | |
|    |                          | |
|    |                          | |
|    ---------------------------- |
-----------------------------------&lt;/code&gt;&lt;/pre&gt;
&lt;!-- more --&gt;
&lt;p&gt;The &amp;#8216;hard disk&amp;#8217; that the VM sees is actually an LVM partition with an MBR and partition table etc. on it. Since &lt;code&gt;/dev/sda&lt;/code&gt; is on LVM we can resize this &amp;#8216;disk&amp;#8217; but since there is a partition table this is just as if you did a byte-for-byte copy (using &lt;code&gt;dd&lt;/code&gt; or similar) of the old disk onto a new one - it doesn&amp;#8217;t actually resize the partitions. Bugger.&lt;/p&gt;

&lt;p&gt;I know I could have simply taken the VM down, run fdisk+ext2resize and then booted it up to work around this but I really wanted to do this without down time (and I couldn&amp;#8217;t get round the kernel&amp;#8217;s caching of partition tables when attempting the same on-line.)&lt;/p&gt;

&lt;p&gt;So what option is there to have on-line-resizeable VMs? Run LVM in the guest &lt;em&gt;and&lt;/em&gt; on the host. Yes, that will incur an extra (hopefully slight) performance hit, but since we&amp;#8217;re talking about VMs here it shouldn&amp;#8217;t be significant. As for it being a crazy idea: it certainly is, and it&amp;#8217;s all &lt;a href='http://unixdaemon.net'&gt;Dean&amp;#8217;s&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To round this post off here&amp;#8217;s another limited edition Ash-ASCII-art image:&lt;/p&gt;

&lt;pre class='no-highlight'&gt;&lt;code&gt;--- LVM on Host -------------------
| /dev/mapper/vms/my_vm (LV)      |
|                                 |
|    ----- VM ------------------- |
|    | /dev/sda*                | |
|    |                          | |
|    |   -- LVM on VM---------- | |
|    |   | /dev/mapper/lvm/*  | | |
|    |   |                    | | |
|    |   |                    | | |
|    |   ---------------------- | |
|    ---------------------------- |
-----------------------------------&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Unfortunately I couldn&amp;#8217;t work out how to get vmbuilder to put LVM onto the raw partition so I switched to netboot and preseeding which does support LVM (rather trivially) and is still fully automatic. Actually finding out all the pressed questions/answers to get it fully automated with LVM is another post.&lt;/p&gt;</summary>
    </entry>
  
    <entry>
      <title>Colorful Ubuntu init.d scripts</title>
      <link href="http://ashberlin.co.uk/blog/2010/08/24/color-in-ubuntu-init-scripts" />
      <id>tag:ashberlin.co.uk:2010-08-24:</id>
      <updated>2010-08-24T13:19:29+01:00</updated>
      <published>2010-08-24T13:19:29+01:00</published>
      <summary type="html">&lt;p&gt;Writing init.d scripts is fun. So much fun that its really easy to fall down rabbit holes &amp;gt;_&amp;gt;.&lt;/p&gt;

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

&lt;p&gt;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.&lt;/p&gt;
&lt;pre class='highlight'&gt;&lt;code class='shell-session'&gt;&lt;span class='gp'&gt;ash@home:~$&lt;/span&gt; tput hpa 20 &lt;span class='o'&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class='nb'&gt;echo &lt;/span&gt;a
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Luckily its easy enough to add by running this command:&lt;/p&gt;
&lt;pre class='highlight'&gt;&lt;code class='bash'&gt;&lt;span class='o'&gt;(&lt;/span&gt;infocmp; &lt;span class='nb'&gt;printf&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;\thpa=\\E[%sG,\n&amp;#39;&lt;/span&gt; %i%p1%d&lt;span class='o'&gt;)&lt;/span&gt; &amp;gt; &lt;span class='nv'&gt;$$&lt;/span&gt; tmp-&lt;span class='k'&gt;${&lt;/span&gt;&lt;span class='nv'&gt;$}&lt;/span&gt;&lt;span class='p'&gt;.tic &amp;amp;&amp;amp; \&lt;/span&gt;
&lt;span class='p'&gt;  tic -s tmp-&lt;/span&gt;&lt;span class='nv'&gt;$$&lt;/span&gt;&lt;span class='p'&gt;.tic &amp;amp;&amp;amp; rm tmp-&lt;/span&gt;&lt;span class='nv'&gt;$$&lt;/span&gt;&lt;span class='p'&gt;.tic&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;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&amp;#8217;t support the &lt;code&gt;-e&lt;/code&gt; flag to escape input.)&lt;/p&gt;

&lt;p&gt;(If you want to do this system wide, and a &lt;code&gt;-o/etc/terminfo&lt;/code&gt; option to the tic command.)&lt;/p&gt;

&lt;p&gt;Now lets test it:&lt;/p&gt;
&lt;pre class='highlight'&gt;&lt;code class='shell-session'&gt;&lt;span class='gp'&gt;ash@home:~$&lt;/span&gt; &lt;span class='nb'&gt;echo&lt;/span&gt; -n b &lt;span class='o'&gt;&amp;amp;&amp;amp;&lt;/span&gt; tput hpa 20 &lt;span class='o'&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class='nb'&gt;echo &lt;/span&gt;a
&lt;span class='go'&gt;b                   a&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With any luck the init.d scripts on Ubuntu will now print &lt;code&gt;[ OK ]&lt;/code&gt; in colour on the right hand side of your terminal.&lt;/p&gt;</summary>
    </entry>
  
    <entry>
      <title>Host header with nginx proxy_pass</title>
      <link href="http://ashberlin.co.uk/blog/2010/03/31/nginx-proxy-host-header" />
      <id>tag:ashberlin.co.uk:2010-03-31:</id>
      <updated>2010-03-31T12:37:17+01:00</updated>
      <published>2010-03-31T12:37:17+01:00</published>
      <summary type="html">&lt;p&gt;I recently moved this blog and &lt;a href='http://evilstreak.co.uk/blog/'&gt;evilstreak&amp;#8217;s&lt;/a&gt; to a VM on my stonking new server from Hetzner: 24GB. Woo!&lt;/p&gt;

&lt;p&gt;But I made a booboo in switching from lighttpd to nginx. It turns out that the &lt;code&gt;proxy_pass&lt;/code&gt; directive for nginx overwrites the Host header from the request with the proxy host. This in turn means that &lt;a href='http://github.com/ashb/jsgi-vhost'&gt;jsgi-vhost&lt;/a&gt; will fallback to the default host: in this case it happened to be evilstreak&amp;#8217;s blog. Oops. The correct config invocation for nginx to preserve the host header from the request is:&lt;/p&gt;
&lt;pre class='highlight'&gt;&lt;code class='nginx'&gt;&lt;span class='k'&gt;server&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='kn'&gt;listen&lt;/span&gt; &lt;span class='mi'&gt;80&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    &lt;span class='kn'&gt;server_name&lt;/span&gt; &lt;span class='s'&gt;ashberlin.co.uk&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;

    &lt;span class='kn'&gt;location&lt;/span&gt; &lt;span class='s'&gt;/blog/&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='kn'&gt;proxy_pass&lt;/span&gt; &lt;span class='s'&gt;http://127.0.0.1:3000&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
        &lt;span class='kn'&gt;proxy_set_header&lt;/span&gt; &lt;span class='s'&gt;Host&lt;/span&gt; &lt;span class='nv'&gt;$http_host&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So to those of you who read my RSS feed - sorry for the confusing posts over night. That&amp;#8217;s what I get for playing at being a sysadmin late at night.&lt;/p&gt;</summary>
    </entry>
  
    <entry>
      <title>Running JSGI Multiple Apps in One Process</title>
      <link href="http://ashberlin.co.uk/blog/2010/02/10/multiple-apps-one-process" />
      <id>tag:ashberlin.co.uk:2010-02-10:</id>
      <updated>2010-02-10T00:00:00+00:00</updated>
      <published>2010-02-10T00:00:00+00:00</published>
      <summary type="html">&lt;p&gt;Good idea or bad?&lt;/p&gt;

&lt;p&gt;&amp;#8216;App&amp;#8217; in this case is talking about running two different &lt;a href='http://github.com/evilstreak/pressed'&gt;Pressed&lt;/a&gt; (a blog engine for &lt;a href='http://juicejs.org'&gt;Juice&lt;/a&gt;) apps. More generally this question could apply to any application written in a scripting language.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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&amp;#8217;ve worked around it.&lt;/p&gt;

&lt;p&gt;This is just a post of the &amp;#8220;Remember Ash, Don&amp;#8217;t Do That&amp;#8221; variety. Some approach like &lt;a href='http://romeda.org/blog/2010/01/hot-code-loading-in-nodejs.html'&gt;this node.js patch&lt;/a&gt; might be a suitable alternative, and it gives other fuzzy warm benefits too.&lt;/p&gt;</summary>
    </entry>
  
    <entry>
      <title>Markdown's List Handling</title>
      <link href="http://ashberlin.co.uk/blog/2010/01/23/markdown-lists" />
      <id>tag:ashberlin.co.uk:2010-01-23:</id>
      <updated>2010-01-23T20:53:15+00:00</updated>
      <published>2010-01-23T20:53:15+00:00</published>
      <summary type="html">&lt;p&gt;Jeff Atwood of codinghorror.com recently posted a &lt;a href='http://www.codinghorror.com/blog/archives/001317.html' title='Responsible Open Source Code Parenting'&gt;rant/diatribe against Markdown&lt;/a&gt;, whilst at the same time declaring his love for it&amp;#8230;&lt;/p&gt;

&lt;p&gt;I agree 99% - the 1% where I don&amp;#8217;t agree is point #3 is a non-issue for me.&lt;/p&gt;

&lt;p&gt;When &lt;a href='http://evilstreak.co.uk'&gt;evilstreak&lt;/a&gt; and I wrote &lt;a href='http://github.com/evilstreak/markdown-js/'&gt;markdown-js&lt;/a&gt; recently we spent hours ranting against the fact that the &amp;#8216;specification&amp;#8217; 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 &lt;a href='http://github.com/evilstreak/markdown-js/blob/d791cb227c62164f5fe47f327854362388e692a0/test/regressions.t.js#L192-210'&gt;this particular gem&lt;/a&gt;:&lt;/p&gt;
&lt;!-- more --&gt;
&lt;pre&gt;&lt;code&gt;  * foo
   * bar
* baz
 * fnord&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Its rather brilliantly ambiguous. It is of course not mentioned in the &amp;#8216;specification&amp;#8217; (which is not a specification per say: its a usage guide). Markdown.pl treats it as if you&amp;#8217;d written:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;* foo
  * bar
  * baz
  * fnord&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So of course this is the behaviour in most markdown implementations &amp;#8211; &lt;a href='http://babelmark.bobtfish.net/'&gt;Babelmark&lt;/a&gt; is a good tool for this sort of checking. If you think that case is odd, try to work out what &lt;a href='http://github.com/evilstreak/markdown-js/blob/d791cb227c62164f5fe47f327854362388e692a0/test/regressions.t.js#L271-319'&gt;this example&lt;/a&gt; is treated as:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;   * foo
  * bar
 * baz
* HATE
  * flibble
   * quxx
    * nest?
        * where
      * am
     * i?&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Any guesses? No? Well, its as if you entered this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;* foo
    * bar
    * baz
    * HATE
    * flibble
* quxx
    * nest?
        * where
        * am
        * i?&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you dont believe me, &lt;a href='http://babelmark.bobtfish.net/?markdown=+++*+foo%0D%0A++*+bar%0D%0A+*+baz%0D%0A*+HATE%0D%0A++*+flibble%0D%0A+++*+quxx%0D%0A++++*+nest%3F%0D%0A++++++++*+where%0D%0A++++++*+am%0D%0A+++++*+i%3F%0D%0A&amp;amp;compare=on&amp;amp;src=0&amp;amp;dest=1'&gt;try it for yourself&lt;/a&gt;. This took me a number of hours just staring at the output and trying different permutations to to work out just &lt;em&gt;what&lt;/em&gt; was going on here. I guess I could have looked at the code, but I &lt;em&gt;like&lt;/em&gt; my eyes, thank you very much.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m not sure if this is how other implementations manage it, but what we did to replicate this (brain dead) behaviour was:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;keep a &amp;#8216;stack&amp;#8217; of previous lists and what indent they have, updated when ever you create a new nested list or &amp;#8216;un-nest&amp;#8217; a list item by pushing and popping&lt;/li&gt;

&lt;li&gt;if the next item is indented by 4 more spaces than the &amp;#8216;indent level&amp;#8217; of the previous item then it&amp;#8217;s a nested list.&lt;/li&gt;

&lt;li&gt;if the number of indent chars (after tab expansion) exactly matches the indent of a list in the stack, place it at the same level as that item&lt;/li&gt;

&lt;li&gt;failing that, treat it as if it was just indented to make it a sub list, even if it is actually indented less than the &amp;#8216;parent&amp;#8217; list item.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The third point above explains why in case VII &lt;code&gt;quxx&lt;/code&gt; appears at the same level as &lt;code&gt;foo&lt;/code&gt;. And screams out for a desperate need for some cases to be specified as errors.&lt;/p&gt;

&lt;p&gt;So no you know what you get when you have people implement a project in different languages without a sufficiently spec-like-spec or even some regression tests they could run: chaos.&lt;/p&gt;</summary>
    </entry>
  

</feed>
