Topic: Restarting multiple Thins with Capistrano

Hi, I'm running a Rails application on 3 Thin instances with Apache as load balancer. What I want is to use Capistrano to restart the 3 Thin instances when I do "cap deploy".

When restart them manually and SSH to my server and use these commands to restart, everything works fine:

server_wrapper -p 3003 -s 3 stop

Stopping server on 0.0.0.0:3003 ... 
Sending QUIT signal to process 22205 ... 
>> Exiting!

Stopping server on 0.0.0.0:3004 ... 
Sending QUIT signal to process 22210 ... 
>> Exiting!

Stopping server on 0.0.0.0:3005 ... 
Sending QUIT signal to process 22215 ... 
>> Exiting!


server_wrapper -d -p 3003 -s 3 -e production start
Starting server on 0.0.0.0:3003 ... 
Starting server on 0.0.0.0:3004 ... 
Starting server on 0.0.0.0:3005 ... 

Where "server_wrapper" is nothing special, it changes some paths and executes "thin" with the parameters given:

#!/bin/sh
PATH=/opt/csw/bin:$PATH
export PATH
LD_LIBRARY_PATH=/opt/csw/lib/mysql:/usr/ucblib:
export LD_LIBRARY_PATH

thin "$@"

Now the problem is, what works fine manually doesn't do it with capistrano. I' trying to tell capistrano to stop the servers before doing any updates or changing symlinks and to start them afterwards, so my deploy.rb looks party like this (I'm not too familiar with Capistrano so that's mostly taken from a railscasts about Capistrano):

namespace :deploy do
  
  desc "Stops 3 thin servers starting from port 3003"
  task :stop_thins do
    run "#{current_path}/server_wrapper -p 3003 -s 3 stop"
  end
  
  desc "Restarts the Modulanmeldung, using 3 thin servers starting from port 3003."
  task :restart do
    run "#{current_path}/server_wrapper -d -p 3003 -s 3 -e production start"
  end
  
  desc "Symlink the database.yml to get the database password."
  task :symlink_shared do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end
  
end

before 'deploy:update_code', 'deploy:stop_thins'
after 'deploy:update_code', 'deploy:symlink_shared'

The start of deployment then looks like this:

cap deploy
SVN Username: username
  * executing `deploy'
  * executing `deploy:update'
 ** transaction: start
  * executing `deploy:update_code'
    triggering before callbacks for `deploy:update_code'
  * executing `deploy:stop_thins'
  * executing "/path/to/my/app/current/server_wrapper -p 3003 -s 3 stop"
    servers: ["my.server.de"]
Enter passphrase for /home/username/.ssh/key: 
    [my.server.de] executing command
 ** [out :: my.server.de] Stopping server on 0.0.0.0:3003 ...
 ** [out :: my.server.de] Can't stop process, no PID found in tmp/pids/thin.3003.pid
 ** [out :: my.server.de] Stopping server on 0.0.0.0:3004 ...
 ** [out :: my.server.de] Can't stop process, no PID found in tmp/pids/thin.3004.pid
 ** [out :: my.server.de] Stopping server on 0.0.0.0:3005 ...
 ** [out :: my.server.de] Can't stop process, no PID found in tmp/pids/thin.3005.pid
    command finished

... here comes the updating stuff, etc ...

What is confusing me the most is, that the pid Files should be there:

ls /path/to/my/app/current/tmp/pids
thin.3003.pid  thin.3004.pid  thin.3005.pid

Well my thoughts are: "stop_thins" is called before everything else, so "current_path" points to the actually running, not-updated-version. So there are the pid files and "ls" tells me that they are there. So why don't they seem to be there when capistrano tries to stop the thins? I don't get that..

I hope somebody here has advice, thanks in advance,

Bender

Last edited by bender (2011-01-04 16:02:06)