Over a million developers have joined DZone.

Method For A Staggered Restart Of A Rails Site Running Fcgid And Capistrano

killing the dispatch processes too fast was triggering too many rails boots and making one of our sites thrash.  This bit of bash can be used to kill them softly. (with it's song...)

def dispatch_killer apache_user, seconds_between_kills=1
  run <<-CMD 
    pids=`ps -U #{apache_user} -o pid,command | grep #{current_path} | awk '{print $1;}'`;\
    for pid in $pids ;do \
      #{ sudo :as => remote_user } -u #{apache_user} kill $pid; \
      sleep #{seconds_between_kills}; \

a recipie could use this method like this:

namespace :deploy do
  task :restart, :roles => :app do
      dispatch_killer 'www', 10 # as www issue kills 10 seconds apart

we came up with 10 seconds by timing the boots of script/console. no more thrashing!
(props to James at http://www.titled.com for the idea)

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}