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

 <title>David Dollar</title>
 <link href="http://blog.daviddollar.org/atom.xml" rel="self"/>
 <link href="http://blog.daviddollar.org/"/>
 <updated>2012-08-20T12:28:23-04:00</updated>
 <id>http://blod.daviddollar.org/</id>
 <author>
   <name>David Dollar</name>
   <email>david@dollar.io</email>
 </author>

 
   <entry>
     <title>Introducing Foreman</title>
     <link href="http://blog.daviddollar.org/2011/05/06/introducing-foreman.html"/>
     <updated>2011-05-06T00:00:00-04:00</updated>
     <id>http://blog.daviddollar.org/2011/05/06/introducing-foreman</id>
     <content type="html">&lt;p&gt;Lately I've noticed my web apps are getting complicated to run. My apps no longer consist of a
single web process; I usually have have one or more types of background workers to run different
types of jobs and a clock process to handle scheduling. Splitting an app up in this way
is great for performance and scalability. The downside, however, is that it becomes much
more complicated to get the app and all of its parts running.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://github.com/ddollar/foreman&quot;&gt;Foreman&lt;/a&gt; is an attempt to make this easier. Using
foreman you can declare the various processes that are needed to run your application
using a &lt;code&gt;Procfile&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;web:    bundle exec thin start -p $PORT
worker: bundle exec rake resque:work QUEUE=*
clock:  bundle exec rake resque:scheduler
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;To get started, simply run &lt;code&gt;gem install foreman&lt;/code&gt;. If your project is using both Bundler and Foreman,
launching it should be as simple as&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;$ bundle install
$ foreman start
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;&lt;img src=&quot;/images/foreman_screenshot_1.png&quot; style=&quot;background-color: #000; padding: 10px; padding-right: 125px&quot;/&gt;&lt;/p&gt;

&lt;p&gt;Foreman will start all of the processes associated with your app and display &lt;code&gt;stdout&lt;/code&gt; and &lt;code&gt;stderr&lt;/code&gt; of
each process. Processes are color-coded by type to make them easy to read. &lt;code&gt;$PORT&lt;/code&gt; will be
automatically assigned by foreman and made available to each underlying process.&lt;/p&gt;

&lt;h2&gt;Exporting to Production&lt;/h2&gt;

&lt;p&gt;While foreman is great for running your application in development, there are some
great existing tools for managing processes in production. Foreman can export to either &lt;a href=&quot;http://upstart.ubuntu.com/&quot;&gt;upstart&lt;/a&gt;
or standard unix &lt;code&gt;init&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;Exporting to upstart&lt;/h3&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; foreman &lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;upstart /etc/init
&lt;span class=&quot;go&quot;&gt;[foreman export] writing: /etc/init/testapp.conf&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[foreman export] writing: /etc/init/testapp-web.conf&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[foreman export] writing: /etc/init/testapp-web-1.conf&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[foreman export] writing: /etc/init/testapp-worker.conf&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[foreman export] writing: /etc/init/testapp-worker-1.conf&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[foreman export] writing: /etc/init/testapp-clock.conf&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[foreman export] writing: /etc/init/testapp-clock-1.conf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;After exporting to upstart, the following commands become available:&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; start testapp
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; stop testapp-clock
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; restart testapp-worker-1
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h3&gt;Exporting to init&lt;/h3&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; foreman &lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;inittab
&lt;span class=&quot;gp&quot;&gt;#&lt;/span&gt; ----- foreman testapp processes -----
&lt;span class=&quot;go&quot;&gt;TE01:4:respawn:/bin/su - testapp -c &amp;#39;PORT=5000 bundle exec thin start -p $PORT &amp;gt;&amp;gt; /var/log/testapp/web-1.log 2&amp;gt;&amp;amp;1&amp;#39;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;TE02:4:respawn:/bin/su - testapp -c &amp;#39;PORT=5100 bundle exec rake resque:work QUEUE=* &amp;gt;&amp;gt; /var/log/testapp/worker-1.log 2&amp;gt;&amp;amp;1&amp;#39;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;TE03:4:respawn:/bin/su - testapp -c &amp;#39;PORT=5200 bundle exec rake resque:scheduler &amp;gt;&amp;gt; /var/log/testapp/clock-1.log 2&amp;gt;&amp;amp;1&amp;#39;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;#&lt;/span&gt; ----- end foreman testapp processes -----
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Advanced Options&lt;/h2&gt;

&lt;h3&gt;Concurrency&lt;/h3&gt;

&lt;p&gt;Foreman supports running more than 1 of each process type.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;# run 1 of each process type, and 2 workers
$ foreman start -c worker=2

# do not run a clock process
$ foreman start -c clock=0
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h3&gt;Port Assignment&lt;/h3&gt;

&lt;p&gt;Foreman starts port assignments at 5000 by default, and assigns them in blocks of 100 per process type in the
order used in your &lt;code&gt;Procfile&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For the &lt;code&gt;Procfile&lt;/code&gt; used at the top of this post, web.1 would be assigned port 5000, worker.1 would be 5100,
and clock.1 would be 5200. If you were ran 2 web processes, web.2 would be assigned 5001.&lt;/p&gt;

&lt;p&gt;You can specify an alternate starting port for foreman to use with the &lt;code&gt;-p&lt;/code&gt; option.&lt;/p&gt;

&lt;h3&gt;Documentation&lt;/h3&gt;

&lt;p&gt;For more information about the available options, check out the &lt;a href=&quot;http://ddollar.github.com/foreman/&quot;&gt;man page&lt;/a&gt;.&lt;/p&gt;
</content>
   </entry>
 
   <entry>
     <title>Simulating the Heroku Environment in Development</title>
     <link href="http://blog.daviddollar.org/2009/11/08/simulating-the-heroku-environment-in-development.html"/>
     <updated>2009-11-08T00:00:00-05:00</updated>
     <id>http://blog.daviddollar.org/2009/11/08/simulating-the-heroku-environment-in-development</id>
     <content type="html">&lt;p&gt;I've been using &lt;a href=&quot;http://heroku.com&quot;&gt;Heroku&lt;/a&gt; quite a bit lately for easy
deployment. Things such as &lt;code&gt;DATABASE_URL&lt;/code&gt; and S3 credentials are managed
through &lt;code&gt;heroku config&lt;/code&gt; and show up in your production app as
&lt;code&gt;ENV['DATABASE_URL']&lt;/code&gt;. This is a great way to keep these configuration details
out of your repository.&lt;/p&gt;

&lt;p&gt;One downside to this approach is that it can be annoying to get these
environment variables set in your local development version of the app. Enter
&lt;a href=&quot;http://github.com/ddollar/rack-environment&quot;&gt;rack-environment&lt;/a&gt;. This piece
of Rack middleware lets you manage your development environment in a small
YAML file that will get loaded in front of your app. Simple, yet effective.&lt;/p&gt;

&lt;h4&gt;Using rack-environment with Rails&lt;/h4&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;# config/environments/development.rb&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;rack-environment&amp;#39;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;middleware&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;s1&quot;&gt;&amp;#39;RackEnvironment&amp;#39;&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# config/environment.yml&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;VARIABLE1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value1&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;VARIABLE2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h4&gt;Using rack-environment with any Rack-based framework&lt;/h4&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;# config.ru&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;Builder&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;n&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;RackEnvironment&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&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;RACK_ENV&amp;#39;&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;s1&quot;&gt;&amp;#39;development&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;MyApplication&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;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</content>
   </entry>
 
   <entry>
     <title>Using Ubuntu's Upstart To Keep Services Running</title>
     <link href="http://blog.daviddollar.org/2009/09/22/using-ubuntus-upstart-to-keep-services-running.html"/>
     <updated>2009-09-22T00:00:00-04:00</updated>
     <id>http://blog.daviddollar.org/2009/09/22/using-ubuntus-upstart-to-keep-services-running</id>
     <content type="html">&lt;p&gt;Ubuntu, since Intrepid, has replaced its init services with a daemon called
&lt;a href=&quot;http://upstart.ubuntu.com/&quot;&gt;Upstart&lt;/a&gt;. Similar to Apple's launchd, it provides
a greater granularity to the events occurring on a modern computer.&lt;/p&gt;

&lt;p&gt;We can use Upstart to start and stop services, and most importantly, to respawn
them automatically if they die. The following is an Upstart script that I wrote
to keep my IRC bouncer (bip) running.&lt;/p&gt;

&lt;p&gt;The script has the following features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Has a &lt;code&gt;pre-start&lt;/code&gt; stanza to create the appropriate &lt;code&gt;/var/run&lt;/code&gt; directory.&lt;/li&gt;
&lt;li&gt;Starts and stops in the appropriate runlevels.&lt;/li&gt;
&lt;li&gt;Uses &lt;code&gt;sudo -u&lt;/code&gt; to run the process as the &lt;code&gt;bip&lt;/code&gt; user.&lt;/li&gt;
&lt;li&gt;Will respawn in case of process termination.&lt;/li&gt;
&lt;/ul&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;# /etc/event.d/bip&lt;/span&gt;
pre-start script
  mkdir -p /var/run/bip
  chown bip:bip /var/run/bip
end script

start on runlevel 2
start on runlevel 3
start on runlevel 4
start on runlevel 5

stop on runlevel 0
stop on runlevel 6

&lt;span class=&quot;nb&quot;&gt;exec &lt;/span&gt;sudo -u bip /usr/bin/bip -n -f /etc/bip.conf -s /var/lib/bip
respawn
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</content>
   </entry>
 
   <entry>
     <title>Static Pages In Rails</title>
     <link href="http://blog.daviddollar.org/2009/08/22/static-pages-in-rails.html"/>
     <updated>2009-08-22T00:00:00-04:00</updated>
     <id>http://blog.daviddollar.org/2009/08/22/static-pages-in-rails</id>
     <content type="html">&lt;p&gt;In any web application there will be some static content. In the application
I'm building for the Rumble, I needed a static landing page, as well as simple
FAQ and Contact pages. I wanted simple static files that I could write in Haml
(my choice of templating engine for this project).&lt;/p&gt;

&lt;p&gt;The controller below allows you to keep static pages in
&lt;code&gt;app/views/pages/&amp;lt;page&amp;gt;.html.haml&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;c1&quot;&gt;# app/controllers/pages_controller.rb&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;PagesController&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ApplicationController&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;rescue_from&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActionView&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;MissingTemplate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:with&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:invalid_page&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;show&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;invalid_page&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;redirect_to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;root_path&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;A custom route allows us to link to static pages using &lt;code&gt;page_url(:welcome)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;:requirements&lt;/code&gt; on the route prevent malicious user input.&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;# config/routes.rb&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;page&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;pages/:id&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;ss&quot;&gt;:controller&lt;/span&gt;   &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;pages&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;ss&quot;&gt;:action&lt;/span&gt;       &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;show&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;ss&quot;&gt;:requirements&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;/[a-z]+/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</content>
   </entry>
 
   <entry>
     <title>Deploying a Rails Application with Capistrano</title>
     <link href="http://blog.daviddollar.org/2009/08/22/capistrano-deployment.html"/>
     <updated>2009-08-22T00:00:00-04:00</updated>
     <id>http://blog.daviddollar.org/2009/08/22/capistrano-deployment</id>
     <content type="html">&lt;p&gt;In most of the apps I work on regularly, the Capistrano setup has become a
ungainly monster that has evolved over time and over multiple Capistrano and
Rails versions. Participating in the &lt;a href=&quot;http://railsrumble.com/&quot;&gt;Rails Rumble&lt;/a&gt;
has given me an opportunity to set up a Capistrano configuration from scratch.&lt;/p&gt;

&lt;p&gt;This is what I came up with. It will automatically handle the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SQLite databases stored in &lt;code&gt;shared/db&lt;/code&gt; will be carried across releases&lt;/li&gt;
&lt;li&gt;Configuration files stored in &lt;code&gt;shared/config&lt;/code&gt; will be symlinked into &lt;code&gt;config&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Automatically install all Rubygems needed by the application&lt;/li&gt;
&lt;li&gt;Restart via Passenger's &lt;code&gt;tmp/restart.txt&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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;set&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:application&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;application-name&amp;quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:deploy_to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;   &lt;span class=&quot;s2&quot;&gt;&amp;quot;/srv/app/&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;application&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;n&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:deploy_via&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;ss&quot;&gt;:remote_cache&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:repository&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;s2&quot;&gt;&amp;quot;git@example.org:application.git&amp;quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:scm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;         &lt;span class=&quot;s2&quot;&gt;&amp;quot;git&amp;quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;        &lt;span class=&quot;s2&quot;&gt;&amp;quot;deploy&amp;quot;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;default_run_options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:pty&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;kp&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ssh_options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:forward_agent&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;kp&quot;&gt;true&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;role&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;server.example.org&amp;quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;role&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;s2&quot;&gt;&amp;quot;server.example.org&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:primary&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:deploy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;desc&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Restart Application&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:restart&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;touch &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;current_path&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/tmp/restart.txt&amp;quot;&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;span class=&quot;n&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:gems&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;desc&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Install Gems&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:install&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;cd &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;release_path&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; &amp;amp;&amp;amp; sudo env RAILS_ENV=production rake gems:install&amp;quot;&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;span class=&quot;n&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:shared&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;desc&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Link shared config files&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:configuration&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;%{&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;      for FILE in $(ls &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shared_path&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;/config);&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;      do&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;        ln -sf &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shared_path&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;/config/$(basename $FILE) &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;release_path&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;/config/$(basename $FILE);&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;      done&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;    }&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;desc&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Link a shared database directory&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:database&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;%{&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;      for FILE in $(ls &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shared_path&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;/db/*.sqlite3);&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;      do&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;        ln -sf &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shared_path&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;/db/$(basename $FILE) &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;release_path&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;/db/$(basename $FILE);&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;      done&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;    }&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;span class=&quot;n&quot;&gt;after&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;deploy:update_code&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;shared:configuration&amp;#39;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;after&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;deploy:update_code&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;gems:install&amp;#39;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;after&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;deploy:update_code&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;shared:database&amp;#39;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;after&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;deploy:update_code&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;deploy:migrate&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</content>
   </entry>
 
   <entry>
     <title>ActiveRecord Enumerables</title>
     <link href="http://blog.daviddollar.org/2009/08/22/active-record-enumerable.html"/>
     <updated>2009-08-22T00:00:00-04:00</updated>
     <id>http://blog.daviddollar.org/2009/08/22/active-record-enumerable</id>
     <content type="html">&lt;p&gt;As part of the requirements for my Poll model in the Rails Rumble, I have a
few columns that need to be locked down to certain values. Rather than
repeating &lt;code&gt;validates_presence_of&lt;/code&gt; and &lt;code&gt;validates_inclusion_of&lt;/code&gt; over and over,
I threw together a quick plugin that does both of these as well as adds some
convenience methods.&lt;/p&gt;

&lt;p&gt;You can find the plugin at &lt;a href=&quot;http://github.com/ddollar/active-record-enumerable.git&quot;&gt;http://github.com/ddollar/active-record-enumerable.git&lt;/a&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;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Food&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&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;kp&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActiveRecordEnumerable&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;enumerate&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;ss&quot;&gt;:as&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;%w( fruit vegetable )&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:default&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;foo&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;enumerate&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:as&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;%w( red green )&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;If &lt;code&gt;:default&lt;/code&gt; is not specified, the first enumerator in the list is used.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;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;no&quot;&gt;Food&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;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#&amp;lt;Food id: nil, type: &amp;quot;foo&amp;quot;, color: &amp;quot;red&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;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;save&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;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;color&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;red?&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;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;color&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;turquoise?&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;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;update_attributes!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:color&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;random&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;=&amp;gt;&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;RecordInvalid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Validation&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;failed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Color&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;included&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;the&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;list&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</content>
   </entry>
 
   <entry>
     <title>Deploying a Jekyll Site Via Git Hooks</title>
     <link href="http://blog.daviddollar.org/2009/08/21/deploying-a-jekyll-site-via-git-hooks.html"/>
     <updated>2009-08-21T00:00:00-04:00</updated>
     <id>http://blog.daviddollar.org/2009/08/21/deploying-a-jekyll-site-via-git-hooks</id>
     <content type="html">&lt;p&gt;Hello World.&lt;/p&gt;

&lt;p&gt;When deciding on Jekyll for this blog, I wanted a way to automagically deploy
updates simply by pushing commits. As it turns out, this is quite easy to
accomplish using a small post-update git hook.&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;cat /my/repo/hooks/post-update

&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Deploying Jekyll Site&amp;quot;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# configure these&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;REPOSITORY_DIR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;/my/repo&amp;quot;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;DEPLOY_DIR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;/var/www/blog&amp;quot;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# dont edit below here&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;DEPLOY_TMP_DIR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;mktemp /tmp/jekyll.deploy.XXXXX&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;
rm -f &lt;span class=&quot;nv&quot;&gt;$DEPLOY_TMP_DIR&lt;/span&gt;
git clone &lt;span class=&quot;nv&quot;&gt;$REPOSITORY_DIR&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$DEPLOY_TMP_DIR&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$DEPLOY_TMP_DIR&lt;/span&gt;
jekyll &lt;span class=&quot;nv&quot;&gt;$DEPLOY_DIR&lt;/span&gt;
rm -rf &lt;span class=&quot;nv&quot;&gt;$DEPLOY_TMP_DIR&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</content>
   </entry>
 

</feed>
