Welcome Guest | Login

Capistrano Woes

Hey!

I'm trying to deploy the Beast forum using Capistrano, Radrails and SVN and it's proving to be a major headache.

The files themselves are looking good (ie changes, to fastcgi, shebang, .htaccess, env.rb). I've tested deploying the application manually by following the tutorial @ HostingRails, and it works great.

However, when using capistrano, I run "cap cold_deploy" and it always fails when it gets to the restart task, providing me with

* executing task restart
 * executing "/home/iskandu/beastfash/current/script/process/reaper"
   servers: ["iskandu.com"]
   [iskandu.com] executing command
** [out :: iskandu.com] Couldn't find any pid file in '/home/iskandu/beastfash/
current/tmp/pids' matching
** [out :: iskandu.com] 'dispatch.[0-9]*.pid'
** [out :: iskandu.com] (also looked for processes matching "/home/iskandu/beas
tfash/current/public/dispa
** [out :: iskandu.com] tch.fcgi")
   command finished "
Any idea how to fix this?

When I travel over to my domain of iskandu.com, all I see is a generic "Application error
Rails application failed to start properly"

Initially I left the restart task as it was when I had the deploy.rb created for me, and this gave the sudo error that is in the thread "http://www.hostingrails.com/forums/deployment_troubleshooting_thread/48"

The strange thing is that it's still called reaper in the restart task, even though I'm specifying in the deploy.rb for it not too. Is this a special case that I'm unaware about?

Here's a copy of my deploy.rb
set :application, "beastfash"
set :repository, "svn+ssh://iskandu@iskandu.com/home/iskandu/svn/beastfash/trunk"

role :web, "iskandu.com"
role :app, "iskandu.com"
role :db,  "iskandu.com", :primary => true

set :deploy_to, "/home/iskandu/beastfash" # defaults to "/u/apps/#{application}"
set :user, "iskandu"            # defaults to the currently logged in user
set :use_sudo, false
set :checkout, "export"
set :restart_via, :run


desc <<DESC
An imaginary backup task. (Execute the 'show_tasks' task to display all
available tasks.)
DESC
task :backup, :roles => :db, :only => { :primary => true } do
 on_rollback { delete "/tmp/dump.sql" }

 run "mysqldump -u theuser -p thedatabase > /tmp/dump.sql" do |ch, stream, out|
   ch.send_data "thepassword\n" if out =~ /^Enter password:/
 end
end

desc "link in production database credentials"
task :after_update_code do
 run <<-CMD
 ln -nfs #{deploy_to}/#{shared_dir}/config/database.yml #{release_path}/config/database.yml
 CMD
 run "chmod +x #{release_path}/script/process/reaper"
 run "chmod +x #{release_path}/script/process/spawner"
 run "chmod a+x #{release_path}/public/dispatch.fcgi"
end

desc "A task demonstrating the use of transactions."
task :long_deploy do
 transaction do
   update_code
   disable_web
   symlink
   migrate
 end

desc "Restarting after deployment"
   task :after_deploy, :roles => [:app, :db, :web] do
    run "touch /home/iskandu/beastfash/current/public/dispatch.fcgi"
   end

   desc "Restarting after rollback"
   task :after_rollback, :roles => [:app, :db, :web] do
    run "touch /home/iskandu/beastfash/current/public/dispatch.fcgi"
   end
   
   task :restart, :roles => :app do
# do nothing but overide the default
end
   
end

I've symlinked the ~/beastfash/current/public to ~/public_html and that doesn't seem to help either.

I've run script/console production from within the directory and that loads fine, and I'm able to play with my variables etc.

I'm certain that my htaccess, shebang, environment.rb is correct. Should these be different from the tutorial for Capistrano to work properly?

Thank you very much for any feedback/help!

2007-01-09 01:41 AM

Hmmmm - there's a number of things we can try. First of all the reaper is looking for the fastcgi pid, you want to make this task just kill off the dispatch.fcgi (with just a killall dispatch.fcgi or something)

Second, what exactly is the error then that's preventing your app to startup? Let me know if you need help troubleshooting that.



2007-01-09 05:03 AM

I am having a very similar problem, but am unable to fix the problem. I am doing a sudo killall on dispatch.fcgi. The wierd issue is that the coder that has been helping me has had no problem deploying from his machine. Furthermore, we are both committing from and updating from the same svn - therefore, we are using the same deploy.rb file.  

Any thoughts or pointers where I should look to solve this issue? cap deploy:restart seems to be the main culprit. Thanks in advance.



The following is the error:
executing `deploy:restart'
 * executing "/home/unitede/apps/uegapp/current/script/process/reaper"
   servers: ["owen.hostingrails.com"]
   [owen.hostingrails.com] executing command
** [out :: owen.hostingrails.com] Couldn't find any pid file in '/home/unitede/apps/uegapp/current/tmp/pids' matching 'dispatch.[0-9]*.pid'
** [out :: owen.hostingrails.com] (also looked for processes matching "/home/unitede/apps/uegapp/current/public/dispatch.fcgi")
The following is the deploy.rb file:
# This defines a deployment "recipe" that you can feed to capistrano
# http://manuals.rubyonrails.com/read/book/17). It allows you to automate
# (among other things) the deployment of your application.

# =============================================================================
# REQUIRED VARIABLES
# =============================================================================
# You must always specify the application and repository for every recipe. The
# repository must be the URL of the repository you want this recipe to
# correspond to. The deploy_to path must be the path on each machine that will
# form the root of the application path.

set :application, "uegapp"
set :domain, "owen.hostingrails.com"
set :user, "unitede"

set :repository,  "svn+ssh://#{user}@#{domain}/home/#{user}/svn/#{application}/trunk"
set :use_sudo, false
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :checkout
set :chmod755, "app config db lib public vendor script script/* public/disp*"
set :mongrel_port, "4104"

# =============================================================================
# ROLES
# =============================================================================
# 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, :primary => true

# =============================================================================
# OPTIONAL VARIABLES
# =============================================================================
# set :deploy_to, "/path/to/app" # defaults to "/u/apps/#{application}"
# set :user, "flippy"            # defaults to the currently logged in user
# set :scm, :darcs               # defaults to :subversion
# set :svn, "/path/to/svn"       # defaults to searching the PATH
# set :darcs, "/path/to/darcs"   # defaults to searching the PATH
# set :cvs, "/path/to/cvs"       # defaults to searching the PATH
# set :gateway, "gate.host.com"  # default to no gateway

# =============================================================================
# SSH OPTIONS
# =============================================================================
# ssh_options[:keys] = %w(/path/to/my/key /path/to/another/key)
# ssh_options[:port] = 25

# =============================================================================
# TASKS
# =============================================================================
# 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 <<DESC
An imaginary backup task. (Execute the 'show_tasks' task to display all
available tasks.)
DESC
task :backup, :roles => :db, :only => { :primary => true } do
 # the on_rollback handler is only executed if this task is executed within
 # a transaction (see below), AND it or a subsequent task fails.
 on_rollback { delete "/tmp/dump.sql" }

 run "mysqldump -u theuser -p thedatabase > /tmp/dump.sql" do |ch, stream, out|
   ch.send_data "thepassword\n" if out =~ /^Enter password:/
 end
end

# Tasks may take advantage of several different helper methods to interact
# with the remote server(s). These are:
#
# * run(command, options={}, &block): execute the given command on all servers
#   associated with the current task, in parallel. The block, if given, should
#   accept three parameters: the communication channel, a symbol identifying the
#   type of stream (:err or :out), and the data. The block is invoked for all
#   output from the command, allowing you to inspect output and act
#   accordingly.
# * sudo(command, options={}, &block): same as run, but it executes the command
#   via sudo.
# * delete(path, options={}): deletes the given file or directory from all
#   associated servers. If :recursive => true is given in the options, the
#   delete uses "rm -rf" instead of "rm -f".
# * put(buffer, path, options={}): creates or overwrites a file at "path" on
#   all associated servers, populating it with the contents of "buffer". You
#   can specify :mode as an integer value, which will be used to set the mode
#   on the file.
# * render(template, options={}) or render(options={}): renders the given
#   template and returns a string. Alternatively, if the :template key is given,
#   it will be treated as the contents of the template to render. Any other keys
#   are treated as local variables, which are made available to the (ERb)
#   template.

desc "Demonstrates the various helper methods available to recipes."
task :helper_demo do
 # "setup" is a standard task which sets up the directory structure on the
 # remote servers. It is a good idea to run the "setup" task at least once
 # at the beginning of your app's lifetime (it is non-destructive).
 setup

 buffer = render("maintenance.rhtml", :deadline => ENV['UNTIL'])
 put buffer, "#{shared_path}/system/maintenance.html", :mode => 0644
 sudo "killall -USR1 dispatch.fcgi"
 run "#{release_path}/script/spin"
 delete "#{shared_path}/system/maintenance.html"
end

# You can use "transaction" to indicate that if any of the tasks within it fail,
# all should be rolled back (for each task that specifies an on_rollback
# handler).

desc "A task demonstrating the use of transactions."
task :long_deploy do
 transaction do
   update_code
   disable_web
   symlink
   migrate
 end

 restart
 enable_web
end

task :start, :roles => :app do
 run "rm -rf /home/#{user}/public_html;ln -s #{current_path}/public /home/#{user}/public_html"
 run "cd #{current_path} && mongrel_rails start -e production -p #{mongrel_port} -d"
end

task :restart, :roles => :app do
 run "cd #{current_path} && mongrel_rails restart"
 run "cd #{current_path} && chmod 755 #{chmod755}"
end

task :after_update_code, :roles => :app do
 %w{exhibits}.each do |share|
   run "rm -rf #{release_path}/public/#{share}"
   run "mkdir -p #{shared_path}/system/#{share}"
   run "ln -nfs #{shared_path}/system/#{share} #{release_path}/public/#{share}"
 end
end




2007-11-05 07:20 PM

You cannot use sudo on HostingRails' servers, hence why ":use_sudo => false" above.  

Check out these threads for implementation.
cap1 -> http://www.hostingrails.com/forums/wiki_thread/5
cap2 -> http://www.hostingrails.com/forums/wiki_thread/46


2007-11-06 01:47 AM

Thanks for the pointer, it helped me realize the issue. I was using Capistrano 2, and the other person working on the app with me was using Capistrano 1.x.

First I: deleted the Capfile created by Capistrano 2.0
Then I: sudo gem uninstall capistrano --version '2.0'
Next I: sudo gem install capistrano --version '1.4.1'
And finally I ran: cap deploy

and it worked.


This post helped as well:
http://forums.planetargon.com/forums/3/topics/79

2007-11-06 05:17 PM


Hello Guest! In order to post you must be an active client with us, please log in or sign up.