<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ryan Kanno: The diary of an Enginerd in Hawaii&#187; WebFaction</title>
	<atom:link href="http://blog.localkinegrinds.com/category/technology/webfaction/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.localkinegrinds.com</link>
	<description>Everything you&#039;ve ever thought, but never had the balls to say.</description>
	<lastBuildDate>Sat, 03 Sep 2011 13:19:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Update: Using Capistrano 2.5 to deploy Rails 2.3 to Webfaction</title>
		<link>http://blog.localkinegrinds.com/2009/07/27/update-using-capistrano-2-5-to-deploy-rails-2-3-to-webfaction/</link>
		<comments>http://blog.localkinegrinds.com/2009/07/27/update-using-capistrano-2-5-to-deploy-rails-2-3-to-webfaction/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 09:41:07 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[WebFaction]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/?p=366</guid>
		<description><![CDATA[Update Having been a Capistrano user for a few years, I absolutely love sweet, sweet automation. A few months ago, I wrote a blog about how to use Capistrano to deploy to WebFaction. However, since that post, the winds of change have swept through the Rails and Capistrano community with the release of Rails 2.3 [...]]]></description>
			<content:encoded><![CDATA[<h2>Update</h2>
<p>Having been a <a href="http://www.capify.org/">Capistrano</a> user for a few years, I absolutely love sweet, sweet automation.  A few months ago, I wrote a blog about <a href="http://blog.localkinegrinds.com/2008/09/16/using-capistrano-to-deploy-to-webfaction/">how to use Capistrano to deploy to WebFaction</a>.  However, since that post, the winds of change have swept through the Rails and Capistrano community with the release of Rails 2.3 and Capistrano 2.5.  WebFaction&#8217;s Ruby installation precludes you from taking advantage of these great updates, so I&#8217;ve come up with a little update to my previous post.</p>
<hr/>
<p><a href="http://blog.localkinegrinds.com/wp-content/uploads/2008/09/automator-icon.jpg" rel="lightbox[366]"><img src="http://blog.localkinegrinds.com/wp-content/uploads/2008/09/automator-icon.jpg" alt="" title="automator-icon" width="200" height="200" class="alignright size-full wp-image-233" /></a></p>
<h2>Learn to Change, Change to Learn</h2>
<p>To be able to deploy Rails 2.3 with Capistrano 2.5, we&#8217;ll first have to jump through a few hoops.  Nice, easy hoops, mind you, but still hoops nonetheless.</p>
<h3>Your own Ruby installation</h3>
<p>You&#8217;ll have to install a custom Ruby installation into your WebFaction home directory.  By following Step 1 <a href="https://help.webfaction.com/index.php?_m=knowledgebase&#038;_a=viewarticle&#038;kbarticleid=89&#038;nav=0,21">here</a>, you&#8217;ll have a working Ruby 1.8.7 installation and RubyGem 1.3.  You&#8217;ll need these if you want to deploy a Rails 2.3 application.  Also, install a version of Mongrel tied to your Ruby installation.</p>
<p><strong>Note:</strong> Typically, I like to install custom installations into ~/opt/local/lib/.  </p>
<h3>Edit Autostart.cgi</h3>
<p>You&#8217;ll have to make a few edits to a few files from <a href="http://blog.localkinegrinds.com/2008/09/16/using-capistrano-to-deploy-to-webfaction/">my previous blog post</a>.</p>
<p>Next, open up your favorite editor of choice (*cough*vi*cough*) and edit the <strong>autostart.cgi</strong> file. Jump to the end of the file and comment out the following line from my previous blog:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;"># os.system('/usr/local/bin/mongrel_rails start -c /home/&lt;webfaction_username&gt;/webapps-releases/&lt;webfaction_app_name&gt;/current -d -e production -P /home/&lt;webfaction_username&gt;/webapps/&lt;webfaction_app_name&gt;/log/mongrel.pid -p &lt;port&gt;')</span></pre></td></tr></table></div>

<p>and change it to the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">&nbsp;
 <span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/home/&lt;webfaction_username&gt;/opt/local/lib/ruby1.8/lib/ruby/gems/1.8/bin/mongrel_rails start -c /home/&lt;webfaction_username&gt;/webapps-releases/&lt;webfaction_app_name&gt;/current -d -e production -P /home/&lt;webfaction_username&gt;/webapps/&lt;webfaction_app_name&gt;/log/mongrel.pid -p &lt;port&gt;'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p><strong>Notice:</strong> We&#8217;re using the path to Mongrel tied to our custom Ruby installation!  This might be different in your installation!</p>
<h3>Edit the Capfile</h3>
<p>In my previous blog, we placed a custom <strong>deploy.rb</strong> into the config directory.  With the latest version of Capistrano, you no longer need to do this.  Rather, place the following into a file called <strong>Capfile</strong> in the root of your Rails project.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'deploy'</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:webfaction_username</span>, <span style="color:#996600;">&quot;&lt;webfaction_username&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_db_type</span>, <span style="color:#996600;">&quot;&lt;webfaction_db_type&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_db</span>, <span style="color:#996600;">&quot;&lt;webfaction_db&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_db_username</span>, <span style="color:#996600;">&quot;&lt;webfaction_db_username&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_port</span>, <span style="color:#996600;">&quot;&lt;webfaction_port (get from autostart.cgi)&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:database_yml_template</span>, <span style="color:#996600;">&quot;database.example.yml&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:application</span>, <span style="color:#996600;">&quot;test&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:deploy_to</span>, <span style="color:#996600;">&quot;/home/#{webfaction_username}/webapps-releases/#{application}&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:scm</span>, <span style="color:#ff3333; font-weight:bold;">:subversion</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_user</span>, <span style="color:#996600;">&quot;&lt;scm_username&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_password</span>, <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#6666ff; font-weight:bold;">Capistrano::CLI</span>.<span style="color:#9900CC;">password_prompt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Subversion password for #{scm_user}: &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
set <span style="color:#ff3333; font-weight:bold;">:repository</span>, <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">&quot;--username #{scm_user} --password #{scm_password} --no-auth-cache &lt;http://path/to/your/svn/goes/here/&gt;&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span> 
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#996600;">&quot;#{webfaction_username}&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:use_sudo</span>, <span style="color:#0000FF; font-weight:bold;">false</span> 
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:domain</span>, <span style="color:#996600;">&quot;&lt;webfaction_domain&gt;&quot;</span>
&nbsp;
role <span style="color:#ff3333; font-weight:bold;">:app</span>, domain
role <span style="color:#ff3333; font-weight:bold;">:web</span>, domain
role <span style="color:#ff3333; font-weight:bold;">:db</span>,  domain, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
desc <span style="color:#996600;">&quot;Symlink public to what webfaction expects the webroot to be&quot;</span>
task <span style="color:#ff3333; font-weight:bold;">:after_symlink</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:web</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  run <span style="color:#996600;">&quot;ln -nfs #{release_path}/public /home/#{webfaction_username}/webapps/#{application}/&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:deploy</span> <span style="color:#9966CC; font-weight:bold;">do</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Taken from http://jonathan.tron.name/2006/07/15/capistrano-password-prompt-tips </span>
  <span style="color:#008000; font-style:italic;"># Thanks Jonathan! :)</span>
  desc <span style="color:#996600;">&quot;Creates the database configuration on the fly&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:create_database_configuration</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;yaml&quot;</span>
    set <span style="color:#ff3333; font-weight:bold;">:production_db_password</span>, <span style="color:#CC0066; font-weight:bold;">proc</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#6666ff; font-weight:bold;">Capistrano::CLI</span>.<span style="color:#9900CC;">password_prompt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Remote production database password: &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
    db_config = <span style="color:#CC00FF; font-weight:bold;">YAML</span>::load_file<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;config/#{database_yml_template}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    db_config.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'test'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    db_config.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'development'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'adapter'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{webfaction_db_type}&quot;</span>
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'database'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{webfaction_db}&quot;</span>
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'username'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{webfaction_db_username}&quot;</span>
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'password'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = production_db_password
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'host'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;localhost&quot;</span>
&nbsp;
    put <span style="color:#CC00FF; font-weight:bold;">YAML</span>::dump<span style="color:#006600; font-weight:bold;">&#40;</span>db_config<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">&quot;#{release_path}/config/database.yml&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:mode</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 0664
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  after <span style="color:#996600;">&quot;deploy:update_code&quot;</span>, <span style="color:#996600;">&quot;deploy:create_database_configuration&quot;</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Redefine deploy:start&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:start</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    invoke_command <span style="color:#996600;">&quot;/opt/local/lib/ruby1.8/lib/ruby/gems/1.8/bin/mongrel_rails start -c #{deploy_to}/current -d -e production -P /home/#{webfaction_username}/webapps/#{application}/log/mongrel.pid -p #{webfaction_port}&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:via</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> run_method
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Redefine deploy:restart&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:restart</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    invoke_command <span style="color:#996600;">&quot;/opt/local/lib/ruby1.8/lib/ruby/gems/1.8/bin/mongrel_rails restart -c #{deploy_to}/current -P /home/#{webfaction_username}/webapps/#{application}/log/mongrel.pid&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:via</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> run_method
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Redefine deploy:stop&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:stop</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    invoke_command <span style="color:#996600;">&quot;/opt/local/lib/ruby1.8/lib/ruby/gems/1.8/bin/mongrel_rails stop -c #{deploy_to}/current -P /home/#{webfaction_username}/webapps/#{application}/log/mongrel.pid&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:via</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> run_method
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<div style="font:normal 1.1em arial; background-color:#E5F3FF; padding:1em; margin:1em 0; border:1px solid #114477; color:#33415D;"><strong>Note:</strong> Change all the values in tags like <strong>&lt;webfaction_username&gt;</strong>, <strong>&lt;webfaction_db&gt;</strong>, <strong>&lt;webfaction_db_username&gt;</strong>, etc. to those values that fit your configuration!<br/>Otherwise, this file in itself won&#8217;t do you any good.</div>
<p><strong>Now, you should be able to run the standard Capistrano tasks to deploy your application to WebFaction with the latest version of Rails!</strong></p>
<h3>Explanation</h3>
<p>Basically, the only thing I&#8217;ve done is shown you how to update your version of Ruby, RubyGems, Mongrel, and Capistrano to place nicely in WebFaction.  This should allow you to run commands like &#8216;cap deploy:setup&#8217;, &#8216;cap deploy:update&#8217; on your local machine and update your live code on WebFaction&#8217;s servers. Nothing too serious going on here!  As always, feel free to use, steal, take, and/or copy anything on this blog. Hopefully somewhere, someone on the Interwebs will find these tips handy!</p>
<p><strong>And if you find anything wrong with these scripts, don&#8217;t hesitate to leave a comment or email!</strong></p>
<h2>Voila! (Enjoy)</h2>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=366&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2009/07/27/update-using-capistrano-2-5-to-deploy-rails-2-3-to-webfaction/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Using Capistrano to deploy to WebFaction</title>
		<link>http://blog.localkinegrinds.com/2008/09/16/using-capistrano-to-deploy-to-webfaction/</link>
		<comments>http://blog.localkinegrinds.com/2008/09/16/using-capistrano-to-deploy-to-webfaction/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 16:57:30 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[WebFaction]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[deploy]]></category>
		<category><![CDATA[mongrel]]></category>
		<category><![CDATA[ror]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/?p=215</guid>
		<description><![CDATA[Update If you like to stay on the edge, check out my latest post describing how to use Capistrano 2.5 to deploy Rails 2.3 to Webfaction! There&#8217;s nothing I love more than sweet automation. After spending the better part of an hour searching the great Googs, there was only a single blog I could find [...]]]></description>
			<content:encoded><![CDATA[<h2>Update</h2>
<p>If you like to stay on the edge, check out my latest <a href="http://blog.localkinegrinds.com/2009/07/27/update-using-capistrano-2-5-to-deploy-rails-2-3-to-webfaction/">post describing how to use Capistrano 2.5 to deploy Rails 2.3 to Webfaction</a>!  </p>
<hr/>
<p><a href="http://blog.localkinegrinds.com/wp-content/uploads/2008/09/automator-icon.jpg" rel="lightbox[215]"><img src="http://blog.localkinegrinds.com/wp-content/uploads/2008/09/automator-icon.jpg" alt="" title="automator-icon" width="200" height="200" class="alignright size-full wp-image-233" /></a></p>
<h2>There&#8217;s nothing I love more than sweet automation.</h2>
<p>After spending the better part of an hour searching the great Googs, there was only a single blog I could find describing <a href="http://mega.blaix.com/2007/8/29/capistrano-on-webfaction">how to use Capistrano to deploy to WebFaction</a>.  <em>Unfortunately, Justin was describing a Capistrano 1.4 deployment.</em> I found a <a href="http://forum.webfaction.com/viewtopic.php?id=598">few</a> <a href="http://forum.webfaction.com/viewtopic.php?id=1610">posts</a> on the <a href="http://forum.webfaction.com/">WebFaction forums</a>, but nothing concrete.  So after a few hours fiddling with the technology, here&#8217;s how I configured my <a href="http://www.rubyonrails.org/">Rails</a> 2.1.1 project to use <a href="http://www.capify.org/">Capistrano</a> 2.5 to deploy to <a href="http://www.webfaction.com">WebFaction</a>.</p>
<h3>Assumptions</h3>
<p>Before getting started, I&#8217;m going to assume the following:</p>
<ul>
<li>I&#8217;m assuming you&#8217;ve already used the one-click WebFaction goodness to create a brand new Rails application in ~/webapps/&lt;application_name&gt;.  If you don&#8217;t know what I&#8217;m referring to, make sure to check out the <a href="http://www.webfaction.com/demos/rails-typo">Rails and Typo Demo screencast</a>.  Make sure you have a domain, application, and website configured.</li>
<li>I&#8217;m also going to assume that your nifty Rails application is safely stored away in either a <a href="http://subversion.tigris.org/">Subversion</a> or <a href="http://git.or.cz/">Git</a> repository and you&#8217;ve frozen Rails in your application.</li>
<li>Finally, I&#8217;m going to assume you setup your database via <a href="http://www.webfaction.com/screencasts/control-panel-demo/demo.html">WebFaction&#8217;s control panel</a>.
</ul>
<h3>Installing Capistrano</h3>
<p>The very first thing you have to do is install Capistrano on your <em>local machine</em> by issuing the following command:</p>
<pre class="console">
$ gem install -y capistrano
</pre>
<p>After installing Capistrano, the first thing you have to do is to &#8220;capify&#8221; your local Rails project.  Change into your project&#8217;s root directory and issue the following command:</p>
<pre class="console">
$ capify .
</pre>
<p>This configures your Rails project to play nicely with Capistrano.  Two files should&#8217;ve been created; <strong>Capfile</strong> in the project root and <strong>config/deploy.rb</strong>.  The deploy.rb file contains the Rails project application-specific deployment configuration.</p>
<h3>Configuring WebFaction</h3>
<p>Jumping back to WebFaction, I followed a few of the steps in <a href="http://mega.blaix.com/2007/8/29/capistrano-on-webfaction">Justin&#8217;s blog</a>.  First thing&#8217;s first, ssh into your WebFaction account and create a directory called <strong>webapps-releases</strong> in your home directory.  This directory is where we&#8217;re going to deploy the application to.</p>
<p>Since you&#8217;ve already configured a Rails application at ~/webapps/&lt;application_name&gt;, change into that directory.  You should see a standard Rails project with the exception of an extra file called autostart.cgi.  Remove everything in the directory except the autostart.cgi file by issuing the following commands:</p>
<pre class="console">
$ cd ~/webapps/&lt;application_name&gt;
$ mv autostart.cgi ~/
$ rm -rf *
$ mv ~/autostart.cgi .
</pre>
<p>Once the directory is clear, create a symlink to the log directory that will be in the webapps-releases directory we created earlier.</p>
<pre class="console">
$ ln -s ~/webapps-releases/&lt;application_name&gt;/shared/log ~/webapps/&lt;application_name&gt;/log
</pre>
<p><strong>Note:</strong> I&#8217;m assuming here that the WebFaction app and the Rails application have identical names.</p>
<p>Next, open up your favorite editor of choice (*cough*Vi*cough*) and edit the <strong>autostart.cgi</strong> file.  Jump to the end of the file and comment out the following line:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;"># os.system('/usr/local/bin/mongrel_rails start -d -e production -P /home/&lt;webfaction_username&gt;/webapps/&lt;webfaction_app_name&gt;/log/mongrel.pid -p &lt;port&gt;')</span></pre></td></tr></table></div>

<p>and right below it, cut and paste the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">&nbsp;
  <span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/usr/local/bin/mongrel_rails start -c /home/&lt;webfaction_username&gt;/webapps-releases/&lt;webfaction_app_name&gt;/current -d -e production -P /home/&lt;webfaction_username&gt;/webapps/&lt;webfaction_app_name&gt;/log/mongrel.pid -p &lt;port&gt;'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<h3>Creating your custom deploy.rb</h3>
<p>After configuring WebFaction, we have to configure the Capistrano application deployment configuration.  On your local machine, find the file <strong>config/deploy.rb</strong> and replace it with the one below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:webfaction_username</span>, <span style="color:#996600;">&quot;&lt;webfaction_username&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_db_type</span>, <span style="color:#996600;">&quot;&lt;webfaction_db_type&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_db</span>, <span style="color:#996600;">&quot;&lt;webfaction_db&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_db_username</span>, <span style="color:#996600;">&quot;&lt;webfaction_db_username&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_port</span>, <span style="color:#996600;">&quot;&lt;webfaction_port (get from autostart.cgi)&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:database_yml_template</span>, <span style="color:#996600;">&quot;database.example.yml&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:application</span>, <span style="color:#996600;">&quot;test&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:deploy_to</span>, <span style="color:#996600;">&quot;/home/#{webfaction_username}/webapps-releases/#{application}&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:scm</span>, <span style="color:#ff3333; font-weight:bold;">:subversion</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_user</span>, <span style="color:#996600;">&quot;&lt;scm_username&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_password</span>, <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#6666ff; font-weight:bold;">Capistrano::CLI</span>.<span style="color:#9900CC;">password_prompt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Subversion password for #{scm_user}: &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
set <span style="color:#ff3333; font-weight:bold;">:repository</span>, <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">&quot;--username #{scm_user} --password #{scm_password} --no-auth-cache &lt;http://path/to/your/svn/goes/here/&gt;&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span> 
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#996600;">&quot;#{webfaction_username}&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:use_sudo</span>, <span style="color:#0000FF; font-weight:bold;">false</span> 
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:domain</span>, <span style="color:#996600;">&quot;&lt;webfaction_domain&gt;&quot;</span>
&nbsp;
role <span style="color:#ff3333; font-weight:bold;">:app</span>, domain
role <span style="color:#ff3333; font-weight:bold;">:web</span>, domain
role <span style="color:#ff3333; font-weight:bold;">:db</span>,  domain, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
desc <span style="color:#996600;">&quot;Symlink public to what webfaction expects the webroot to be&quot;</span>
task <span style="color:#ff3333; font-weight:bold;">:after_symlink</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:web</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  run <span style="color:#996600;">&quot;ln -nfs #{release_path}/public /home/#{webfaction_username}/webapps/#{application}/&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:deploy</span> <span style="color:#9966CC; font-weight:bold;">do</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Taken from http://jonathan.tron.name/2006/07/15/capistrano-password-prompt-tips </span>
  <span style="color:#008000; font-style:italic;"># Thanks Jonathan! :)</span>
  desc <span style="color:#996600;">&quot;Creates the database configuration on the fly&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:create_database_configuration</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;yaml&quot;</span>
    set <span style="color:#ff3333; font-weight:bold;">:production_db_password</span>, <span style="color:#CC0066; font-weight:bold;">proc</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#6666ff; font-weight:bold;">Capistrano::CLI</span>.<span style="color:#9900CC;">password_prompt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Remote production database password: &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
    db_config = <span style="color:#CC00FF; font-weight:bold;">YAML</span>::load_file<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;config/#{database_yml_template}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    db_config.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'test'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    db_config.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'development'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'adapter'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{webfaction_db_type}&quot;</span>
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'database'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{webfaction_db}&quot;</span>
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'username'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{webfaction_db_username}&quot;</span>
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'password'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = production_db_password
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'host'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;localhost&quot;</span>
&nbsp;
    put <span style="color:#CC00FF; font-weight:bold;">YAML</span>::dump<span style="color:#006600; font-weight:bold;">&#40;</span>db_config<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">&quot;#{release_path}/config/database.yml&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:mode</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 0664
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  after <span style="color:#996600;">&quot;deploy:update_code&quot;</span>, <span style="color:#996600;">&quot;deploy:create_database_configuration&quot;</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Redefine deploy:start&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:start</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    invoke_command <span style="color:#996600;">&quot;/usr/local/bin/mongrel_rails start -c #{deploy_to}/current -d -e production -P /home/#{webfaction_username}/webapps/#{application}/log/mongrel.pid -p #{webfaction_port}&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:via</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> run_method
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Redefine deploy:restart&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:restart</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    invoke_command <span style="color:#996600;">&quot;/usr/local/bin/mongrel_rails restart -c #{deploy_to}/current -P /home/#{webfaction_username}/webapps/#{application}/log/mongrel.pid&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:via</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> run_method
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Redefine deploy:stop&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:stop</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    invoke_command <span style="color:#996600;">&quot;/usr/local/bin/mongrel_rails stop -c #{deploy_to}/current -P /home/#{webfaction_username}/webapps/#{application}/log/mongrel.pid&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:via</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> run_method
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<div style="font:normal 1.1em arial; background-color:#E5F3FF; padding:1em; margin:1em 0; border:1px solid #114477; color:#33415D;"><strong>Note:</strong> Change all the values in tags like <strong>&lt;webfaction_username&gt;</strong>, <strong>&lt;webfaction_db&gt;</strong>, <strong>&lt;webfaction_db_username&gt;</strong>, etc. to those values that fit your configuration!<br/>Otherwise, this file in itself won&#8217;t do you any good.</div>
<p><strong>Props out to <a href="http://jonathan.tron.name/">Jonathan</a> for the fantastic Capistrano tips!</strong></p>
<p>After copying the deploy.rb file and editing the appropriate variables, run the following command in your Rails project&#8217;s root directory:</p>
<pre class="console">
$ cap deploy:setup
</pre>
<p>This command creates the appropriate directory structure for Capistrano on the deployment server based upon values set in your deploy.rb.  Next, run the following command to check your dependencies.</p>
<pre class="console">
$ cap deploy:check
</pre>
<p>If everything is successful, you should see a message that reads something like&#8230;<br/></p>
<p><strong>You appear to have all necessary dependencies installed</strong></p>
<p>Next, push your code out to the server using the following command:</p>
<pre class="console">
$ cap deploy:update
</pre>
<p>Finally, to start up your application run the following Capistrano command:</p>
<pre class="console">
$ cap deploy:start
</pre>
<p>Now, you should be able to run the standard Capistrano tasks to deploy your application to WebFaction!</p>
<h3>Explanation</h3>
<p>Most techies like to have an explanation of what&#8217;s going on with the Capistrano deploy.rb.  I could probably write another blog about it, but I&#8217;m lazy (and pressed for time).  The :create_database_configuration task basically writes the database.yml production configuration on the fly (courtesy of this <a href="http://jonathan.tron.name/2006/07/15/capistrano-password-prompt-tips">blog posting</a>).</p>
<p>The basic gyst of the rest of the script is that WebFaction is proxying a Mongrel instance.  The Capistrano deploy.rb override the original deploy:start, deploy:stop, and deploy:restart tasks to run Mongrel commands that WebFaction can understand.  Typically, the default Capistrano tasks run script/spin and reaper, but it was easier just to redefine the task.  <strong>If anyone has any tips/suggestions to improve the script, I&#8217;m all ears!  </strong></p>
<h2>Voila! (Enjoy)</h2>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=215&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2008/09/16/using-capistrano-to-deploy-to-webfaction/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: blog.localkinegrinds.com @ 2012-02-07 21:15:46 -->
