<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Gerhard Lazu web feed</title>
 <link href="http://gerhardlazu.com/atom.xml" rel="self"/>
 <link href="http://gerhardlazu.com/"/>
 <updated>2011-10-04T23:33:55+01:00</updated>
 <id>http://gerhardlazu.com/</id>
 <author>
   <name>Gerhard Lazu</name>
   <email>gerhard@lazu.co.uk</email>
 </author>
 
 
 <entry>
   <title>Deploy a Ruby application with Capistrano, rvm & bundler</title>
   <link href="http://gerhardlazu.com/2011/09/deploy-ruby-with-capistrano-bundler-rvm"/>
   <updated>2011-09-12T00:00:00+01:00</updated>
   <id>http://gerhardlazu.com/2011/09/deploy-ruby-with-capistrano-bundler-rvm</id>
   <content type="html">&lt;h2 id='the_wastelands_of_sysadminia'&gt;The wastelands of &amp;#8220;sysadminia&amp;#8221;&lt;/h2&gt;

&lt;p&gt;If you want to get your code out there, you - as a developer - need to match your most fierce adversary: the &amp;#8220;sysadmin&amp;#8221;. It can&amp;#8217;t be done from the comfort of your shiny Mac development environment, you need to go out in the wastelands of &amp;#8220;sysadminia&amp;#8221; where the fans howls 24/7 and sysadmins roam with their mighty htop, tmux and pkill. There will be no clever plugins, no IDEs, no snippets, just plain text. You will need an ally.&lt;/p&gt;

&lt;p&gt;There are 2 weapons in particular which make all the conventional sysadmin tools look cheap in comparison: Chef and Puppet. You should pick one and make it your horse: it will make a life and death difference in the wastelands. Both of them are fine choices, go with whatever makes you most comfortable, but know this: Chef comes with a knife. I don&amp;#8217;t use it myself, true men fight with their bare hands, but just in case you&amp;#8217;re a stabby proc -&amp;gt; person, it will suit you.&lt;/p&gt;

&lt;p&gt;So let&amp;#8217;s assume that you&amp;#8217;ve chosen Chef, your chances are already looking good. Preparation is everything, so let&amp;#8217;s pick up some gear first.&lt;/p&gt;

&lt;h2 id='githubia'&gt;Githubia&lt;/h2&gt;

&lt;p&gt;The best place for finding the most awesome gear is &lt;a href='https://github.com/search?&amp;amp;q=chef-cookbooks&amp;amp;type=Repositories'&gt;Githubia&lt;/a&gt;. It&amp;#8217;s a world of magic with unicorns and eternal queues. Some say that when developers die, they all hope to end up in this land of magic.&lt;/p&gt;

&lt;p&gt;I will pick the &lt;a href='https://github.com/gchef/rvm-cookbook'&gt;RVM&lt;/a&gt; &amp;amp; &lt;a href='https://github.com/gchef/bootstrap-cookbook'&gt;bootstrap&lt;/a&gt; cookbooks.&lt;/p&gt;

&lt;p&gt;Once you have those 2 cookbooks, this is a sample role which configures a server with rvm, latest Ruby 1.9.2 and sets up a new user under which we&amp;#8217;ll deploy our Ruby app.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='nb'&gt;name&lt;/span&gt;          &lt;span class='s2'&gt;&amp;quot;ruby_apps&amp;quot;&lt;/span&gt;
&lt;span class='n'&gt;description&lt;/span&gt;   &lt;span class='s2'&gt;&amp;quot;Ruby Apps&amp;quot;&lt;/span&gt;
&lt;span class='n'&gt;run_list&lt;/span&gt;      &lt;span class='s2'&gt;&amp;quot;recipe[build-essential]&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
              &lt;span class='s2'&gt;&amp;quot;recipe[git]&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
              &lt;span class='s2'&gt;&amp;quot;recipe[ssh]&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
              &lt;span class='s2'&gt;&amp;quot;recipe[sudo]&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
              &lt;span class='s2'&gt;&amp;quot;recipe[bootstrap]&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
              &lt;span class='s2'&gt;&amp;quot;recipe[bootstrap::users]&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
              &lt;span class='s2'&gt;&amp;quot;recipe[rvm]&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
              &lt;span class='s2'&gt;&amp;quot;recipe[rvm::users]&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
              &lt;span class='s2'&gt;&amp;quot;recipe[bootstrap::ruby_apps]&amp;quot;&lt;/span&gt;

&lt;span class='n'&gt;default_attributes&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;
  &lt;span class='ss'&gt;:ssh&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='ss'&gt;:password_authentication&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;no&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='ss'&gt;:permit_root_login&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;no&amp;quot;&lt;/span&gt;
  &lt;span class='p'&gt;},&lt;/span&gt;
  &lt;span class='ss'&gt;:sudo&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='ss'&gt;:groups&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;admin&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='ss'&gt;:users&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;ubuntu&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='c1'&gt;# the default sudo user on Ubuntu-based EC2 AMIs&lt;/span&gt;
  &lt;span class='p'&gt;},&lt;/span&gt;
  &lt;span class='ss'&gt;:bootstrap&lt;/span&gt;&lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='ss'&gt;:users&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
      &lt;span class='ss'&gt;:gerhard&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='ss'&gt;:admin&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='kp'&gt;true&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
        &lt;span class='ss'&gt;:deploy&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='kp'&gt;true&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
        &lt;span class='ss'&gt;:keys&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='o'&gt;[&lt;/span&gt;
          &lt;span class='s2'&gt;&amp;quot;my-sha-is-longer-than-your-sha&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
        &lt;span class='o'&gt;]&lt;/span&gt;
      &lt;span class='p'&gt;}&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
  &lt;span class='p'&gt;},&lt;/span&gt;
  &lt;span class='ss'&gt;:rvm_rubies&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;1.9.2&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
  &lt;span class='ss'&gt;:ruby_apps&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;rubyapp&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;
&lt;span class='p'&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The other cookbooks are mostly taken from the &lt;a href='https://github.com/gchef'&gt;gchef repository&lt;/a&gt;, everything else comes from &lt;a href='https://github.com/opscode/cookbooks'&gt;opscode cookbooks&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id='lets_make_sysadmins_drool_over_our_deploys'&gt;Let&amp;#8217;s make sysadmins drool over our deploys&lt;/h2&gt;

&lt;p&gt;Once you cook your server with the above role, it will be all set up for deploying. Before we go to the deployment files, pick some good hints from this abridged &lt;code&gt;~/.ssh/config&lt;/code&gt; file:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='c'&gt;# to prevent SSH connections timing out. This will poll the server every 60&amp;quot;.&lt;/span&gt;
ServerAliveInterval 60
ServerAliveCountMax 3
&lt;span class='c'&gt;# use my local SSH key to authenticate on the remote hosts (when tunelling)&lt;/span&gt;
ForwardAgent yes

Host ec2-rubyapp
  Hostname ec2-50-19-201-63.compute-1.amazonaws.com &lt;span class='c'&gt;# deploying to the cloud FTW!&lt;/span&gt;
  User gerhard &lt;span class='c'&gt;# it will default to your username if omitted&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Here&amp;#8217;s a &lt;code&gt;deploy.rb&lt;/code&gt;, taken from a production app.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='c1'&gt;# makes the output nice and colourful&lt;/span&gt;
&lt;span class='c1'&gt;# gem &amp;#39;capistrano_colors&amp;#39;&lt;/span&gt;
&lt;span class='nb'&gt;require&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;capistrano_colors&amp;quot;&lt;/span&gt;

&lt;span class='n'&gt;default_run_options&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='ss'&gt;:pty&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='kp'&gt;true&lt;/span&gt;  &lt;span class='c1'&gt;# Must be set for the password prompt from git to work&lt;/span&gt;
&lt;span class='n'&gt;ssh_options&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='ss'&gt;:forward_agent&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='kp'&gt;true&lt;/span&gt;

&lt;span class='n'&gt;set&lt;/span&gt; &lt;span class='ss'&gt;:application&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;rubyapp&amp;quot;&lt;/span&gt;
&lt;span class='n'&gt;set&lt;/span&gt; &lt;span class='ss'&gt;:repository&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;  &lt;span class='s2'&gt;&amp;quot;git@github.com:gerhard/&lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;.git&amp;quot;&lt;/span&gt;
&lt;span class='n'&gt;set&lt;/span&gt; &lt;span class='ss'&gt;:user&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;application&lt;/span&gt;
&lt;span class='n'&gt;set&lt;/span&gt; &lt;span class='ss'&gt;:use_sudo&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='kp'&gt;false&lt;/span&gt;
&lt;span class='n'&gt;set&lt;/span&gt; &lt;span class='ss'&gt;:default_shell&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;/bin/bash&amp;quot;&lt;/span&gt; &lt;span class='c1'&gt;# required for rvm scripts to work properly&lt;/span&gt;

&lt;span class='n'&gt;server&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;ec2-rubyapp&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:app&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:web&lt;/span&gt;

&lt;span class='n'&gt;set&lt;/span&gt; &lt;span class='ss'&gt;:scm&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:git&lt;/span&gt;
&lt;span class='n'&gt;set&lt;/span&gt; &lt;span class='ss'&gt;:branch&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;master&amp;quot;&lt;/span&gt;
&lt;span class='n'&gt;set&lt;/span&gt; &lt;span class='ss'&gt;:deploy_via&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:remote_cache&lt;/span&gt;
&lt;span class='n'&gt;set&lt;/span&gt; &lt;span class='ss'&gt;:deploy_to&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;/home/&lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;&lt;/span&gt;
&lt;span class='n'&gt;set&lt;/span&gt; &lt;span class='ss'&gt;:keep_releases&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;10&lt;/span&gt;

&lt;span class='n'&gt;set&lt;/span&gt; &lt;span class='ss'&gt;:myself&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='sb'&gt;`whoami`&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;chomp&lt;/span&gt; &lt;span class='c1'&gt;# if more users have the same user on the server,&lt;/span&gt;
&lt;span class='c1'&gt;# with deploy privileges and ssh keys set up properly, they can deploy!&lt;/span&gt;
&lt;span class='n'&gt;set&lt;/span&gt; &lt;span class='ss'&gt;:rvm_path&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;/usr/local/rvm/scripts/rvm&amp;quot;&lt;/span&gt;

&lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;close_sessions&lt;/span&gt;
  &lt;span class='n'&gt;sessions&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;values&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;each&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='o'&gt;|&lt;/span&gt;&lt;span class='n'&gt;session&lt;/span&gt;&lt;span class='o'&gt;|&lt;/span&gt; &lt;span class='n'&gt;session&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;close&lt;/span&gt; &lt;span class='p'&gt;}&lt;/span&gt;
  &lt;span class='n'&gt;sessions&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;clear&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;

&lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;with_user&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;new_user&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='o'&gt;&amp;amp;&lt;/span&gt;&lt;span class='n'&gt;block&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
  &lt;span class='n'&gt;initial_user&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;user&lt;/span&gt;
  &lt;span class='n'&gt;set&lt;/span&gt; &lt;span class='ss'&gt;:user&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;new_user&lt;/span&gt;
  &lt;span class='n'&gt;close_sessions&lt;/span&gt;
  &lt;span class='k'&gt;yield&lt;/span&gt;
  &lt;span class='n'&gt;set&lt;/span&gt; &lt;span class='ss'&gt;:user&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;initial_user&lt;/span&gt;
  &lt;span class='n'&gt;close_sessions&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And now for the &lt;code&gt;Capfile&lt;/code&gt; where all the magic happens. It assumes that you are using &lt;a href='https://github.com/ddollar/foreman'&gt;foreman&lt;/a&gt; for managing your app processes. If you&amp;#8217;re not using it already, drop everything and get it set up straight away: &lt;a href='http://blog.daviddollar.org/2011/05/06/introducing-foreman.html'&gt;David - the creator himself - introduces Foreman&lt;/a&gt;.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='nb'&gt;load&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;deploy&amp;#39;&lt;/span&gt; &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='nb'&gt;respond_to?&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='ss'&gt;:namespace&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='c1'&gt;# cap2 differentiator&lt;/span&gt;
&lt;span class='nb'&gt;load&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;config/deploy&amp;#39;&lt;/span&gt; &lt;span class='c1'&gt;# remove this line to skip loading any of the default tasks&lt;/span&gt;

&lt;span class='n'&gt;namespace&lt;/span&gt; &lt;span class='ss'&gt;:deploy&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt;
  &lt;span class='n'&gt;task&lt;/span&gt; &lt;span class='ss'&gt;:stop&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:roles&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='ss'&gt;:app&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:except&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='ss'&gt;:no_release&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='kp'&gt;true&lt;/span&gt; &lt;span class='p'&gt;}&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt;
    &lt;span class='n'&gt;with_user&lt;/span&gt; &lt;span class='n'&gt;myself&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt;
      &lt;span class='n'&gt;run&lt;/span&gt; &lt;span class='o'&gt;[&lt;/span&gt;
        &lt;span class='s2'&gt;&amp;quot;sudo [ -f /etc/init/&lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;.conf ]&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
        &lt;span class='s2'&gt;&amp;quot;[ $(sudo status &lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt; | grep -c running) -eq 1 ]&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
        &lt;span class='s2'&gt;&amp;quot;sudo stop &lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt; || exit 0&amp;quot;&lt;/span&gt;
      &lt;span class='o'&gt;].&lt;/span&gt;&lt;span class='n'&gt;join&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot; &amp;amp;&amp;amp; &amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;

  &lt;span class='n'&gt;task&lt;/span&gt; &lt;span class='ss'&gt;:generate_upstart&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:roles&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='ss'&gt;:app&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:except&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='ss'&gt;:no_release&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='kp'&gt;true&lt;/span&gt; &lt;span class='p'&gt;}&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt;
    &lt;span class='n'&gt;with_user&lt;/span&gt; &lt;span class='n'&gt;myself&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt;
      &lt;span class='n'&gt;run&lt;/span&gt; &lt;span class='o'&gt;[&lt;/span&gt;
        &lt;span class='s2'&gt;&amp;quot;source ~/.profile&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
        &lt;span class='s2'&gt;&amp;quot;cd &lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;current_release&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
        &lt;span class='s2'&gt;&amp;quot;bundle exec foreman export upstart /tmp -u &lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt; -a &lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
        &lt;span class='s2'&gt;&amp;quot;sudo [ -f /etc/init/&lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;.conf ] || exit 0&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
        &lt;span class='s2'&gt;&amp;quot;sudo rm /etc/init/&lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;*.conf&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
      &lt;span class='o'&gt;].&lt;/span&gt;&lt;span class='n'&gt;join&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot; &amp;amp;&amp;amp; &amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
      &lt;span class='n'&gt;run&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;sudo mv /tmp/&lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;*.conf /etc/init/&amp;quot;&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;

  &lt;span class='n'&gt;task&lt;/span&gt; &lt;span class='ss'&gt;:start&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:roles&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='ss'&gt;:app&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:except&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='ss'&gt;:no_release&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='kp'&gt;true&lt;/span&gt; &lt;span class='p'&gt;}&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt;
    &lt;span class='n'&gt;with_user&lt;/span&gt; &lt;span class='n'&gt;myself&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt;
      &lt;span class='n'&gt;run&lt;/span&gt; &lt;span class='o'&gt;[&lt;/span&gt;
        &lt;span class='s2'&gt;&amp;quot;sudo [ -f /etc/init/&lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;.conf ]&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
        &lt;span class='s2'&gt;&amp;quot;[ $(sudo status &lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt; | grep -c running) -eq 0 ]&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
        &lt;span class='s2'&gt;&amp;quot;sudo start &lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;&lt;/span&gt;
      &lt;span class='o'&gt;].&lt;/span&gt;&lt;span class='n'&gt;join&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot; &amp;amp;&amp;amp; &amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;

  &lt;span class='n'&gt;task&lt;/span&gt; &lt;span class='ss'&gt;:restart&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:roles&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='ss'&gt;:app&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:except&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='ss'&gt;:no_release&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='kp'&gt;true&lt;/span&gt; &lt;span class='p'&gt;}&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt;
    &lt;span class='n'&gt;stop&lt;/span&gt;
    &lt;span class='n'&gt;generate_upstart&lt;/span&gt;
    &lt;span class='n'&gt;start&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;

&lt;span class='n'&gt;task&lt;/span&gt; &lt;span class='ss'&gt;:ensure_permissions&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt;
  &lt;span class='n'&gt;run&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;chmod g-w &lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;deploy_to&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;span class='n'&gt;after&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;deploy:setup&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:ensure_permissions&lt;/span&gt;
&lt;span class='n'&gt;after&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;deploy:update&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:ensure_permissions&lt;/span&gt;

&lt;span class='n'&gt;task&lt;/span&gt; &lt;span class='ss'&gt;:bundle&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt;
  &lt;span class='n'&gt;run&lt;/span&gt; &lt;span class='o'&gt;[&lt;/span&gt;
    &lt;span class='s2'&gt;&amp;quot;source &lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;rvm_path&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt; &amp;amp;&amp;amp; cd &lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;release_path&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt; &amp;amp;&amp;amp;&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='s2'&gt;&amp;quot;bundle install&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='s2'&gt;&amp;quot;--gemfile &lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;release_path&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;/Gemfile&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='s2'&gt;&amp;quot;--path &lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;shared_path&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;/bundle&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='s2'&gt;&amp;quot;--deployment --quiet&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='s2'&gt;&amp;quot;--without development test&amp;quot;&lt;/span&gt;
  &lt;span class='o'&gt;].&lt;/span&gt;&lt;span class='n'&gt;join&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot; &amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;span class='n'&gt;after&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;deploy:finalize_update&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:bundle&lt;/span&gt;

&lt;span class='n'&gt;after&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;deploy:update&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;deploy:cleanup&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I&amp;#8217;m making use of upstart (running on Ubuntu, aren&amp;#8217;t you?!?), bundler &amp;amp; rvm, everything just works. Chef takes care of all the burden related to getting system-wide rvm to play nicely with user shell profiles. I&amp;#8217;m using bash on the server and defining it explicitly in Capistrano. Trying to make the default Capistrano &lt;code&gt;sh&lt;/code&gt; shell option work properly with rvm is guaranteed to make your blood boil, I prefer to play with unicorns and rainbows instead.&lt;/p&gt;

&lt;p&gt;It might not be the most elegant solution, but it works. Everything is nice and straightforward, tasks are pretty self explanatory and can be tweaked to your own taste. Go on then, try some painless deploys, the feeling is awesome!&lt;/p&gt;

&lt;h2 id='update'&gt;UPDATE&lt;/h2&gt;

&lt;p&gt;I came across Tom&amp;#8217;s gem after getting this deploy strategy in place, his &lt;a href='https://github.com/tomafro/tomafro-deploy'&gt;tomafro-deploy&lt;/a&gt; gem is definitely worth checking out.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>2011 Resolutions</title>
   <link href="http://gerhardlazu.com/2011/01/2011-resolutions"/>
   <updated>2011-01-01T00:00:00+00:00</updated>
   <id>http://gerhardlazu.com/2011/01/2011-resolutions</id>
   <content type="html">&lt;h2 id='be_more_pragmatic'&gt;Be more pragmatic&lt;/h2&gt;

&lt;p&gt;Take this blog for example. I had the new version done for January 2010. A year has gone by while I kept switching between Nesta, Toto, Padrino and Sinatra, yet the blog was still not live! Now I&amp;#8217;m running on &lt;a href='https://github.com/mojombo/jekyll'&gt;Jekyll&lt;/a&gt;, I can now focus on content and experiment with newer, better options as time permits.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Get shit done, then iterate&lt;/em&gt;&lt;/p&gt;

&lt;h2 id='lose_12kg_or_25lbs'&gt;Lose 12kg (or 25lbs)&lt;/h2&gt;

&lt;p&gt;I cycle as much as 150 miles every week, daily commute being 30 miles, but my appetite rivals a hyppo&amp;#8217;s. December is not a good month for exercising anyways, you tend to stay around the house more, shop more and indulge in all sorts of treats. A little baby limits your activities a lot, so it all adds up. I also have a sweet tooth, so when you combine that with a desk job, you gain lots of pounds, very quickly. That being said, I&amp;#8217;m making this my top priority for 2011. After all, I have a honeymoon to look forward to.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stop eating shit, work out more&lt;/em&gt;&lt;/p&gt;

&lt;h2 id='switch_to_vim'&gt;Switch to vim&lt;/h2&gt;

&lt;p&gt;I have been using Textmate for years now, I&amp;#8217;ve only played with vim briefly, most of it was in my gap between Macs. I had an older desktop which made a snazzy little Linux development machine, vim was the only serious text editor. There is gedit that comes close to Textmate, but vim is the benchmark on Linux. Yes emacs is the dog&amp;#8217;s nuts also, but I just don&amp;#8217;t get it, so there, flame war avoided.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Don&amp;#8217;t take shit from your text editor, make it bend like a porn star&lt;/em&gt;&lt;/p&gt;

&lt;h2 id='become_a_british_citizen'&gt;Become a British citizen&lt;/h2&gt;

&lt;p&gt;I have been living in the UK for over 7 years now, I can see myself living here for many more. I got married here, my baby boy was born here, I am working in London with awesome people, there&amp;#8217;s no real reason to want to go anywhere else. It is said that it takes about 7 years for every single cell in the human body to get regenerated, so since all of them are British in mine, it&amp;#8217;s time to get the paperwork done.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Don&amp;#8217;t accept bullshit, do the honourable thing&lt;/em&gt;&lt;/p&gt;

&lt;h2 id='bring_out_glz_custom_fields_v20'&gt;Bring out glz_custom_fields v2.0&lt;/h2&gt;

&lt;p&gt;For those that don&amp;#8217;t know, I&amp;#8217;ve written this plugin for &lt;a href='http://textpattern.com'&gt;Textpattern&lt;/a&gt; in autumn 2007 and it had stellar success. It a nutshell, it turbo charges custom fields. If articles are regarded as objects, custom fields would be their properties. &lt;a href='https://github.com/gerhard/glz_custom_fields_public'&gt;glz_custom_fields&lt;/a&gt; is a super stable plugin which powers &lt;strong&gt;a lot&lt;/strong&gt; of websites. Adding new features to a mature, untested and fairly complex PHP script is not something I look forward to. I have been considering various approaches, I am planning to start work on the new major version early this year. With a bit of luck, it will be ready for TXP 5.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Reinvent some legacy code and make it shit hot&lt;/em&gt;&lt;/p&gt;

&lt;h2 id='take_our_honeymoon'&gt;Take our honeymoon&lt;/h2&gt;

&lt;p&gt;Having a baby &lt;strong&gt;is&lt;/strong&gt; a big deal, more so if you live away from all your family. We wanted to tackle the big task first, we knew that the honeymoon will be appreciated even more after the baby. We still have almost another year to go, but boy are we looking forward to it! The expectations are not high, we just want to get away from the daily baby ruled routines and soak in some sun and warm, white sand with turquoise, crystal clear water. Cuba, you cannot come soon enough!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Take a break from cleaning shit, go on an awesome holiday&lt;/em&gt;&lt;/p&gt;

&lt;h2 id='release_my_own_ruby_app'&gt;Release my own Ruby app&lt;/h2&gt;

&lt;p&gt;Everything that I&amp;#8217;ve been doing for the past 3 years will converge in this one app. I&amp;#8217;ve been working on various aspects of it for over a year now, it should be all coming together nicely in 2011. I don&amp;#8217;t want it to become a cash cow or my retirement fund. It&amp;#8217;s something that I enjoy doing and would like to continue working on in my spare time. If others will find it useful, I&amp;#8217;ll be glad, if not, my life will be better having it, and that&amp;#8217;s all that matters.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stop dreaming shit, this is it, make it work&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That&amp;#8217;s me for 2011, what about you?&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Using Chef to manage Amazon EC2 instances, Part 2</title>
   <link href="http://gerhardlazu.com/2010/08/using-chef-to-manage-amazon-ec2-instances-part2"/>
   <updated>2010-08-11T00:00:00+01:00</updated>
   <id>http://gerhardlazu.com/2010/08/using-chef-to-manage-amazon-ec2-instances-part2</id>
   <content type="html">&lt;p&gt;Now that Amazon &lt;span class=&quot;caps&quot;&gt;AWS&lt;/span&gt; authentication is out of the way and Chef client is set up locally, let&amp;#8217;s create our first EC2 instance.&lt;/p&gt;
&lt;p&gt;I am only interested in &lt;a href=&quot;http://uec-images.ubuntu.com/&quot;&gt;Ubuntu AMIs&lt;/a&gt;. I&amp;#8217;ll set up &lt;a href=&quot;http://aws.amazon.com/ec2/instance-types/&quot;&gt;the smallest available instance&lt;/a&gt; for testing, I&amp;#8217;ll choose US East &amp;amp; Lucid Lynx 10.04 &lt;span class=&quot;caps&quot;&gt;LTS&lt;/span&gt; 32bit (all reflected in the &lt;span class=&quot;caps&quot;&gt;AMI&lt;/span&gt; id). I am also going to choose my availability zone by using the &lt;code&gt;-Z&lt;/code&gt; option. This comes in handy for when you get the &lt;strong&gt;Availability Zone Error&lt;/strong&gt;.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;knife ec2 server create -i ami-5ca44e35 -f m1.small -S ec2-keypair -Z us-east-1a
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;&lt;em&gt;Small EC2 instances are 32bit only&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I could have created a new EC2 instance with &lt;code&gt;ec2-run-instances&lt;/code&gt; as well, but I will be using &lt;code&gt;knife&lt;/code&gt; as much as I can because it holds the secret to eternal sysadmin nirvana.&lt;/p&gt;
&lt;p&gt;Now that the server is created, let&amp;#8217;s set up chef-client and register it with our Opscode platform user.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;knife bootstrap &amp;lt;ec2-public-ip-address&amp;gt; -N my-first-ec2-instance -x ubuntu --sudo
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;You&amp;#8217;ll be shown the public IP after the server is created. I&amp;#8217;m giving my new instance a name &lt;code&gt;my-first-ec2-instance&lt;/code&gt;, I&amp;#8217;m logging in as the &lt;code&gt;ubuntu&lt;/code&gt; user (root is disabled by default), and I&amp;#8217;m running all commands as &lt;code&gt;sudo&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;After the above is finished, let&amp;#8217;s see what we have:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;knife node list
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;
  &lt;span class=&quot;s2&quot;&gt;&amp;quot;my-first-ec2-instance&amp;quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Congratulations, you&amp;#8217;ve created your first EC2 instance without breaking a sweat!&lt;/p&gt;
&lt;h2&gt;Your chef cookbooks&lt;/h2&gt;
&lt;p&gt;We know that &lt;code&gt;knife&lt;/code&gt; is the bees knees. But how do you use it with your EC2 instance and available cookbooks?&lt;/p&gt;
&lt;p&gt;I am assuming that you have followed the &lt;a href=&quot;https://opscode.tenderapp.com/faqs/start&quot;&gt;Getting Started with Chef&lt;/a&gt; tutorial closely. If you have, you should have your &lt;code&gt;chef-repo&lt;/code&gt; locally and &lt;code&gt;knife&lt;/code&gt; configured. Let&amp;#8217;s get some relatively simple cookbooks: &lt;a href=&quot;https://github.com/papercavalier/mongodb-cookbook&quot;&gt;MongoDB&lt;/a&gt; &amp;amp; &lt;a href=&quot;https://github.com/papercavalier/redis-cookbook&quot;&gt;Redis&lt;/a&gt;. Unpack and place them in your &lt;code&gt;cookbooks&lt;/code&gt; folder, then upload them to your Opscode platform user:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;knife cookbook upload redis
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;knife cookbook upload mongodb
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Let&amp;#8217;s create a new role for our EC2. We create a new file &lt;code&gt;roles/master-db.json&lt;/code&gt; containing:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;s2&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;master-db&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;s2&quot;&gt;&amp;quot;default_attributes&amp;quot;&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;s2&quot;&gt;&amp;quot;chef&amp;quot;&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;s2&quot;&gt;&amp;quot;server_url&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;https://api.opscode.com/organizations/&amp;lt;your-organization&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;s2&quot;&gt;&amp;quot;cache_path&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;/var/chef/cache&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;s2&quot;&gt;&amp;quot;backup_path&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;/var/chef/backup&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;s2&quot;&gt;&amp;quot;validation_client_name&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;lt;your-validator&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;s2&quot;&gt;&amp;quot;run_path&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;/var/chef&amp;quot;&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;s2&quot;&gt;&amp;quot;json_class&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Chef::Role&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;s2&quot;&gt;&amp;quot;run_list&amp;quot;&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;s2&quot;&gt;&amp;quot;recipe[redis::source]&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s2&quot;&gt;&amp;quot;recipe[mongodb::source]&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
  &lt;span class=&quot;s2&quot;&gt;&amp;quot;description&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Master DB&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;s2&quot;&gt;&amp;quot;chef_type&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;role&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;s2&quot;&gt;&amp;quot;override_attributes&amp;quot;&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;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;Upload the role, then assign it to your new EC2 instance:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;knife role from file roles/master-db.json
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;knife node run_list add my-first-ec2-instance &lt;span class=&quot;s2&quot;&gt;&amp;quot;role[master-db]&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Log into your EC2 instance, &lt;em&gt;change your ubuntu user password&lt;/em&gt; and run chef-client as sudo:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ssh ubuntu@ec2-xxx.compute-1.amazonaws.com
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;sudo -i
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;passwd ubuntu
&amp;lt;mysupersecurepassword&amp;gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;exit&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;sudo chef-client
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;And that&amp;#8217;s it! Your new Amazon EC2 instance now has a very recent MongoDB &amp;amp; Redis set up.&lt;/p&gt;
&lt;p&gt;If you want to modify any cookbooks, copy the entire cookbook into your &lt;code&gt;site-cookbooks&lt;/code&gt; folder and get hacking.&lt;/p&gt;
&lt;h2&gt;Cleaning up&lt;/h2&gt;
&lt;p&gt;I don&amp;#8217;t want to leave that EC2 instance running, it was only created for testing purposes after all:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;knife ec2 server list &lt;span class=&quot;c&quot;&gt;# I need the server ID&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;knife ec2 server delete i-xxxxxx
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;knife node delete my-first-ec2-instance
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;knife node list
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Using Chef to manage Amazon EC2 instances, Part 1</title>
   <link href="http://gerhardlazu.com/2010/08/using-chef-to-manage-amazon-ec2-instances-part1"/>
   <updated>2010-08-10T00:00:00+01:00</updated>
   <id>http://gerhardlazu.com/2010/08/using-chef-to-manage-amazon-ec2-instances-part1</id>
   <content type="html">&lt;p&gt;So now that you have you Amazon &lt;span class=&quot;caps&quot;&gt;AWS&lt;/span&gt; account, you must feel smug and think that you&amp;#8217;re on the top of the cloud computing world. Not so quick tiger. Let&amp;#8217;s say that you fire up an EC2 instance, what next? How are you going to configure it? Let&amp;#8217;s tackle this step by step. I&amp;#8217;m on OS X by the way, you should be too.&lt;/p&gt;
&lt;h2&gt;Keys, Certificates &amp;amp; authentication&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;http://github.com/mxcl/homebrew&quot;&gt;Install brew&lt;/a&gt; if you don&amp;#8217;t have it, then create an &lt;code&gt;.ec2&lt;/code&gt; folder:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;brew install ec2-api-tools
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;mkdir ~/.ec2
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Create a file in the newly created folder called e.g. &lt;code&gt;gerhard_aws&lt;/code&gt; containing:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;c&quot;&gt;#!/bin/sh&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Setup Amazon EC2 Command-Line Tools&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;EC2_ACCESS_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;lt;your-access-key&amp;gt;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;EC2_SECRET_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;lt;your-secret-key&amp;gt;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;JAVA_HOME&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;/System/Library/Frameworks/JavaVM.framework/Home&amp;quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;EC2_PRIVATE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;$(/bin/ls $HOME/.ec2/pk-*.pem)&amp;quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;EC2_CERT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;$(/bin/ls $HOME/.ec2/cert-*.pem)&amp;quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;EC2_HOME&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;/usr/local/Cellar/ec2-api-tools/&amp;lt;your-version&amp;gt;/jars&amp;quot;&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;# ec2-version w/o date&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;The Access Key, Secret Key and Certificate should be easy to find in your Amazon &lt;span class=&quot;caps&quot;&gt;AWS&lt;/span&gt; account. You&amp;#8217;ll find them in &lt;em&gt;Account &amp;gt; Security Credentials&lt;/em&gt;. You should be given the Private Key when creating your first keypair, but I&amp;#8217;m not 100% sure. You need to move this Private Key into the same &lt;code&gt;.ec2&lt;/code&gt; folder.&lt;/p&gt;
&lt;p&gt;In your shell&amp;#8217;s configuration file add the following and reload the shell environment:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[[&lt;/span&gt; -s &lt;span class=&quot;nv&quot;&gt;$HOME&lt;/span&gt;/.ec2/gerhard_aws &lt;span class=&quot;o&quot;&gt;]]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;source&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$HOME&lt;/span&gt;/.ec2/gerhard_aws
&lt;span class=&quot;k&quot;&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;After generating a new EC2 keypair, put everything starting with &lt;code&gt;-----BEGIN RSA PRIVATE KEY-----&lt;/code&gt; into a new file called the same name as the keypair (&lt;code&gt;ec2-keypair&lt;/code&gt; in my example). When done, let&amp;#8217;s add this key to our agent so that we can ssh into our EC2 instances with no extra hassle:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ec2-add-keypair ec2-keypair
&lt;span class=&quot;c&quot;&gt;# this will output the new keypir contents&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ssh-add ~/.ec2/ec2-keypair
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ssh-add -l &lt;span class=&quot;c&quot;&gt;# make sure it was added!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;As an extra tip, keep your &lt;code&gt;.ec2&lt;/code&gt; folder on &lt;a href=&quot;https://www.dropbox.com/&quot;&gt;Dropbox&lt;/a&gt; and just symlink it to your home folder:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ln -nfs ~/Dropbox/dotfiles/.ec2 ~/.ec2
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;h2&gt;Create Opscode account &amp;amp; install Chef locally&lt;/h2&gt;
&lt;p&gt;There is an excellent, up-to-date write-up on &lt;a href=&quot;https://opscode.tenderapp.com/faqs/start&quot;&gt;Getting Started with Chef&lt;/a&gt;, follow it!&lt;/p&gt;
&lt;p&gt;Make sure that you install the following gems, they will save you a good &lt;del&gt;ba&amp;#8230;&lt;/del&gt; head scratch later:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gem install net-ssh-multi fog highline
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;At step 2, &lt;em&gt;Create your Chef repository&lt;/em&gt;, I have created another folder on Dropbox and just symlinked it from there. I have also modified the cookbook path and added the &lt;span class=&quot;caps&quot;&gt;AWS&lt;/span&gt; keys to &lt;code&gt;.chef/knife.rb&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;cookbook_path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;current_dir&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/../site-cookbooks&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;current_dir&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/../cookbooks&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Amazon AWS&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;knife&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:aws_access_key_id&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;no&quot;&gt;ENV&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;EC2_ACCESS_KEY&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;knife&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:aws_secret_access_key&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;no&quot;&gt;ENV&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;EC2_SECRET_KEY&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;We&amp;#8217;ll create our first EC2 instance &amp;amp; configure it in the second part:&lt;br /&gt;
&lt;a href=&quot;/2010/08/using-chef-to-manage-amazon-ec2-instances-part2&quot;&gt;Using Chef to manage Amazon EC2 instances, Part 2&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 
</feed>

