14 February 2007

Deploying a rails application on site5

It took me a while - 2 days and a half ! - but I finnaly managed to deploy my application on site5 using capistrano!

The toughest part was understanding this error message:

error: directory is writable by others: (/home/xxxxxx/rails/webapps/xxxx/releases/20070213163348/public)
[warn] FastCGI: (dynamic) server "/home/xxxxx/public_html/xxxxx/dispatch.fcgi"
has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off
to 600 seconds

It turned out - as I found in the site5 forum - that site5 has CGI/FCGI configured to shut down scripts that are group- or world-writable. As of 1.3, Capistrano issues a "chmod g+w" command over the entire check-out branch.

The solution was to change the permissions in a :after_update_code task.

The thing is, site5 is cheap but it so sloooooooooow! not sure how long I am going to pay for such a service.

# Capistrano deployment script on site 5
# Jean-Michel Garnier
# Tested with capistrano 1.40 14/02/2007
# Inspired by http://fluctisonous.com/2006/11/19/moving-home-with-capistrano-on-site5
# And Kyle Daigle http://forums.asmallorange.com/index.php?showtopic=8892

# Usage:
# the first time: cap setup
# Then to initialize the db the first time- if you have a bootstrap task like in mephisto -
# env BOOTSTRAP=true cap deploy
# otherwise: cap deploy

# =============================================================================
# Customize these variables
# =============================================================================

set :application, "bicinostrum"

set :user, "your userlogin at site5" # defaults to the currently logged in user
set :password, "your site5 password"
set :domain, "21croissants.com" # your applications domain name
#set :deploy_server, "you.server.name" # the url of your server

set :public_html, "/home/#{user}/public_html/#{application}"
set :svn_repositoty_home, "rails/svn_repository"
set :rails_apps_home, "rails/webapps"

# =============================================================================
# Do not change these variables
# =============================================================================
set :use_sudo, false
set :rails_env, "production"
set :deploy_to, "/home/#{user}/#{rails_apps_home}/#{application}"
set :repository, "svn+ssh://#{user}@#{domain}/home/#{user}/#{svn_repositoty_home}/#{application}/trunk"

# =============================================================================
# =============================================================================
# You can define any number of roles, each of which contains any number of
# machines. Roles might include such things as :web, or :app, or :db, defining
# what the purpose of each machine is. You can also specify options that can
# be used to single out a specific subset of boxes in a particular role, like
# :primary => true.

role :web, domain
role :app, domain
role :db, domain

# =============================================================================
# =============================================================================

set :svn_passphrase, ""
# ssh_options[:port] = 25

# =============================================================================
# =============================================================================
# Define tasks that run on all (or only some) of the machines. You can specify
# a role (or set of roles) that each task should be executed on. You can also
# narrow the set of servers to a subset of a role by specifying options, which
# must match the options given for the servers to select (like :primary => true)

desc "Restart the web server. Overrides the default task for Site5 use"
task :restart, :roles => :app do
run "skill -9 -u#{user} -cdispatch.fcgi"

task :after_setup, :roles => :app do
run <<-CMD
ln -s /home/#{user}/#{rails_apps_home}/#{application}/current/public/ #{public_html}


task :after_update_code, :roles => :app do
run "find #{release_path}/public -type d -exec chmod 0755 {} \\;"
run "find #{release_path}/public -type f -exec chmod 0644 {} \\;"
run "chmod 0755 #{release_path}/public/dispatch.*"

run <<-EOF
cd #{release_path} && rake db:bootstrap RAILS_ENV=production
run <<-EOF
cd #{release_path} && rake db:migrate RAILS_ENV=production


Kule said...

FYI you can just override the set_permissions task so you dont have to reset permissions. e.g.

task :set_permissions do
donothing = true

Matt said...

Thanks dude, you helped me out with that post :-)

Brian said...


Do a quick search on "cdispatch" in your script. Did you miss a space there?

Otherwise, this is by far the best example I've seen. I think it is the only one that worked with site5 and the latest version of capistrano (2.1) for me. It was those chmod's that did the trick!! No other deploy.rb file I tried had those.

Thanks a million!

RandyInLA said...

Right on! I had to comment out the migration lines as it was throwing errors during deployment and then backing out at the end. The chmod stuff seems to be the culprit though, as I was able to get my app to make a few short appearances.
I did a rake rails:freeze:gems (rails 2.0.2) along the way, do you think I don't need that anymore, or should I leave it since it's working?

Nate said...

Thank you for your code.

I noticed that the skill -9 command doesn't find any of my dispatch.fcgi processes.

I get the error message:
Couldn't find any process matching: dispatch.fcgi

When I type ps -ef | grep username, I see this:

/usr/bin/ruby dispatch.fcgi

I've tried using various forms of the skill command, but can't seem to kill those pesky dispatch.fcgi

Thanks for the code, and please post back if anyone finds a way of restarting the dispatch.fcgi process.

I see this:

Ashleywnj said...

Hi - thanks so much for sharing your experiences and offering help.

After many hours (days) I narrowed my deploy down to one error, then I found your post. Running deploy check now runs 'clean'

-command finished
-You appear to have all necessary
-dependencies installed

However when I run deploy cold it just hangs on the following:

>cap deploy:cold
* executing `deploy:cold'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'

Anyone have any ideas? I am new to Ruby and RoR.

Thanks so much!


Ravicious said...

Ok, but what I should do, when I use Git?