<?xml version="1.0" encoding="UTF-8"?>
<blog>
  <comment-count type="integer">0</comment-count>
  <created-at type="datetime">2009-05-19T14:55:20-04:00</created-at>
  <file></file>
  <id type="integer">28</id>
  <published type="boolean">true</published>
  <story>&lt;p&gt;The joys of &lt;a href='http://www.capify.org/'&gt;Capistrano&lt;/a&gt; have long eluded me. I was well aware of the easy life of instant deploys that it promised, but getting it up and running on my &lt;a href='http://www.webfaction.com?affiliate=lefthip'&gt;WebFaction&lt;/a&gt; account proved an insurmountable task that always saw me giving up in frustration, I didn&#8217;t even &lt;em&gt;try&lt;/em&gt; getting things going with &lt;a href='http://rubyhitsquad.com/Vlad_the_Deployer.html'&gt;Vlad&lt;/a&gt;. Every time I created a &lt;a href='http://www.webfaction.com?affiliate=lefthip'&gt;WebFaction&lt;/a&gt; account I bravely attempted to get Capistrano running again, and every time I failed and gave up. Maybe the problem had to do with me not being willing to fork out the cash for a Github account &#8211; I was trying to deploy instead from my local &lt;a href='https://github.com/'&gt;Github&lt;/a&gt; repo. Or maybe it had to do with Capistrano&#8217;s vague/non-existent error messages; I had a feeling that the software was vague due to the fact that it was created and intended for an elite group of intelligent professionals, not troglodytic hackers like myself. &lt;/p&gt;

&lt;p&gt;The first time I created a Hosting Rails account I found getting things going with Git and Capistrano were incredibly easy. And the benefits of Capistrano were &lt;em&gt;immediately&lt;/em&gt; discernible. Pushing changes were suddenly a few words and a return key away instead of an exercise in annoyance. The writeup I followed to get Capistrano working on &lt;a href='http://www.hostingrails.com/'&gt;Hosting Rails&lt;/a&gt; was based on the idea of deploying from a Git repo on the &lt;a href='http://www.webfaction.com?affiliate=lefthip'&gt;WebFaction&lt;/a&gt; account itself. &lt;/p&gt;

&lt;p&gt;It occurred to me that this could be the key to finally getting Capistrano and Git working for me on &lt;a href='http://www.webfaction.com?affiliate=lefthip'&gt;WebFaction&lt;/a&gt;&amp;#8230;. 24 hours later, and after endless curses, hair pulling, fists banged on tables and whatnot, I finally got the darned thing playing nice, pretty much.&lt;/p&gt;

&lt;p&gt;This is the solution that finally worked for me, based on a combination of resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://blog.localkinegrinds.com/2008/09/16/using-capistrano-to-deploy-to-webfaction/'&gt;Ryan Kanno&#8217;s article on Deploying With Capistrano To Webfaction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a hre'http://www.hostingrails.com/wiki/46/Capistrano-2x&amp;#8212;-Deploying-Your-Rails-Application-on-HostingRailscom'&gt;The Hosting Rails article Deploying With Git and Capistrano&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href='http://www.hostingrails.com/wiki/59/How-to-Deploy-Rails-Using-Git-with-Capistrano-on-Mongrel-with-HostingRails'&gt;More Hosting Rails Info On Capistrano And Git&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href='http://forum.webfaction.com/viewtopic.php?pid=9718'&gt;The Webfaction Article On Doing Your Own Ruby Install&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href='https://help.webfaction.com/index.php?&lt;em&gt;m=knowledgebase&amp;amp;&lt;/em&gt;a=pdfexport&amp;amp;kbarticleid=169'&gt;This PDF on a personal Git Install on Webfaction&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Preliminaries&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create your &lt;a href='http://www.webfaction.com?affiliate=lefthip'&gt;WebFaction&lt;/a&gt; account, Rails app and database, add your &lt;a href='http://www.webfaction.com?affiliate=lefthip'&gt;WebFaction&lt;/a&gt; production database to config/database.yml.&lt;/li&gt;
&lt;li&gt;Create a &lt;a href='https://help.webfaction.com/89'&gt;personal Webfaction Ruby install&lt;/a&gt;.

At the point where you install the mysql gem using the instructions in this article, you will encounter an error. Run this instead: &lt;code&gt;gem install mysql -- --with-mysql-config=/usr/bin/mysql_config&lt;/code&gt;

&lt;/li&gt;
&lt;/ul&gt;


&lt;h2 id=&quot;step_1_install_git&quot;&gt;Step 1 - Get Git Going&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Go to the &lt;a href='http://git-scm.com/'&gt;Git&lt;/a&gt; site and copy a link to the latest release, then log in to your &lt;a href='http://www.webfaction.com?affiliate=lefthip'&gt;WebFaction&lt;/a&gt; account using SSH and get it (adjust your actions according to the release): &lt;code&gt;wget http://kernel.org/pub/software/scm/git/git-1.6.5.6.tar.bz2&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Untar Git: &lt;code&gt;tar -xvjf git-1.6.5.6.tar.bz2&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Change into the Git directory: &lt;code&gt;cd git-1.6.5.6&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Configure it: &lt;code&gt;./configure --prefix=$HOME&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Make it: &lt;code&gt;make &amp;amp;&amp;amp; make install&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Now test to make sure everything worked by calling the Git version: &lt;code&gt;git version&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;You&#8217;ll need to edit .bashprofile and .bashhrc in your Webfaction home folder now to make sure that the Git command line works: &lt;pre&gt;&lt;code&gt;# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
GIT=/home/me/git-1.6.5.6/

export PATH
export PATH=$GIT:/home/me/ruby1.8/bin/:/home/me/ruby1.8/lib/ruby/gems/1.8/
bin/:$PATH
&lt;/code&gt;&lt;pre&gt;&lt;/li&gt;

&lt;li&gt;Create a zip archive of your app on your local machine.&lt;/li&gt;
&lt;li&gt;Go to your home folder, then create a place for your repository on the server: &lt;pre&gt;&lt;code&gt;cd
mkdir git&lt;/code&gt;&lt;/pre&lt;/li&gt;
&lt;li&gt;Back on your local machine, copy up your app: &lt;code&gt;scp /path/to/myapp.zip username@domain:~/git/&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Back on the server, unzip the application, then initialize a Git repository:
&lt;pre&gt;&lt;code&gt;cd git
unzip myapp.zip
cd myapp
git init
git add .
git commit -a -m &quot;Initial commit.&quot;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
&lt;li&gt;Back on your local machine, clone the Git repo, then Capify it:
&lt;pre&gt;&lt;code&gt;git clone me@domain:/home/me/git/myapp myapp
cd /path/to/myapp
capify .&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything worked this far? Great! On to the next step: the Capistrano recipe&amp;#8230;&lt;/p&gt;

&lt;h2 id=&quot;the_capistrano_recipe&quot;&gt;Step 2. The Capistrano Recipe (myapp/config/deploy.rb)&lt;/h2&gt;

&lt;script src=&quot;http://gist.github.com/171309.js&quot;&gt;&lt;/script&gt;


&lt;h2&gt;Step 3. Prepare Your App For Capistrano&lt;/h2&gt;
&lt;p&gt;Log into your Webfaction account and create a directory called webapps-releases, then empty your webapp folder, save for the autostart, and relink : &lt;pre&gt;&lt;code&gt;cd ~/webapps/myapp
mv autostart.cgi ~/
rm -rf *
mv ~/autostart.cgi .
ln -s ~/webapps-releases/myapp/shared/log ~/webapps/myapp/log&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now you want to edit the last line of your autostart: &lt;code&gt;os.system('/home/me/ruby1.8/lib/ruby/gems/1.8/bin/mongrel_rails start -c /home/me/webapps-releases/myapp/current -d -e production -P /home/me/webapps/myapp/log/mongrel.pid -p MY PORT NUMBER')&lt;/code&gt;

&lt;h2 id=&quot;final_steps&quot;&gt;Step 4. Final Steps&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Save the recipe and add it to your Git repo.
&lt;pre&gt;&lt;code&gt;git add .
git commit -a -m &quot;Capified.&quot;
git push&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;Now your are ready to begin your deployment:
&lt;pre&gt;&lt;code&gt;cap deploy:setup
cap deploy:update&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Future Deployments&lt;/h2&gt;
&lt;p&gt;If you&#8217;ve got this far without any problems, future deployments might be as easy as comitting your changes and deploying:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;git add .
git commit -m 'my latest commit'
git push origin master
cap deploy&lt;/code&gt;&lt;/pre&gt;
	
&lt;h2&gt;Notes&lt;/h2&gt;

&lt;p&gt;I have had problems with a few gems, namely &lt;a href='http://wiki.github.com/why/hpricot'&gt;Hpricot&lt;/a&gt; and &lt;a href='http://redcloth.org/'&gt;RedCloth&lt;/a&gt;, perhaps because they include non-Ruby files in C and Java etc). I found that the only way to get around these problems was to NOT INCLUDE THEM in the config.rb gem dependencies in my application. Just install them on your &lt;a href='http://www.webfaction.com?affiliate=lefthip'&gt;WebFaction&lt;/a&gt; via gem install hpricot, gem install RedCloth. I think these gems are also causing problems with the standard deploy procedure&amp;#8230;. If your app is not working after running cap deploy, you can try running&lt;/p&gt; 

&lt;code&gt;cap:deploy:restart&lt;/code&gt; 

&lt;p&gt;or&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;cap deploy:stop
cap:deploy:start&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Solving Restart Problems After Cap Deploy&lt;/h2&gt;

&lt;p&gt;I have been having problems and found that the procedure that works for me is to modify the capistrano restart procedure to this:&lt;/p&gt;
	
&lt;script src=&quot;http://gist.github.com/179918.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;Capistrano&#8217;s error messages are vague/non-existent as far as I can tell. I finally troubleshot my problems by modifying the capistrano gem itself to print out various parts of its process - eg the revision, the results, the command it was issuing, etc&amp;#8230;. you might try doing this, if you&#8217;re having problems. &lt;/p&gt;

&lt;h2&gt;Capistrano Migrations&lt;/h2&gt;

&lt;p&gt;I have had trouble with Capistrano&#8217;s cap deploy:migrate feature, and solved it like this:&lt;/p&gt;

&lt;script src=&quot;http://gist.github.com/179914.js&quot;&gt;&lt;/script&gt;

&lt;h2&gt;javan-whenever&lt;/h2&gt;

&lt;p&gt;I also had problem getting javan-whenever to update via Capistrano, and after much wrangling I finally started reading through Capistrano&#8217;s endless logging and discovered that sh was simply not finding whenever, so this worked for me:&lt;/p&gt;

&lt;script src=&quot;http://gist.github.com/179912.js&quot;&gt;&lt;/script&gt;
</story>
  <title>My Recipe For Capistrano/Git Rails Deployment on Webfaction</title>
  <updated-at type="datetime">2009-12-13T12:43:19-05:00</updated-at>
</blog>
