NOTE: These instructions were written for capistrano 1.4. I haven't used the new 2.0 version yet. Also, I'm assuming you've used Capistrano before and already have your app in svn.
The way webfaction handles your rails setup with fancy point and click hand-holding is great. Until you want to set your site up to use Capistrano. The problem boils down to two major issues:
- The root of your app on the server is setup automatically and is owned by root. You can't change it.
- The server wants to start your site with an autostart.cgi script.
There's probably a better way to do this, but here's how I set things up...
SSH to the server, and create a directory called "webapps-releases"
$: ssh username.webfactional.com
$: mkdir webapps-releases
Back on your local machine, install capistrano, and apply it to your app:
$: sudo gem install capistrano -y
$: cd ~/Sites/myapp
$: cap --apply-to .
Open myapp/config/deploy.rb and set the :application, :repository, and roles normally. In the "OPTIONAL VARIABLES" section, set these variables:
set :deploy_to, "/home/username/webapps-releases/myapp"
set :user, "username"
set :use_sudo, false
In the "TASKS" section, add these tasks:
desc "Symlink public to what webfaction expects the webroot to be"
task :after_symlink, :roles => :web do
run "ln -nfs #{release_path}/public /home/username/webapps/rails/"
end
desc "Call reaper with custom options"
task :restart, :roles => :web do
run "#{deploy_to}/current/script/process/reaper -p /home/username/webapps/rails/log -r mongrel.pid"
end
Close deploy.rb and run setup:
$: cap setup
In your webfaction control panel, setup a normal rails app.
On the server, you should now have a directory at ~/webapps/rails filled will all the default rails files, plus an autostart.cgi script. Delete everything except autostart.cgi
Create a symbolic link to the log directory:
$: ln -s ~/webapps-releases/myapp/shared/log ~/webapps/rails/log
Open autostart.cgi. Comment out the last line, it should look something like this:
os.system('/usr/local/bin/mongrel_rails start -d -e production -P /home/username/webapps/rails/log/mongrel.pid -p 2507')
Your port number will probably differ, take that into account and add a line like this directly beneath the line you just commented out:
os.system('cd /home/username/webapps-releases/myapp/current && /usr/local/bin/mongrel_rails start -d -e production -P /home/username/webapps/rails/log/mongrel.pid -p 2507
Back on your local machine, deploy your site:
$: cap deploy_with_migrations
That should be it. You can now use cap normally. If you want to set up a mongrel cluster, contact webfaction, I hear they're pretty helpful.