<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>In Valid Logic</title>
 <link href="http://invalidlogic.com/atom.xml" rel="self"/>
 <link href="http://invalidlogic.com"/>
 <link rel="license" type="/application/rdf+xml" href="http://creativecommons.org/licenses/by-nc-sa/3.0/rdf" />
 <updated>2012-05-01T09:49:51-07:00</updated>
 <id>http://invalidlogic.com</id>
 <author>
     <name>Ken Robertson</name>
     <email>ken@invalidlogic.com</email>
 </author>

 
 <entry>
   <title>Deploying Ubuntu 12.04 on XenServer Made Easy</title>
   <link href="http://invalidlogic.com//2012/05/01/deploying-ubuntu-12-04-on-xenserver-made-easy/"/>
   <link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" />
   <updated>2012-05-01T00:00:00-07:00</updated>
   <id>http://invalidlogic.com//2012/05/01/deploying-ubuntu-12-04-on-xenserver-made-easy</id>
   <content type="html">&lt;p&gt;To follow up on my &lt;a href=&quot;/2012/04/28/ubuntu-precise-on-xenserver-disk-errors&quot;&gt;previous post&lt;/a&gt;
about disk errors with Ubuntu 12.04 on XenServer, I wanted to cover the process
I've put in place for provisioning Ubuntu VMs.&lt;/p&gt;

&lt;p&gt;With &lt;a href=&quot;http://paas.io&quot;&gt;PaaS.io&lt;/a&gt;, I have a mixture between systems deployed on bare
metal and virtualized.  With the virtualized systems, I set out to make the
provisioning as easy as if I was using an IaaS provider, while still giving me
fine control over sizing and placement. Some of the decisions there are enough
for another post.&lt;/p&gt;

&lt;p&gt;Ubuntu 12.04 is the new hotness and I'd been anxiously awaiting it, with plans
to progressively roll it out throughout PaaS.io.&lt;/p&gt;

&lt;p&gt;With XenServer, it provides an easy template for provisioning Ubuntu Lucid 10.04
VMs and even for some newer releases.  However, the way XenSever provisions
Ubuntu is to essentially netboot it and install it from a remote source. Because
of that, we can't simply use one of those templates buts install a newer release.&lt;/p&gt;

&lt;p&gt;Fortunately, the template itself is very simple, and which release it installs is
just a configuration parameter.&lt;/p&gt;

&lt;p&gt;To create a new Ubuntu 12.04 template, simply log into the XenServer console and
runt he following commands.  It will clone the Lucid template and then change
the parameter for the release to install from &lt;code&gt;lucid&lt;/code&gt; to &lt;code&gt;precise&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;console&quot;&gt;&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;TEMPLATE_UUID&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;xe template-list &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;        name-label=&amp;quot;Ubuntu Lucid Lynx 10.04 (64-bit)&amp;quot; params=uuid --minimal`&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;NEW_TEMPLATE_UUID&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;xe vm-clone &lt;span class=&quot;nv&quot;&gt;uuid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$TEMPLATE_UUID&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;        new-name-label=&amp;quot;Ubuntu Precise (64-bit)&amp;quot;`&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; xe template-param-set other-config:default_template&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;        other-config:debian-release=precise uuid=$NEW_TEMPLATE_UUID&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Now you will find a &quot;Ubuntu Precise (64-bit)&quot; option in the template list of
XenCenter.&lt;/p&gt;

&lt;div style=&quot;text-align: center&quot; markdown=&quot;1&quot;&gt;
&lt;img src=&quot;http://invalidlogic-blog.s3.amazonaws.com/2012-04-30-xencenter1.jpg&quot; alt=&quot;XenCenter template list&quot; /&gt;
&lt;/div&gt;


&lt;p&gt;Now, we can actually provision a new box.  Next, one interesting discovery was
that you can pass in a kickstart script in the boot parameters options for the new
VM.&lt;/p&gt;

&lt;p&gt;Kickstart allows you to do a scripted installation, automated pretty much
every aspect of the system.  Instead of picking a bunch of options, it allows
for an easy, repeatable process that basically leaves the machine completely
ready to go.&lt;/p&gt;

&lt;p&gt;To use a kickstart script, make a script available over HTTP somewhere on your
LAN or on the public internet.  By the time it is grabbed, the machine will have
an IP, DNS, and all.  Then, simply add &lt;code&gt;ks=http://url/to/your/kickstart&lt;/code&gt; to the
beginning part of &quot;advanced OS boot parameters&quot; option when selecting the
installation media.&lt;/p&gt;

&lt;div style=&quot;text-align: center&quot; markdown=&quot;1&quot;&gt;
&lt;img src=&quot;http://invalidlogic-blog.s3.amazonaws.com/2012-04-30-xencenter2.jpg&quot; alt=&quot;XenCenter media selection&quot; /&gt;
&lt;/div&gt;


&lt;p&gt;Below is a cleaned version of the kickstart script I used on my Ubuntu VMs. The
main things of note:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sets up my partition table&lt;/li&gt;
&lt;li&gt;Configures base system with ubuntu-minimal as well as some common packages
like openssh-server, curl, wget, and screen.&lt;/li&gt;
&lt;li&gt;Disables the creation of the &lt;code&gt;ubuntu&lt;/code&gt; user (I create a normal every day user through chef)&lt;/li&gt;
&lt;li&gt;Configures the fstab with &lt;code&gt;barrier=0&lt;/code&gt; as mentioned before&lt;/li&gt;
&lt;li&gt;Disables &lt;code&gt;/bin/sh&lt;/code&gt; from pointing to &lt;code&gt;/bin/dash&lt;/code&gt; (personal preference)&lt;/li&gt;
&lt;li&gt;Updates apt sources&lt;/li&gt;
&lt;li&gt;Installs xenstore-utils&lt;/li&gt;
&lt;li&gt;Downloads some auto-configuration scripts&lt;/li&gt;
&lt;li&gt;Installs XenTools&lt;/li&gt;
&lt;li&gt;Installs the Ubuntu virtual kernel and removes the generic one&lt;/li&gt;
&lt;li&gt;Cleans up apt caches&lt;/li&gt;
&lt;li&gt;Shuts down the VM.&lt;/li&gt;
&lt;/ul&gt;


&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;lang en_US
langsupport en_US
keyboard us
timezone America/Los_Angeles
text
install
skipx
halt
url --url http://us.archive.ubuntu.com/ubuntu

rootpw pa$$word   # you should replace, and use --iscrypted
auth --useshadow --enablemd5
user --disabled

bootloader --location=mbr
zerombr yes
clearpart --all --initlabel
part /boot --fstype=ext2 --size=64
part swap --size=1024
part / --fstype=ext4 --size=1 --grow

network --device=eth0 --bootproto=static --ip=10.0.0.50 --netmask=255.255.255.0 \
        --nameserver=10.0.0.1 --gateway=10.0.0.1
firewall --disabled

%packages
ubuntu-minimal
openssh-server
screen
curl
wget

%post

# update fstab for the root partition
perl -pi -e &amp;#39;s/(errors=remount-ro)/noatime,nodiratime,$1,barrier=0/&amp;#39; /etc/fstab

# point sh to bash instead of dash
rm /bin/sh
ln -s /bin/bash /bin/sh

# add normal apt source list
(
cat &amp;lt;&amp;lt;&amp;#39;EOP&amp;#39;
deb http://us.archive.ubuntu.com/ubuntu/ precise main restricted universe
deb http://us.archive.ubuntu.com/ubuntu/ precise-security main restricted universe
deb http://us.archive.ubuntu.com/ubuntu/ precise-updates main restricted universe
EOP
) &amp;gt; /etc/apt/sources.list
apt-get update
apt-get upgrade -y

# install some additional packages
apt-get install -y xenstore-utils

# set up xenserver automation scripts
AUTOMATER_REPO=https://raw.github.com/krobertson/xenserver-automater
curl $AUTOMATER_REPO/master/usr/sbin/xe-set-hostname &amp;gt; /usr/sbin/xe-set-hostname
curl $AUTOMATER_REPO/master/usr/sbin/xe-set-network &amp;gt; /usr/sbin/xe-set-network
curl $AUTOMATER_REPO/master/usr/sbin/generate-sshd-keys &amp;gt; /usr/sbin/generate-sshd-keys
curl $AUTOMATER_REPO/master/etc/init/xe-automator.conf &amp;gt; /etc/init/xe-automator.conf
chmod a+x /usr/sbin/xe-set-hostname
chmod a+x /usr/sbin/xe-set-network
chmod a+x /usr/sbin/generate-sshd-keys

# setup locales
locale-gen en_US.UTF-8
update-locale LANG=&amp;quot;en_US.UTF-8&amp;quot;
echo &amp;#39;LANG=en_US.UTF-8&amp;#39; &amp;gt;&amp;gt; /etc/environment
echo &amp;#39;LC_ALL=en_US.UTF-8&amp;#39; &amp;gt;&amp;gt; /etc/environment

# install xe tools
cd /tmp
wget http://some/url/to/xe-guest-utilities_6.0.0-743_amd64.deb
dpkg -i xe-guest-utilities_6.0.0-743_amd64.deb

# install paravirt kernel image
apt-get install -f -y linux-virtual
dpkg -l | grep generic | grep linux | awk &amp;#39;{print $2}&amp;#39; | xargs apt-get remove -y

# clean up some stuff
rm -f /etc/ssh/ssh_host_*
rm -f /var/cache/apt/archives/*.deb
rm -f /var/cache/apt/*cache.bin
rm -f /var/lib/apt/lists/*_Packages
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;It is important that it shuts down at the end.  My goal was to have it be all
inclusive, and that means setting up the virtual kernel.  However, it can't successfully
reboot, because we need to update some PV boot options before it is ready to go.&lt;/p&gt;

&lt;p&gt;Also, some packages must be installed in the post steps. The default install sources
for Ubuntu don't always have all packages available, and I found it best to do
the kernel last.&lt;/p&gt;

&lt;p&gt;When you first bring up the new VM in XenServer, you may need to enter in a few
details if you don't have DHCP running.  It will self configure by default,
but I normally opt to manually configure it to ensure the template gets a certain
IP just to avoid any future possible collision.&lt;/p&gt;

&lt;p&gt;After the bootstrapping is done and the VM is then off, log into console on
the XenServer host itself and run the following snippet:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;console&quot;&gt;&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;VMNAME&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;precise-20120501
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;UUID&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;xe vm-list name-label&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;$VMNAME&amp;quot;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;uuid --minimal&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;EDITOR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;cat xe-edit-bootloader -n &lt;span class=&quot;s2&quot;&gt;&amp;quot;$VMNAME&amp;quot;&lt;/span&gt; -p 1 &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;        -f /grub/grub.cfg &amp;gt; /tmp/$VMNAME-grub&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;KERNEL&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;grep vmlinuz /tmp/&lt;span class=&quot;nv&quot;&gt;$VMNAME&lt;/span&gt;-grub | grep virtual |
&lt;span class=&quot;go&quot;&gt;        grep -v recovery | awk &amp;#39;{print $2}&amp;#39;`&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;ROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;grep vmlinuz /tmp/&lt;span class=&quot;nv&quot;&gt;$VMNAME&lt;/span&gt;-grub | grep virtual |
&lt;span class=&quot;go&quot;&gt;        grep -v recovery | awk &amp;#39;{print $3}&amp;#39;`&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;RAMDISK&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;grep initrd /tmp/&lt;span class=&quot;nv&quot;&gt;$VMNAME&lt;/span&gt;-grub | head -1 | awk &lt;span class=&quot;s1&quot;&gt;&amp;#39;{print $2}&amp;#39;&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; xe vm-param-set &lt;span class=&quot;nv&quot;&gt;uuid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$UUID&lt;/span&gt; PV-bootloader-args&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;--kernel=$KERNEL --ramdisk=$RAMDISK&amp;quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; xe vm-param-set &lt;span class=&quot;nv&quot;&gt;uuid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$UUID&lt;/span&gt; PV-args&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;$ROOT ro quiet console=hvc0&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Before you run it, of course set the VMNAME to the name of your VM.  You might
also want to check some of the values as you go (&lt;code&gt;echo $UUID&lt;/code&gt;). You can use the
&lt;code&gt;xe-edit-bootloader&lt;/code&gt; command to view the grub configuration within the VM, but
need to set the PV settings outside the guest.  By faking the &lt;code&gt;EDITOR&lt;/code&gt; to cat,
you can export the grub file to a local file, then use some grep+awk to get
the necessary pieces and finally set the PV settings correctly.&lt;/p&gt;

&lt;p&gt;At this point, the machine is ready to be booted, converted into a template, or
simply cloned.  I personally like to leave my templates as never-been-used.&lt;/p&gt;

&lt;p&gt;One of the main benefits of an IaaS setup like OpenStack or CloudStack is the
self orientating of the VMs.  Normally with a template, it keeps the template's
setting for its hostname and network configuration.  However, I found some example
scripts on Github for passing network information into a VM through the VM's
&quot;xenstore&quot; options.  That way on boot, the VM can read in the settings it needs
and update itself. I &lt;a href=&quot;https://github.com/krobertson/xenserver-automater&quot;&gt;did some work&lt;/a&gt;
to update the scripts to work with Precise, to more thoroughly update the hostname
and DNS, as well as to regenerate the ssh host keys (since the kickstart did
delete them).&lt;/p&gt;

&lt;p&gt;As an example, this would be how to clone the template to a VM, set the params,
and boot it:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;console&quot;&gt;&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;UUID&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;xe vm-install &lt;span class=&quot;nv&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;precise-20120501 new-name-label&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;builder&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; xe vm-param-set &lt;span class=&quot;nv&quot;&gt;uuid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$UUID&lt;/span&gt; xenstore-data:vm-data/ip&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;10.0.0.11
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; xe vm-param-set &lt;span class=&quot;nv&quot;&gt;uuid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$UUID&lt;/span&gt; xenstore-data:vm-data/gw&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;10.0.0.1
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; xe vm-param-set &lt;span class=&quot;nv&quot;&gt;uuid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$UUID&lt;/span&gt; xenstore-data:vm-data/nm&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;255.255.255.0
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; xe vm-param-set &lt;span class=&quot;nv&quot;&gt;uuid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$UUID&lt;/span&gt; xenstore-data:vm-data/ns&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;10.0.0.1 10.0.0.2&amp;#39;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; xe vm-start &lt;span class=&quot;nv&quot;&gt;uuid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$UUID&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;That is cool and all, but I don't want to log into the XenServer console each
time I want to setup a VM.  Luckily, found a plugin for Chef's &lt;code&gt;knife&lt;/code&gt; utility
that &lt;a href=&quot;https://github.com/bvox/knife-xenserver&quot;&gt;adds XenServer provisioning&lt;/a&gt;. I
forked it and added &lt;a href=&quot;https://github.com/krobertson/knife-xenserver&quot;&gt;setting xenstore network parameters&lt;/a&gt;
to it.&lt;/p&gt;

&lt;p&gt;Now, provisioning a new VM, configuring it, and bootstrapping chef on it is just
a matter of one call:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;console&quot;&gt;&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; knife xenserver vm create --vm-template precise-20120501 &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;                            -x root --keep-template-networks \&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;                            -r &amp;quot;role[foo]&amp;quot; -E production \&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;                            --vm-ip 10.0.0.12 --vm-name foobar&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;The command may be a little long, but it is all encapsulated in a single command.
I simply have an internal README of sorts with the command pre-prepared for various
roles.&lt;/p&gt;

&lt;p&gt;If you have any questions, please leave a comment and ask.  I'd be glad to help
and always looking to improve my process as well.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Fixing random disk errors with Ubuntu 12.04 Precise on XenServer</title>
   <link href="http://invalidlogic.com//2012/04/28/ubuntu-precise-on-xenserver-disk-errors/"/>
   <link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" />
   <updated>2012-04-28T00:00:00-07:00</updated>
   <id>http://invalidlogic.com//2012/04/28/ubuntu-precise-on-xenserver-disk-errors</id>
   <content type="html">&lt;p&gt;Ubuntu 12.04 LTS Precise is hot off the press right now.  Over the past few days,
have been working on building new base images for &lt;a href=&quot;http://paas.io&quot;&gt;PaaS.io&lt;/a&gt;, but
was running into random issues where the root parition would encounter an error
and freeze up.  It normally happened just after it would finish booting and about
50% of the time.&lt;/p&gt;

&lt;p&gt;A few times it happened after I already logged in, so was able to do basic read
only operations.  In &lt;code&gt;dmesg&lt;/code&gt;, was able to see the following:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;[    6.748868] blkfront: barrier: empty write xvda op failed
[    6.748876] blkfront: xvda: barrier or flush: disabled
[    6.748890] end_request: I/O error, dev xvda, sector 6584768
[    6.748908] end_request: I/O error, dev xvda, sector 6584768
[    6.748943] Aborting journal on device xvda6-8.
[    6.767022] EXT4-fs error (device xvda6): ext4_journal_start_sb:327: Detected aborted journal
[    6.767046] EXT4-fs (xvda6): Remounting filesystem read-only
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Or if you weren't able to log in first, you might see this in the XenCenter
console:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://img.skitch.com/20120427-qxcyrn473jdw37qi67ay1wguqf.medium.jpg&quot; alt=&quot;XenCenter show&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After some Googling, was able to track a similar error down by someone else. The
fix was to update the mount options for the root partition.  Mine are now:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;noatime,nodiratime,errors=remount-ro,barrier=0
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;The key is the &lt;code&gt;barrier=0&lt;/code&gt;.  From some &lt;a href=&quot;http://kernelnewbies.org/Ext4#head-25c0a1275a571f7332fa196d4437c38e79f39f63&quot;&gt;documentation&lt;/a&gt;, it is an option to help increase the
integrity of writes by ensuring everything is flushed to disk be committing to the
journal.  However sometimes in a virtualized environment that is difficult to
guarantee.  In my case, have disk-&gt;RAID-&gt;dom0-&gt;LVM-&gt;domU.&lt;/p&gt;

&lt;p&gt;Figure many other people will be diving into Precise this weekend, potentially
running into this issue like me.&lt;/p&gt;

&lt;p&gt;Soon, will post some additional details about how to easily get a nice Precise
template in XenServer 6. I've been getting my setup nicely tuned using a kickstart
script for the base system and leveraging xenstore data to dynamically setup the
IP and hostname on boot.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Configuring MongoDB Replica Sets With Keepalived</title>
   <link href="http://invalidlogic.com//2012/02/23/configuring-mongodb-replica-sets-with-keepalived/"/>
   <link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" />
   <updated>2012-02-23T00:00:00-08:00</updated>
   <id>http://invalidlogic.com//2012/02/23/configuring-mongodb-replica-sets-with-keepalived</id>
   <content type="html">&lt;p&gt;While working on developing &lt;a href=&quot;http://paas.io&quot;&gt;PaaS.io&lt;/a&gt;, one of my primary objectives is to
ensure that everything is configured to be truly Highly Available (HA).
This means everything has a secondary, replicated, and has automated
failover. This way it is nicely resilent and fault tolerant. Core
infrastructure changes can be made without any affect to running
applications, servers go down without issues. Sweet, huh?&lt;/p&gt;

&lt;p&gt;When it came to setting up MongoDB, the obvious option was to go to
using Replica Sets. They're like master-slave replication in RDBMSes but
the master node is essentially floating.  Client applications connect to
the whole cluster, identify the master, and then start to speak to it.&lt;/p&gt;

&lt;p&gt;By default, Cloud Foundry provisions a dedicated MongoDB instance for
you and provides you the IP, port, and other credentials. This doesn't
include replication, and focuses on single IP connections rather than
replica sets.&lt;/p&gt;

&lt;p&gt;However when using Replica Sets, the connection pattern in your code is
slightly different.  You use a &lt;code&gt;ReplSetConnection&lt;/code&gt; instead of a
normal &lt;code&gt;Connection&lt;/code&gt;, in ruby driver speak. So you need to &lt;em&gt;know&lt;/em&gt; you're
connecting to a Replica Set if the host you're connecting to isn't the
master. If you only connect to the master though, you can use a
traditional connection.&lt;/p&gt;

&lt;p&gt;I was interested in maintainin full compatibility with Cloud Foundry's
out-of-the-box experience, so first looked at using &lt;code&gt;mongos&lt;/code&gt; in front of
replicas. It is normally used to front a sharded setup, but using it
without sharding is still a &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1594&quot;&gt;feature request&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So I set out looking at how to use a virtual IP
have it track which node is the master. In this case, if one switches over, it will
pick it up and move the virtual IP to follow. This would be mostly
transparent to the application. The only handling in the app is the next
query will fail, but quickly reconnect and its fine.&lt;/p&gt;

&lt;p&gt;I'd already been using &lt;a href=&quot;http://www.keepalived.org/&quot;&gt;keepalived&lt;/a&gt; for HA within HAProxy, and one of the
nice things it provides is the ability to define a script to run as a
part of its local health checks. Using this, can have a script that just
asks the local system &lt;em&gt;&quot;you the master?&quot;&lt;/em&gt; and returns appropriately.&lt;/p&gt;

&lt;p&gt;Below is the script:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/env ruby&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;optparse&amp;#39;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;options&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:hostname&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;127.0.0.1&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;ss&quot;&gt;:port&lt;/span&gt;     &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;27017&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;ss&quot;&gt;:username&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;ss&quot;&gt;:password&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;optparser&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;OptionParser&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;opt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;opt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;banner&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Usage: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;vg&quot;&gt;$0&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; [options]&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;opt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;-H&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;--hostname HOST&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Hostname&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:hostname&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;o&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;o&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;opt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;-P&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;--port PORT&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Hostname&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:port&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to_i&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;o&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;opt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;-u&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;--username USER&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Username&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:username&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;o&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;o&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;opt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;-p&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;--password PASSWORD&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Password&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:password&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;o&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;o&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;optparser&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parse!&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;
  &lt;span class=&quot;vg&quot;&gt;$stderr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;
  &lt;span class=&quot;vg&quot;&gt;$stderr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;optparser&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;exit&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;rubygems&amp;#39;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;mongo&amp;#39;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Mongo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Connection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:hostname&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:port&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;admin&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;authenticate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:username&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:password&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;master_status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;admin&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;isMaster&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;master_status&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;ismaster&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;exit&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;exit&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This won't return any output, but will exit with 0 if it is the master
or 1 if it isn't.&lt;/p&gt;

&lt;p&gt;Its requirements are simple... Ruby, RubyGems, &lt;code&gt;mongo&lt;/code&gt; gem, and
recommend the &lt;code&gt;bson_ext&lt;/code&gt; gem too.&lt;/p&gt;

&lt;p&gt;Then within our &lt;code&gt;keepalived.conf&lt;/code&gt; file, it looks like this:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;global_defs {
   notification_email {
     me@example.com
   }
   notification_email_from system@example.com
   smtp_server 192.168.1.1
   smtp_connect_timeout 30
}

# Define the script used to check if mongod is running
vrrp_script chk_mongod {
    script &amp;quot;killall -0 mongod&amp;quot;
    interval 2 # every two seconds
    weight 2
}

# Define the script to see if the local node is the primary
vrrp_script chk_mongo_primary {
    script &amp;quot;/usr/local/mongodb/bin/mongo_check_primary -u admin -p password&amp;quot;
    interval 2 # every two seconds
    weight 2
}

# Configuation for the virtual interface
vrrp_instance VI_1 {
    interface bond0
    state node MASTER        # SLAVE on the other nodes
    priority 101             # 100 on other nodes
    virtual_router_id 55

    authentication {
        auth_type AH
        auth_pass secret     # Set this to some secret phrase
    }

    # The virtual ip address shared between the two nodes
    virtual_ipaddress {
        192.168.1.222
    }

    # Use the script above to check if we should fail over
    track_script {
        chk_mongod
        chk_mongo_primary
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;With this in place, if a server goes down, it'll switch. If &lt;code&gt;mongod&lt;/code&gt;
dies, it will switch over (since Mongo itself will recognize that), and
if the current primary is switched, the &lt;code&gt;mongo_check_primary&lt;/code&gt; will
return an exit code of 1, causing it to switch over.&lt;/p&gt;

&lt;p&gt;Another reason this might be useful in some cases is because some clients &lt;a href=&quot;https://github.com/bcg/em-mongo/issues/12&quot;&gt;still don't
support replica sets&lt;/a&gt;. With
this method, they don't need to.&lt;/p&gt;

&lt;p&gt;In addition to these steps, you will need to perform the normal steps to
setup keepalived.  These would include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensure &lt;code&gt;mongod&lt;/code&gt; is bound to &lt;code&gt;0.0.0.0&lt;/code&gt; so it'll accept any incoming
connection.&lt;/li&gt;
&lt;li&gt;Set &lt;code&gt;net.ipv4.ip_nonlocal_bind=1&lt;/code&gt; in sysctl so you can use virtual
IPs.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Try this out and let me know your experiences. If you're interested in
this kind of seamless infrastructure automation, check out
&lt;a href=&quot;http://paas.io&quot;&gt;PaaS.io&lt;/a&gt; or drop me a line.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Jekyll on PaaS.io with Cloud Foundry</title>
   <link href="http://invalidlogic.com//2012/01/06/jekyll-on-paasio-with-cloud-foundry/"/>
   <link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" />
   <updated>2012-01-06T00:00:00-08:00</updated>
   <id>http://invalidlogic.com//2012/01/06/jekyll-on-paasio-with-cloud-foundry</id>
   <content type="html">&lt;p&gt;Recently I moved my blog over to the service I am currently working on building, &lt;a href=&quot;http://paas.io&quot;&gt;PaaS.io&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Running Jekyll on PaaS.io isn't all that different from running it on other services, though I had a few other goals in mind.  The way I wanted it set up was:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stop using &lt;code&gt;rack-jekyll&lt;/code&gt;.  Its a nice gem, however it is locked to an older version of Jekyll.  And the current gem is on an even more outdated one.  Currently, Cloud Foundry doesn't support pulling bundler sources from git too.&lt;/li&gt;
&lt;li&gt;Have a &lt;code&gt;public&lt;/code&gt; folder for static content like CSS and images.&lt;/li&gt;
&lt;li&gt;Have the &lt;code&gt;_site&lt;/code&gt; folder for generated content&lt;/li&gt;
&lt;li&gt;Don't have it copy the &lt;code&gt;Gemfile&lt;/code&gt; and the &lt;code&gt;config.ru&lt;/code&gt; into the &lt;code&gt;_site&lt;/code&gt; folder (annoys me)&lt;/li&gt;
&lt;li&gt;Redirect &lt;code&gt;www.invalidlogic.com&lt;/code&gt; to &lt;code&gt;invalidlogic.com&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Low foot print&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;First, the &lt;code&gt;Gemfile&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;source&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:rubygems&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;rack-contrib&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:require&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;rack/contrib/try_static&amp;#39;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;rack-redirect&amp;#39;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;thin&amp;#39;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:development&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;jekyll&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;RedCloth&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;rdiscount&amp;#39;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;The main gems being used are &lt;code&gt;thin&lt;/code&gt;, &lt;code&gt;rack-contrib&lt;/code&gt; (for TryStatic, note on that later), and &lt;code&gt;rack-redirect&lt;/code&gt; (for www redirection).  I also include some of the gems I use for Jekyll in the development group.  That way they are available locally but not loaded when I deploy (lower footprint... and yes, it is minor).&lt;/p&gt;

&lt;p&gt;Now, the &lt;code&gt;config.ru&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;rubygems&amp;#39;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;bundler&amp;#39;&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;Bundler&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;require&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Rack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Solo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;DomainRedirect&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Rack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;TryStatic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;ss&quot;&gt;:root&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;_site&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;ss&quot;&gt;:urls&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;%w[/]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;ss&quot;&gt;:try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;.html&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;index.html&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/index.html&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Rack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Static&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;ss&quot;&gt;:root&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;public&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;ss&quot;&gt;:urls&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;%w[/]&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;404&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Content-Type&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;text/html&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Not Found&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;There are 4 rack components here.  First, &lt;code&gt;Rack::EY::Solo::DomainRedirect&lt;/code&gt; is the &lt;code&gt;rack-redirect&lt;/code&gt; gem and handles the www redirection.  Next, is &lt;code&gt;Rack::TryStatic&lt;/code&gt;.  It is used to access files from the &lt;code&gt;_site&lt;/code&gt; generated content directory.  It gives a couple different &lt;code&gt;:try&lt;/code&gt; values for different ways to find the intended file.  Then is the &lt;code&gt;Rack::Static&lt;/code&gt; which gets static content from the &lt;code&gt;public&lt;/code&gt; directory.  No need to try different combinations.  And last is a generic lambda that will return 404.&lt;/p&gt;

&lt;p&gt;Next, want to avoid duplication.  With things as they are, when I run &lt;code&gt;jekyll&lt;/code&gt; it will copy the &lt;code&gt;public&lt;/code&gt; and other items into the &lt;code&gt;_site&lt;/code&gt; folder duplicating it.  To resolve that, in our &lt;code&gt;_config.yml&lt;/code&gt;, can add an exclude line:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;yaml&quot;&gt;&lt;span class=&quot;l-Scalar-Plain&quot;&gt;exclude&lt;/span&gt;&lt;span class=&quot;p-Indicator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p-Indicator&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;public&amp;#39;&lt;/span&gt;&lt;span class=&quot;p-Indicator&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;Gemfile&amp;#39;&lt;/span&gt;&lt;span class=&quot;p-Indicator&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;Gemfile.lock&amp;#39;&lt;/span&gt;&lt;span class=&quot;p-Indicator&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;config.ru&amp;#39;&lt;/span&gt; &lt;span class=&quot;p-Indicator&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;And with that, we are set!  All of our goals are met.  Commit and push to deploy!  Currently I have &lt;a href=&quot;http://cloudfoundry.org&quot;&gt;Cloud Foundry&lt;/a&gt; set up with a Rack framework defined (will be sending a pull request with it soon) and also have my blog set to use Ruby 1.9.3 as well.&lt;/p&gt;

&lt;p&gt;Soon I'll be providing some more details on &lt;a href=&quot;http://paas.io&quot;&gt;PaaS.io&lt;/a&gt;, so stay tuned and click over to it and sign up to get access to the beta.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>iPhone vs Android is the new Mac vs PC</title>
   <link href="http://invalidlogic.com//2011/10/18/iphone-vs-android-is-the-new-mac-vs-pc/"/>
   <link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" />
   <updated>2011-10-18T00:00:00-07:00</updated>
   <id>http://invalidlogic.com//2011/10/18/iphone-vs-android-is-the-new-mac-vs-pc</id>
   <content type="html">&lt;p&gt;After spending &lt;a href=&quot;/2010/04/06/one-week-with-a-droid-and-a-few-hours-with-an-ipad/&quot;&gt;18 months with Android&lt;/a&gt;, I am now back to an iPhone and
likely here to stay.  While Android isn't necessarily bad, it more boils
down to iPhone simply being better.  After a while, I started looking at
iPhone vs Android as largely a repeat of the Mac vs PC comparisons.&lt;/p&gt;

&lt;h3&gt;Mac vs PC&lt;/h3&gt;

&lt;p&gt;Just look at it.  Apple is doing what they've always done.  They control
the hardware and the software.  They have a solid, unified experience.
You can pick up any iPhone, old or new, and still be at home.&lt;/p&gt;

&lt;p&gt;Android is repeating the history of PCs.  Google makes the OS, as
Microsoft did with Windows.  Then OEMs offer a wide variety of different
hardware, with their own shitty customizations layered on top of the OS.
Even worse, you have the carriers layering on their customizations and
restrictions.&lt;/p&gt;

&lt;p&gt;You can go from one Android phone to another and have it
be completely foreign.  Even baseline apps can have different names and
a completely different look and feel, such between the &quot;Email&quot; vs &quot;Mail&quot; of vanilla
Android and HTC Android.&lt;/p&gt;

&lt;h3&gt;Shelf Life&lt;/h3&gt;

&lt;p&gt;With Android, the phones have a very short shelf life.  I bought a
Thunderbolt from Verizon back in April, just 6 months ago.  About a
month after I bought it, it was no longer the hot model they were
pimping.  In fact, there have been 2-3 phones to come out since then
that became &quot;king of the mountain.&quot;&lt;/p&gt;

&lt;p&gt;With iPhone, they release a new phone about once a year, and that one
stays the current phone.  Older phones are still pretty well supported.
The iPhone 3GS is over 2 years old, still got updated to iOS 5, and
likely will until iOS 6.  My original Motorola Droid that is
nearing 2 years old is pretty much forgotten already.&lt;/p&gt;

&lt;p&gt;Updates with iPhone?  Available right away to everyone.  AT&amp;amp;T or
Verizon, you get the update when Apple makes it generally available.&lt;/p&gt;

&lt;p&gt;Updates with Android?  Have fun.  Google has to release it, your OEM has
to customize it, then the carrier gets to tweak it, and decide when to
finally roll it out.  Google released Gingerbread back in December 2010,
nearly 10 months ago.  Verizon just started rolling out the update last
month, &lt;a href=&quot;http://www.gottabemobile.com/2011/10/17/htc-thunderbolt-gingerbread-update-said-to-be-returning-soon/&quot;&gt;then pulled it&lt;/a&gt;.  Even then, they decide when you can upgrade with a phased roll out.  And since it was pulled, looks like they seem to skip over adequate testing.&lt;/p&gt;

&lt;p&gt;Most Android users who want recent releases end up rooting their phones
and use unofficial ROMs put together by an informal group of people.
Have an issue with your phone?  Limited options.&lt;/p&gt;

&lt;h3&gt;Marketing&lt;/h3&gt;

&lt;p&gt;I definitely agreed with &lt;a href=&quot;http://www.slowcookedbacon.com/&quot;&gt;my friend Joe&lt;/a&gt; in his &lt;a href=&quot;http://www.slowcookedbacon.com/the-droid-bionic-shows-why-android-isnt-domin&quot;&gt;post about the Droid Bionic&lt;/a&gt;.  Android phones are being pitched like PCs.  They give a bunch of technical specs that are meaningless to consumers.  It echos the &lt;a href=&quot;http://www.ted.com/talks/simon_sinek_how_great_leaders_inspire_action.html&quot;&gt;&quot;Golden Circle&quot;&lt;/a&gt; idea by Simon Sinek.  Apple is still doing what they do best.  Verizon sells like PC manufacturers.  Lacking inspiration.&lt;/p&gt;

&lt;h3&gt;False Sense of Market Share&lt;/h3&gt;

&lt;p&gt;You've probably seen the headlines of &lt;a href=&quot;http://www.dailytech.com/Android+Outsells+iPhone+5to2+Has+Nearly+50+Percent+of+the+Market/article22326.htm&quot;&gt;&quot;Android sales outpacing
iPhone&quot;&lt;/a&gt;
or &lt;a href=&quot;http://www.dailytech.com/Android+Market+Share+Reaches+56+Percent+RIMs+Microsofts+Cut+in+Half/article22852.htm&quot;&gt;&quot;Android market share to surpass iPhone&quot;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Overall the numbers are comparing apples to oranges.  They are comparing
the sales figure of a &lt;em&gt;single phone&lt;/em&gt; to a whole &lt;em&gt;group of phones&lt;/em&gt;.
There are many different Android phones, and individually, iPhone is
spanking them in sales figures.  No single Android phone has a chance of
elipsing the iPhone or gaining any meaningful market share, especially
with their overall short shelf life.  I'd be very interested to see
sales figured of individual phones and see how long they really last.
All the manufacturers are still struggling to get a sliver of what the iPhone is capable of.&lt;/p&gt;

&lt;p&gt;The numbers may hold some weight for developers because it represents
the size of your audience.  But at the same time, Android is many phones
vs iPhones entire existence is now just 5 phones.  Less &quot;your app
doesn't work on my Verizon Droid Mumbojumbo&quot; and you don't have a Droid
Mumbojumbo to test on.&lt;/p&gt;

&lt;h3&gt;Falseness of Open&lt;/h3&gt;

&lt;p&gt;Many people tout Android as being open, however the actions of Google
with &lt;a href=&quot;http://www.businessweek.com/technology/content/mar2011/tc20110324_269784_page_2.htm&quot;&gt;Honeycomb's source code&lt;/a&gt; seem to be heading in the direction of more closed.&lt;/p&gt;

&lt;p&gt;While Google said part of their goal was to try and unify the platform
more, as Honeycomb was intended for tablets and not handsets, the
ability to control a platform is difficult while also keeping it &quot;open.&quot;
I think Google is right in closing it, since in order to further the
platform, they will need to have some control in order to maintain a
consistent direction.&lt;/p&gt;

&lt;p&gt;However, the &quot;openness&quot; usually just comes from developers.  What do most of then
define the &quot;openness&quot; as?  Being able to write apps and put them on
their phone without paying $99.  They tout the source being open, but
the truth is that isn't what they really care about.  Very few Android
developers likely dive into the OS code, they just want to install their
own apps for free.&lt;/p&gt;

&lt;p&gt;Personally, if I prefer one platform over the other, a $99 fee to build
apps isn't going to a stopper for me.  But I also
don't mind paying for the tools I use in my craft if they are worth it.&lt;/p&gt;

&lt;h3&gt;Working&lt;/h3&gt;

&lt;p&gt;Most average people care more about how well the phone works.  iPhone
simply works better.  Since software and hardware are more married, the
experience is more consistent.  In my own experience, apps crash less on
iPhone.  The phone lags less.  Scrolling and browsing is more graceful.
My wife is still on her original Droid for another month, and every day
I see her struggle with the phone.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.changewaveresearch.com/articles/2011/smart_phones_20110718.html&quot;&gt;iPhone has better customer satisfaction ratings than Android.&lt;/a&gt;  While the reasons aren't mentioned, I wouldn't be surprised that part of it stems from &quot;it just works&quot;.&lt;/p&gt;

&lt;p&gt;Apple has a strong emphasis on usability.  Google and the OEMs aren't as
much so.  This particularly stuck me with a &lt;a href=&quot;http://dinnerwithandroid.tumblr.com/post/8838035574/dual-wielding&quot;&gt;post I read&lt;/a&gt; about a guy talking to a girl who had an Android phone and an iPod Touch.  In particuar, &quot;nothing happened when I plugged it into my computer.&quot;  To the average user, the simple integration is important.  They don't know why the phone shows up as a &quot;Mass Storage Device&quot; when they plug it in.&lt;/p&gt;

&lt;h3&gt;Future&lt;/h3&gt;

&lt;p&gt;The future for Android will probable improve.  The OS is maturing and
hardware getting better, however the ecosystem of manufacturers and
carriers will likely stay the same.  The reality is that Apple is doing
what Apple has always done and they've gotten really good at it.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Cooking with Chef slides</title>
   <link href="http://invalidlogic.com//2011/07/25/cooking-with-chef-slides/"/>
   <link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" />
   <updated>2011-07-25T00:00:00-07:00</updated>
   <id>http://invalidlogic.com//2011/07/25/cooking-with-chef-slides</id>
   <content type="html">&lt;p&gt;A little late, but I have posted my slides from my talk at the &lt;a href=&quot;http://www.meetup.com/EBRuby/&quot;&gt;East Bay
Ruby Meetup&lt;/a&gt; in &lt;a href=&quot;http://www.meetup.com/EBRuby/events/16505489/&quot;&gt;June&lt;/a&gt;.&lt;/p&gt;

&lt;center&gt;&lt;div style=&quot;width:425px;margin: 10px&quot; id=&quot;__ss_8668127&quot;&gt;&lt;strong style=&quot;display:block;margin:12px 0 4px&quot;&gt;&lt;a href=&quot;http://www.slideshare.net/krobertson2/cooking-with-chef-8668127&quot; title=&quot;Cooking with Chef&quot;&gt;Cooking with Chef&lt;/a&gt;&lt;/strong&gt;&lt;object id=&quot;__sse8668127&quot; width=&quot;425&quot; height=&quot;355&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=cheftalk-110722221912-phpapp02&amp;stripped_title=cooking-with-chef-8668127&amp;userName=krobertson2&quot; /&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;/&gt;&lt;param name=&quot;allowScriptAccess&quot; value=&quot;always&quot;/&gt;&lt;embed name=&quot;__sse8668127&quot; src=&quot;http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=cheftalk-110722221912-phpapp02&amp;stripped_title=cooking-with-chef-8668127&amp;userName=krobertson2&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;425&quot; height=&quot;355&quot;&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;/center&gt;


&lt;p&gt;Check them out and feel free to ping me if there are any questions.  At
the meetup, was also talking about doing a bit of a blog series on
getting started with Chef and posting some of the scripts and baseline
setup I have used before.  Hope to start forming some simple getting started resources.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>New Opportunities</title>
   <link href="http://invalidlogic.com//2011/07/19/new-opportunities/"/>
   <link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" />
   <updated>2011-07-19T00:00:00-07:00</updated>
   <id>http://invalidlogic.com//2011/07/19/new-opportunities</id>
   <content type="html">&lt;div style=&quot;float:right; margin-left: 10px; margin-bottom: 5px&quot;&gt;&lt;img src=&quot;http://invalidlogic-blog.s3.amazonaws.com/demandbase_logo.gif&quot; width=&quot;200&quot; height=&quot;32&quot;/&gt;&lt;/div&gt;


&lt;p&gt;Finally posting about it a little bit late, but last week was my first
week in a new position with a new company.  I truly enjoyed my stay at
&lt;a href=&quot;http://www.involver.com/&quot;&gt;Involver&lt;/a&gt;, but saw an opportunity pop up and decided to take it.&lt;/p&gt;

&lt;p&gt;This new opportunity is to be one of the first in-house Ruby developers
at &lt;a href=&quot;http://www.demandbase.com&quot;&gt;Demandbase&lt;/a&gt;.  Demandbase specializes in a
B2B analytics API for reporting and logging information about visitors
hitting your business's website.&lt;/p&gt;

&lt;p&gt;That all sounds fancy, but the gist is I'll be helping to grow and form
the team, scale up and expand the platform, and able to leverage both
skillsets as a developer and in operations.  They've been working with
the awesome guys from &lt;a href=&quot;http://highgroove.com/&quot;&gt;Highgroove&lt;/a&gt;, utilizing
Chef in a continuous deployment setup, doing geographic load balancing, and have a pretty agile and
responsive process setup.&lt;/p&gt;

&lt;p&gt;I had an amazing time at Involver and grew so much personally and
professionally.  I was a part of some major projects and instrumented a
lot of change.  Our Operations team was top notch and put out of a lot
of stuff considering it was only 3 people.&lt;/p&gt;

&lt;p&gt;Going forward, have some goodies I'll hopefully be working on and open
sourcing.  There are a lot of interesting things in the works and hope
to post about them over time.&lt;/p&gt;

&lt;p&gt;And by the way, Demandbase is hiring.  Hit me up
&lt;a href=&quot;http://twitter.com/krobertson&quot;&gt;@krobertson&lt;/a&gt; or shoot me &lt;a href=&quot;http://scr.im/2e1e&quot;&gt;an email&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Announcing Gemstache</title>
   <link href="http://invalidlogic.com//2011/06/30/announcing-gemstache/"/>
   <link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" />
   <updated>2011-06-30T00:00:00-07:00</updated>
   <id>http://invalidlogic.com//2011/06/30/announcing-gemstache</id>
   <content type="html">&lt;p&gt;Pleased to announce &lt;a href=&quot;http://gemstache.com&quot;&gt;Gemstache&lt;/a&gt;, a new service to enable teams and companies to build and distribute their own private gems with security and ease of use in mind.&lt;/p&gt;

&lt;p&gt;Gems are an incredibly simple way to package up code and distribute it, making it available to multiple code bases or just a great way to encapsulate functionality.  However, the way gems are traditionally distributed doesn't lend itself well to securing the gems and controlling access.  The default &quot;gem install&quot; command you run doesn't provide any support for authentication against the gem source, so most sources are open to the public.&lt;/p&gt;

&lt;div style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;http://invalidlogic-blog.s3.amazonaws.com/2011-06-30-gemstache.png&quot; width=&quot;399&quot; height=&quot;323&quot; /&gt;&lt;/div&gt;


&lt;p&gt;Gemstache works by giving you your own private gem source you can use.  In order to download any gems from it, you must have the accompanied &quot;gemstache&quot; gem installed locally or on your servers.  When talking to your private gem source, it interlaces to add authentication to the request as well as ensuring it is happening over HTTPS.  With this, your gems are only downloaded over SSL and any interaction requires authentication.&lt;/p&gt;

&lt;p&gt;To make managing your gems easier, the gem adds the ability to easily upload a gem to your private gem source and make it available.  From your command line, just run &quot;gem stache [your gem file]&quot; and it is uploaded and ready for use.&lt;/p&gt;

&lt;p&gt;Within the service, you can give users varying roles to define whether they can just download gems, are able to publish new gems, and are able to yank/delete gems.&lt;/p&gt;

&lt;p&gt;Gemstache was born out of a need we had been facing at &lt;a href=&quot;http://www.involver.com&quot;&gt;Involver&lt;/a&gt;, where some of our own internal code is enclosed in gems and used between a few of our codebases, as well as we have some gems we have forked to either add customizations or our own fixes.  Traditional methods left them exposed and also more painstaking to release.&lt;/p&gt;

&lt;p&gt;We're just about ready to launch a public beta.  Visit &lt;a href=&quot;http://gemstache.com&quot;&gt;gemstache.com&lt;/a&gt; and sign up to be notified.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Beware of error handling with fibers in an evented context</title>
   <link href="http://invalidlogic.com//2011/05/26/beware-of-error-handling-with-fibers-in-an-evented-context/"/>
   <link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" />
   <updated>2011-05-26T00:00:00-07:00</updated>
   <id>http://invalidlogic.com//2011/05/26/beware-of-error-handling-with-fibers-in-an-evented-context</id>
   <content type="html">&lt;p&gt;One of the more interesting developments in Ruby lately has been the interesting things being done with Ruby 1.9.2, Fibers, and EventMachine.  Whether you look at it being applied to existing libraries with &lt;a href=&quot;https://github.com/mperham/rack-fiber_pool&quot;&gt;rack/fiber_pool&lt;/a&gt;, or &lt;a href=&quot;https://github.com/postrank-labs/goliath&quot;&gt;Goliath&lt;/a&gt;, it packs a punch and proving interesting for high performance evented applications.&lt;/p&gt;

&lt;p&gt;Recently when reworking one of our backend applications to use rack/fiber_pool with EventMachine, I ran into a gotcha when it came to exception handling.  Asynchronous applications makes heavy use of callbacks, where the context of when an operation is completed is not inline with when it began.  Fibers work to make it easier to write asynchronous code look like synchronous, where you make a call, and it returns a result.&lt;/p&gt;

&lt;p&gt;The problem is that this can play a trick on your eye.  You think you are executing something in line, but the context it is operating within jumps without you being necessarily aware of it.  Take the following example:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;eventmachine&amp;#39;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;em-synchrony&amp;#39;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;fiber&amp;#39;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;doit&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Fiber&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;current&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;EventMachine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add_timer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;uhh ohh&amp;#39;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;Fiber&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;yield&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;no&quot;&gt;EM&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;synchrony&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;beginning&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;doit&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;end&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Exception&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;ERROR: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;ensure&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Have a nice day&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;EventMachine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stop&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;From looking at the main block, you have the call to doit wrapped in a begin/rescue, so it seems logic that if an error was raised within it, the rescue block would capture it and handle the error.  Unfortunately, the error it being raised outside the context of the fiber, so it isn't caught.  You are outside the context of the fiber in the time between when &lt;code&gt;Fiber.yield&lt;/code&gt; is called and &lt;code&gt;f.resume&lt;/code&gt; is called.&lt;/p&gt;

&lt;p&gt;Why is this context important?  Because when we built applications, we want them to be resilient.  For instance, if a web request encounters an error, we want it caught, reported either to a log or a service, a response returned to the user, and then it be ready to handle the next request.  However outside the context of the fiber, the error handling we've built in won't get called and the application can exit.  Even if the application is monitored with god, existing connections will get closed out and connections won't be served while it is restarting, and the valuable information within the error is lost.&lt;/p&gt;

&lt;p&gt;Once the fiber is resumed, the error handling functions as expected.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;eventmachine&amp;#39;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;em-synchrony&amp;#39;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;fiber&amp;#39;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;doit&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Fiber&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;current&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;EventMachine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add_timer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;resume&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;Fiber&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;yield&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;no&quot;&gt;EM&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;synchrony&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;beginning&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;doit&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;uhh ohh&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Exception&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;ERROR: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;ensure&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Have a nice day&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;EventMachine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stop&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;In this case, the exception will be caught and handled, and you will make it to the &quot;Have a nice day&quot; message.&lt;/p&gt;

&lt;p&gt;In order to handle the error, you can add some exception handling within the main context, or the root fiber.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;EM&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;synchrony&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
      &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;beginning&amp;quot;&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;doit&lt;/span&gt;
      &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;end&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Exception&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;
      &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;ERROR: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;ensure&lt;/span&gt;
      &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Have a nice day&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;no&quot;&gt;EventMachine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stop&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Exception&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;We caught something outside a fiber!&amp;quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;However, I haven't yet figured out how to have the same thing done in the context of a web app.  So far, I've just ensured I have proper error handling in the callbacks before the fiber is resumed.  Trying to put a begin/rescue block in the config.ru doesn't seem to have any effect on rescuing an error.&lt;/p&gt;

&lt;p&gt;The moral of the story is when using fibers, be conscious of error handling outside the context of the fiber.  Unhandled exceptions there can cause the entire application to exit.  Be aware you have proper error handling when doing something that yields a fiber, and whether they fiber-enabled libraries you are using have error handling outside the context as well.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>MySQL Read/Write Splitting in JRuby</title>
   <link href="http://invalidlogic.com//2011/05/16/mysql-read-write-splitting-with-jruby/"/>
   <link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" />
   <updated>2011-05-16T00:00:00-07:00</updated>
   <id>http://invalidlogic.com//2011/05/16/mysql-read-write-splitting-with-jruby</id>
   <content type="html">&lt;p&gt;I was rather surprised about the lack of information out there about how to do read/write splitting with MySQL and Rails on JRuby.  This is a pretty key part of our infrastructure, and has been a major point of our attention when performing large platform upgrades.&lt;/p&gt;

&lt;p&gt;Having recently gone through one such upgrade and subsequent breaking of our read/write splitting, I had to dive into the code that was doing it more and get a better understanding of how it works.&lt;/p&gt;

&lt;p&gt;With JRuby, there are two things to be aware of when trying to enable read/write splitting:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does it route the queries to the right box?&lt;/li&gt;
&lt;li&gt;Does it do it without sucking all available connections up on MySQL?&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The second one sounds weird, however we have actually seen it and had it cause major issues.  I am not totally sure what to attribute it to, but somewhere between ActiveRecord, ActiveRecord-JDBC, and the MySQL JDBC driver, there is some weird connection handling going on where a connection will still be established, however viewed as dead and a new connection will be opened up.  Eventually, it just sucks up all available connections to MySQL.&lt;/p&gt;

&lt;p&gt;This is a pretty big problem, but can work around it.  Most of the existing information out there about how to do read/write splitting with ActiveRecord doesn't always apply cleanly to JRuby.  In particular with one, we ran into the connection-sucking issue while in the benchmarking process.&lt;/p&gt;

&lt;p&gt;Fortunately, there isn't a whole lot that needs to be done to enable splitting.  The MySQL JDBC driver &lt;a href=&quot;http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-replication-connection.html&quot;&gt;already has support for it&lt;/a&gt; with its ReplicationDriver, you just need to enable it when using Rails.  Then you can leverage a plugin which sets a &quot;read_only&quot; property on the raw connection when it recognizes a 'SELECT' query.  When read_only is flagged, the driver knows it can send the query to servers other than the master.&lt;/p&gt;

&lt;p&gt;Steps to configure read/write splitting:&lt;/p&gt;

&lt;h3&gt;1) Get activerecord-jdbcmysql-adapter&lt;/h3&gt;

&lt;p&gt;If you're going to use MySQL on JRuby with ActiveRecord, this is rather a given.  We're currently using v1.1.1 and happy.  All the JDBC adapters are basically rolled up in &lt;a href=&quot;https://github.com/nicksieger/activerecord-jdbc-adapter&quot;&gt;one repo&lt;/a&gt; which produces multiple gems.&lt;/p&gt;

&lt;h3&gt;2) Get my version of the active-record-jdbc-mysql-master-slave plugin&lt;/h3&gt;

&lt;p&gt;There is a plugin that takes care of setting the read_only property on the connection for 'select' queries.  The &lt;a href=&quot;https://github.com/mccraigmccraig/active-record-jdbc-mysql-master-slave&quot;&gt;original version&lt;/a&gt; of the plugin was originally written for Rails 2.2 and hasn't been updated in 2 years.  We originally used it on Rails 2.2.2 and had a lot of success with it.&lt;/p&gt;

&lt;p&gt;It doesn't work on Rails 2.3 through, primarily because of the load order changing.  It previously worked by alias_methoding the initializer on JdbcAdapter, and in its initialize, would alias_method the _execute method if using mysql.  However, load order changed in Rails 2.3 and the database connection is initialized before the plugin is loaded, causing its own version of initialize to not run.  I've &lt;a href=&quot;https://github.com/krobertson/active-record-jdbc-mysql-master-slave&quot;&gt;updated it&lt;/a&gt; to use a slightly different method to ensure it happens regardless of load order.&lt;/p&gt;

&lt;p&gt;To install the plugin, can just use ./script/plugin:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;$ ./script/plugin install git://github.com/krobertson/active-record-jdbc-mysql-master-slave.git
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h3&gt;3) Ensure active connections are reset in ActiveRecord&lt;/h3&gt;

&lt;p&gt;You can still experience some issues with stray connections.  The best way we have found to combat this is through an after filter on controllers that does some cleanup.  Add this portion to your ApplicationController:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;after_filter&lt;/span&gt;  &lt;span class=&quot;ss&quot;&gt;:clear_database_connections&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;clear_database_connections&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Base&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clear_active_connections!&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;By calling &lt;tt&gt;ActiveRecord::Base.clear_active_connections!&lt;/tt&gt;, it ensures connections are reset.  It is best to try and ensure it is the last after_filter defined.&lt;/p&gt;

&lt;h3&gt;4) Configure your database.yml&lt;/h3&gt;

&lt;p&gt;The key in the database.yml is to set up activerecord-jdbc to use MySQL's replication driver and to configure the &quot;url&quot; for it.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;erb&quot;&gt;&lt;span class=&quot;x&quot;&gt;production:&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  adapter:  jdbcmysql&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  username: myuser&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  password: secret&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;&amp;lt;%&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;vg&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=~&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;/(rake|irb)/&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;-%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  host:     masterdb&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  port:     3306&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  database: myapp&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;&amp;lt;%&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;-%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  driver:   com.mysql.jdbc.ReplicationDriver&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  url:      jdbc:mysql://masterdb:3306,slavedb:3306/myapp?roundRobinLoadBalance=false&amp;amp;autoReconnect=true&amp;amp;failOverReadOnly=true&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;&amp;lt;%&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;-%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;You may be looking at it and thinking I've got erb in my yaml... and yes.  Rails lets you mix the two, and the reason in this case is because we opt to disable the read/write splitting in the Rails console (irb) and when running rake.  Two very important reasons to. First, in console, we've had it suck up all connections just when doing simple debugging.  Not fun.  The normal adapter doesn't do it.  And second, we want it off in rake for when we deploy and it does db:migrate.  We don't want to allow replication delay in there, such as when querying the schema_migrations table.&lt;/p&gt;

&lt;p&gt;For the read/write splitting part, the bulk of the settings are in the &quot;url&quot;.  The first host specified is the master, and any others are slaves.  It is &lt;em&gt;supposed&lt;/em&gt; to support multiple slaves and have the option to load balance between them, though we found in practice it never really worked.  Instead we direct our web app and background processing to separate slaves.  After the hosts comes the database name, and the query string parameters are a number of the driver options.&lt;/p&gt;

&lt;h3&gt;How the stuff works&lt;/h3&gt;

&lt;p&gt;At first, looking at the code for the plugin seemed rather confusing.  Less than 100 lines of injecting into ActiveRecord did our read/write splitting?  But the truth is it is fairly simple, as most of the work is handled by the underlying driver (MySQL's JDBC driver).  All we really need to do is populate that read_property on the driver's connection.  Shortened up, it does this:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;alias_method&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:_execute_without_master_slave&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:_execute&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;alias_method&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:_execute&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:_execute_with_master_slave&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# if we&amp;#39;re in auto-commit mode and about to execute a select statement, &lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# then set the connection in read-only mode for the duration of&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# the query... which will permit the query to be load-balanced&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# amongst the slaves by the mysql connector/j ReplicationDriver&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;_execute_with_master_slave&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# Need to set the read_only option on the raw connection&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# to tell the underlying driver whether the request can&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# go to slaves.&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;cro&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;raw_connection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;connection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read_only&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;raw_connection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;connection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read_only&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; 
      &lt;span class=&quot;n&quot;&gt;raw_connection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;connection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;auto_commit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
      &lt;span class=&quot;no&quot;&gt;JdbcConnection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_execute_without_master_slave&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
     
  &lt;span class=&quot;k&quot;&gt;ensure&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;raw_connection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;connection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read_only&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cro&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;To sum it up, the adapter has an _execute method which does the real execution and is passed in the raw SQL.  The plugin injects itself in the middle.  First, it captures the current read_only value, because after it executes the given query, it wants to ensure it is set back to that.  Next, it sets the read_only property based on whether MySQL itself has auto_commit on and if it is a 'select' query.  It then calls the original _execute method, and after it runs, sets read_only back.&lt;/p&gt;

&lt;p&gt;The actual plugin has several additional things, like allowing you to run some statements within a block to ensure it goes to the master, and to only work with the MySQL adapter.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Transparency and status</title>
   <link href="http://invalidlogic.com//2011/04/29/transparency-and-status/"/>
   <link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" />
   <updated>2011-04-29T00:00:00-07:00</updated>
   <id>http://invalidlogic.com//2011/04/29/transparency-and-status</id>
   <content type="html">&lt;p&gt;One thing that I think can really be highlighted from the recent AWS issues is the value of a status dashboard for your platform/service..  However, simply having one isn't quite enough.  Plenty of services already do.  What really matters is how effectively it is used.&lt;/p&gt;

&lt;p&gt;Just think why a customer would be coming to your status dashboard and what they'd be looking for.  If they're coming to it, it is likely because they're having a problem.  What they'd be looking for is confirmation that the company is aware of the issue and a rough idea of when it would be fixed.&lt;/p&gt;

&lt;p&gt;This sounds quite simple and plainly put, however rarely done.  I don't know if its some management/PR intervention of not wanting to sound unstable or unreliable, or if it is just that level of transparency isn't encouraged/practiced at these companies, but simple information often never makes it public, or seems to after the fact.&lt;/p&gt;

&lt;div style=&quot;float:right; margin-top: 5px; margin-left: 10px; margin-bottom: 5px&quot;&gt;&lt;a href=&quot;http://invalidlogic-blog.s3.amazonaws.com/2011-04-28-aws-large.png&quot;&gt;&lt;img src=&quot;http://invalidlogic-blog.s3.amazonaws.com/2011-04-28-aws-small.jpg&quot; width=&quot;68&quot; height=&quot;400&quot; title=&quot;holy cow that sucker's long&quot; border=&quot;0&quot; style=&quot;border: 0&quot; /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;p&gt;One our major gripes with Amazon when we were hosted with them was how we'd become aware of an issue, but in some cases it would be hours before an &lt;em&gt;acknowledgment&lt;/em&gt; of it went onto the status dashboard.  The 1am EBS outage of last week has repeated itself before, and interestingly around 1am several times.  It affected Reddit just a month or so ago, and it affected us back in October.  One of our other guys was up at 1am, aware immediately of the EBS issue since it was impacting our master database server.  It took Amazon &lt;em&gt;two and a half hours&lt;/em&gt; to post about it on their status site, even stating it began the same time we were paged.&lt;/p&gt;

&lt;p&gt;An additional aspect often missed is the value of the post-mortem.  When you have a major issue, customers lose confidence.  The post-mortem is a chance to try and gain some of that back.  It doesn't need to divulge every single detail and shouldn't look at it as an embarrassment.  When I think of a post-mortem, I look for 3 things: what happened, why it happened, and how it won't happen again.  It can very effective at reassuring users if you can clearly show that you understand what went wrong and have a solid plan to ensure it won't happen again.  Glossing over the chance by simply saying &quot;we've fixed &lt;em&gt;it&lt;/em&gt;&quot; (without saying what &lt;em&gt;it&lt;/em&gt; is, in some fashion) can simply detract users even more.&lt;/p&gt;

&lt;p&gt;Example of a post-mortem done wrong?  Look at &lt;a href=&quot;http://staff.tumblr.com/post/2127872280/downtime&quot;&gt;Tumblr's downtime in December&lt;/a&gt; or their &lt;a href=&quot;http://staff.tumblr.com/post/3959106211/update-regarding-security-issue&quot;&gt;security leak in March&lt;/a&gt;.  Look at the majority of AWS issues.  Typically, they don't do them.  They only do them when they &lt;a href=&quot;http://aws.amazon.com/message/65648/&quot;&gt;majorly&lt;/a&gt; &lt;a href=&quot;http://status.aws.amazon.com/s3-20080720.html&quot;&gt;screw up&lt;/a&gt;.  And when they do, there is an air of &quot;architect for us&quot; attitude.&lt;/p&gt;

&lt;p&gt;Here are a few quick things that would make any status dashboard serve its purpose well.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Update early, update often.&lt;/li&gt;
&lt;li&gt;Don't downplay the severity.&lt;/li&gt;
&lt;li&gt;Give ETAs on resolutions.&lt;/li&gt;
&lt;li&gt;Be very generous with ETAs (go worst case).&lt;/li&gt;
&lt;li&gt;Choose a good layout!  Look at the image to the side for Amazon's site during their issue.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Above all though, look at the status site from the perspective of their users.  Think about why they would come there and what information they're looking for.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Talk Cloudy To Me</title>
   <link href="http://invalidlogic.com//2011/04/27/talk-cloudy-to-me/"/>
   <link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" />
   <updated>2011-04-27T00:00:00-07:00</updated>
   <id>http://invalidlogic.com//2011/04/27/talk-cloudy-to-me</id>
   <content type="html">&lt;div style=&quot;float:right; margin-top: 5px; margin-left: 10px; margin-bottom: 5px&quot;&gt;&lt;img src=&quot;http://invalidlogic-blog.s3.amazonaws.com/2011-04-27-talk-cloud.jpg&quot; width=&quot;180&quot; height=&quot;119&quot; /&gt;&lt;/div&gt;


&lt;p&gt;I will be talking at the &lt;a href=&quot;http://www.meetup.com/cloudcomputing/events/16701362/&quot;&gt;Silicon Valley Cloud Computing Meetup&lt;/a&gt; this Saturday, April 30th.  If you are interested in the topic and in the area, please come out!  So far there are about 500+ people plus registered to view panels discussing a wide variety of cloud-related topics throughout the day.&lt;/p&gt;

&lt;p&gt;I will be speaking on the panel titled &lt;strong&gt;&quot;What are public clouds still missing?&quot;&lt;/strong&gt;  Will be talking about what areas the public clouds still fall short in and where the road ahead will hopefully take us.&lt;/p&gt;

&lt;p&gt;Other speakers who will be there include notable people from VMware, including some of the &lt;a href=&quot;http://www.cloudfoundry.com/&quot;&gt;CloudFoundry&lt;/a&gt; engineers, Netflix, Cisco, Microsoft, and Rackspace.&lt;/p&gt;

&lt;p&gt;Definitely come and check it out!  Saturday starting at 1pm, hosted at the Microsoft Mountain View offices.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Amazon and what it means to you</title>
   <link href="http://invalidlogic.com//2011/04/22/amazon-and-what-it-means-to-you/"/>
   <link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" />
   <updated>2011-04-22T00:00:00-07:00</updated>
   <id>http://invalidlogic.com//2011/04/22/amazon-and-what-it-means-to-you</id>
   <content type="html">&lt;p&gt;Unless you were under a rock, you probably heard about the major issues in Amazon's US-East region yesterday.  Needless to say, a lot of businesses had a rough day yesterday.&lt;/p&gt;

&lt;p&gt;One of the most interesting aspects of yesterday was realizing how big Amazon's reach is.  Numerous well known startups and businesses were down, but beyond that, services not even on Amazon themselves were affected.  We &lt;a href=&quot;http://invalidlogic.com/2011/02/11/how-we-did-a-datacenter-migration-with-no-downtime/&quot;&gt;moved off EC2&lt;/a&gt; back in December, however we integrate with APIs from several other services, including some that are running on EC2.  We still felt the impact and were closely watching Amazon tracking status.&lt;/p&gt;

&lt;p&gt;The event lead to some interesting discussions though.&lt;/p&gt;

&lt;div style=&quot;width: 100%; text-align: center; margin: 10px 0;&quot;&gt;&lt;a href=&quot;http://twitter.com/#!/rtomayko/status/61132582489817088&quot;&gt;&lt;img src=&quot;http://invalidlogic-blog.s3.amazonaws.com/2011-04-22-rtomayko-tweet.jpg&quot; width=&quot;588&quot; height=&quot;260&quot; border=&quot;0&quot; style=&quot;border: 0&quot; /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;p&gt;There has been a lot of blame going back and forth, with some leaning on the side of &quot;you should have planned for it&quot;.  While it can be particularly harsh, in that most best practices for Amazon stressed leveraging multiple availability zones, while yesterday, it was nearly an entire region that was out.  There is an element of truth in the argument... &lt;em&gt;have a plan&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Typically that is known as a Disaster Recovery plan.  They easy to be overlooked until you realize you need one.  They're always one of those &quot;we should do that someday&quot; or maybe even something a company doesn't think its big enough to need.&lt;/p&gt;

&lt;p&gt;I am no expert on disaster recovery (and there are plenty of consultants out there to help build a professional one), but there are some pretty basic things you can look at to at least have &lt;em&gt;a plan&lt;/em&gt; rather than &lt;em&gt;no plan&lt;/em&gt;.  Some services recovered pretty well yesterday, albeit with partial functionality, but they got something back up.  Others realized they were at the mercy of another provider and were stuck until then.&lt;/p&gt;

&lt;p&gt;There are some simple questions you can begin to answer for yourself for a simple plan:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What data is important?&lt;/strong&gt;  Your service runs on code, but it is powered by data.  What data is it dependent on?  Image assets, file uploads, databases?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where does my data live, and how can I have it in multiple places?&lt;/strong&gt;  Take regular database backups and store them off site.  Keep a backup of assets.  It is important for them to be in more than one location since if that location disappears, you are SOL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How much data loss is acceptable?&lt;/strong&gt;  If stuff goes down, you may lose some data.  If you want to limit the loss, you need to keep fresher copies of data.  More frequent backups, perhaps a live DB slave hosted somewhere else.  You need to either accept that some data loss is acceptable, or architect so that you won't have any data loss.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How fast can you provision servers and where?&lt;/strong&gt;  Geo distribution all the time can be expense and not necessary (unless you deem it is), but being able to have somewhere to quickly set up emergency servers is a major plus.  If you use AWS East, then maybe use AWS West for DR.  Make sure your account limits give you enough capacity, and have scripts and basic stuff in place and ready to be used.  We leverage Chef for all our systems, so we can quickly launch some new servers and get right to work configuring them pretty quickly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is your order of priorities?&lt;/strong&gt;  A service is often comprised of many smaller components.  Know which ones are the highest priority.  Know which functionality without your app is most important.  You'll be racing against the clock and have only so many people.  This lets them focus their attention to help get core functionality up as quickly as possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do a fire drill.&lt;/strong&gt;  This is something I think we'll be doing pretty soon.  Out of the blue one day, do a mock fire drill.  You are down, your datacenter disappeared.  Get the service back up in an alternative place.  How long does it take you?  What were the pain points?  Beyond simply having a plan, you need to know the plan will work.&lt;/p&gt;

&lt;p&gt;And lastly, &lt;strong&gt;know your application&lt;/strong&gt;.  Know its requirements, constraints, and understand its bare minimums, most important pieces, etc.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Power through environments</title>
   <link href="http://invalidlogic.com//2011/04/14/power-through-environments/"/>
   <link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" />
   <updated>2011-04-14T00:00:00-07:00</updated>
   <id>http://invalidlogic.com//2011/04/14/power-through-environments</id>
   <content type="html">&lt;p&gt;At Involver, we have a pretty rich deployment environment that I think isn't very common.  It is normal to hear about places having a separate staging environment from the production environment, and sometimes having a staging and test environment.  We actually go a step further and have a total of 8 non-production environments.  They all serve different purposes, but are all heavily used.&lt;/p&gt;

&lt;p&gt;Our environments are broken up like this:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Production: duh, live stuff&lt;/li&gt;
&lt;li&gt;Staging: Used for QA, close to production, no experimental stuff, pretty good data set and history in the DB.&lt;/li&gt;
&lt;li&gt;Demo: Used for client-facing stuff that is under development.  Somewhat experimental, but expected to not be breaking or of a major impact.&lt;/li&gt;
&lt;li&gt;Perf: This environment is regularly repurposed and is used for benchmarking, testing infrastructure changes, and other large scale changes (Rails upgrades, DB upgrades, core app perf testing).&lt;/li&gt;
&lt;li&gt;Test1-5: These guys are pretty special.&lt;/li&gt;&lt;/ul&gt;


&lt;p&gt;The test environments are something special and are meant to be highly flexible.  They are used to deploy separate git branches to an environment that has all the different elements of our application fully orchestrated.  They are useful for testing volatile code, experimental code, or for performing QA on features or feature branches before the code gets merged into master.&lt;/p&gt;

&lt;p&gt;The deployment to these environments works by specifying the branch on deploy, and it will create the MySQL/Mongo databases, setup the DB schema, bootstrap the DB with some initial data, and then configure all the configuration files and even config files for other applications that it interacts with.  Each branch on each environment gets its own database.  And between deploys, the data for your branch is fully preserved.&lt;/p&gt;

&lt;p&gt;So say you deploy &quot;dev-fix-booboo&quot; to test3 for the first time.  It sets you up with a fresh dataset and are good to go.  You do your thing, then later on, someone deploys another branch.  They get their own DB, not mucking up the stuff you previously had done, and when you deploy there again, you are right back where you left off.&lt;/p&gt;

&lt;p&gt;Since they are specific to the environment too, we often times assign a long-running feature branch to an environment, so that the data used by QA sticks around more, and smaller test branches can use them here and there.&lt;/p&gt;

&lt;p&gt;The full power of these comes form:&lt;/p&gt;

&lt;ol&gt;&lt;li&gt;Flexibility.  I have a branch I want to deploy, but not much other environments.  Sweet.&lt;/li&gt;
&lt;li&gt;Some element of persistence.  I can use it for a few days, come back, and be right where I left off.  No risk of someone polluting my stuff with bad data.&lt;/li&gt;
&lt;li&gt;QA can actually deploy to them and pick which is available.  For non-feature branch testing, this gives them great flexibility.&lt;/li&gt;&lt;/ol&gt;


&lt;p&gt;Of course, there are still some pitfalls:&lt;/p&gt;

&lt;ol&gt;&lt;li&gt;They don't mirror the full production setup.  They're usually one box and not spec'd for any kind of load.  They run good, but not going to handle lots of people.  Can't perf test here.&lt;/li&gt;
&lt;li&gt;There is the data persistence between switching branches, but often no rich DB history.  It is harder to test large datasets of legacy type setups.&lt;/li&gt;
&lt;li&gt;Can't test infrastructure changes.  If deploys don't switch out gems or system configs, so harder if you want to test a change like that, you need to lock the environment til done.&lt;/li&gt;&lt;/ol&gt;


&lt;p&gt;All of this makes for a very flexible deployment process.  It allows devs to easily get code off of their machines and in a more controlled environment.  It allows us to have high confidence in code before it makes it to master and often even before the feature branch.  It also allows QA to do their testing without potentially deploying code they reject to staging or demo, where it might be customer facing or impact other development.&lt;/p&gt;

&lt;p&gt;Big props for it go to &lt;a href=&quot;http://twitter.com/mikewadhera&quot;&gt;@mikewadhera&lt;/a&gt;, who initially wrote the deployment process for it.  Since then, we (infra/ops team) have worked on making the environments single-system, which allow us to have more of them, as well as iterate on making them more streamlined with developer and QA feedback.&lt;/p&gt;

&lt;p&gt;This kind of builds up to something I'll be talking about soon too.  Since we have a total of 9 different environments, this can lead to a very interesting chef workflow.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Serving Static Content Via POST From Nginx</title>
   <link href="http://invalidlogic.com//2011/04/12/serving-static-content-via-post-from-nginx/"/>
   <link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" />
   <updated>2011-04-12T00:00:00-07:00</updated>
   <id>http://invalidlogic.com//2011/04/12/serving-static-content-via-post-from-nginx</id>
   <content type="html">&lt;p&gt;Recently, a change was made on Facebook's end where their &amp;lt;fb:iframe&gt; FBML tag started doing POST request to get content.  Their documentation seemed to indicate their &quot;Post for Canvas&quot; change wouldn't affect the &amp;lt;fb:iframe&gt; tag, however our error logs spoke quite to the contrary.  We saw an influx in errors in places where we used &amp;lt;fb:iframe&gt; to pull in static content.  Nginx would simply return a 405 error for &quot;Method Not Allowed&quot;.  Nginx can't serve static content on a POST request.&lt;/p&gt;

&lt;p&gt;Some quick googling seems to reveal some quick answers, but the problem is none of them worked.&lt;/p&gt;

&lt;p&gt;The most popular, &lt;a href=&quot;http://forum.nginx.org/read.php?2,2414,47301&quot;&gt;this thread&lt;/a&gt;, talks about a work around by manipulating the error page for nginx.  First, there is some mixed syntax depending on the nginx version.  Some references seem to be to old 2007 syntax which doesn't work on the nginx 0.7 build we use.  But they all indicated that this &lt;em&gt;should&lt;/em&gt; have worked:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;nginx&quot;&gt;&lt;span class=&quot;k&quot;&gt;error_page&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;405&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;@405&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;location&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;@405&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kn&quot;&gt;root&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This basically tells nginx to change the response code to 200 for 405 messages, and to use the @405 location entry to handle it.  Setting the root it is supposed to pull the requested document.  It didn't work though.  At best, I got it to return a 200 code, but no response body.  Essentially, it was still doing a POST request and it still didn't like it.&lt;/p&gt;

&lt;p&gt;I could however, get it to be served by proxying it to our Rails application, if I enabled serving static content from Rails.  But that was less than ideal.&lt;/p&gt;

&lt;p&gt;But then, I was scanning through nginx's &lt;a href=&quot;http://wiki.nginx.org/HttpProxyModule&quot;&gt;proxy documentation&lt;/a&gt; and found what seemed like an ideal solution.  I could configure nginx to serve static content on another port, have the main server proxy it to the other port, and when proxying, change it into a GET request:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;nginx&quot;&gt;&lt;span class=&quot;k&quot;&gt;upstream&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;static_backend&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kn&quot;&gt;server&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;localhost&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;89&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;server&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kn&quot;&gt;...&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;error_page&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;405&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;@405&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kn&quot;&gt;location&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;@405&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;root&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;proxy_method&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;GET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;proxy_pass&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://static_backend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# POST STATIC CONTENT&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;server&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kn&quot;&gt;listen&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;89&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kn&quot;&gt;server_name&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kn&quot;&gt;root&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</content>
 </entry>
 
 
</feed>
