Capistrano won't spawn fcgi processes

I’ve ran into quiet an annoying problem: I have a Capistrano task
that is supposed to run a shell script. The script restarts a rails
application by first killing all active fcgi processes and then
spawning new ones again. The shell script works fine when executed
locally on the server but running this in a Capistrano task will
simply not work.

The task is simple:

desc “ReStart Rails”
task :rails_app_restart, :roles => :app do
run “#{home_directory}/etc/rc.d/restart_rails.sh”
end

my restart_rails.sh:

if [ -e home_dir/var/run/app-0.pid ]; then kill -9 cat home_dir/var/ run/app-0.pid; echo ‘Killed home_dir/var/run/app-0.pid’; fi
if [ -e home_dir/var/run/app-0.pid ]; then rm -f home_dir/var/run/
app-0.pid; echo ‘Force deleted home_dir/var/run/app-0.pid’; fi
if [ ! -e home_dir/var/run/app-0.pid ]; then RAILS_ENV=production /
usr/local/bin/spawn-fcgi -f base_path/current/public/dispatch.fcgi -s
home_dir/var/run/app-0.socket -P home_dir/var/run/app-0.pid; else
echo ‘home_dir/var/run/app-0.pid already exists.’; fi
if [ -e home_dir/var/run/app-1.pid ]; then kill -9 cat home_dir/var/ run/app-1.pid; echo ‘Killed home_dir/var/run/app-1.pid’; fi
if [ -e home_dir/var/run/app-1.pid ]; then rm -f home_dir/var/run/
app-1.pid; echo ‘Force deleted home_dir/var/run/app-1.pid’; fi
if [ ! -e home_dir/var/run/app-1.pid ]; then RAILS_ENV=production /
usr/local/bin/spawn-fcgi -f base_path/current/public/dispatch.fcgi -s
home_dir/var/run/app-1.socket -P home_dir/var/run/app-1.pid; else
echo ‘home_dir/var/run/app-1.pid already exists.’; fi

Again, no problem running this script directly. But when Capistrano
runs it, no processes are created even though the command output
indicates that everything was executed correctly. In fact, the socket
and pid files are created just fine by the cap task. The two fcgi
processes, however, never start. There’re no errors indicating any
kind of trouble.

I just can’t think of a single reason why this would start up fine
when running the script from the command line but not when executed
remotely via capistrano (and despite the good command output).
Anybody has an ideas where the problem could be? Thank you very much.

Sebastian

Sebastian F. wrote:

I’ve ran into quiet an annoying problem: I have a Capistrano task that
is supposed to run a shell script. The script restarts a rails
application by first killing all active fcgi processes and then spawning
new ones again. The shell script works fine when executed locally on the
server but running this in a Capistrano task will simply not work.

Here’s one answer: http://tinyurl.com/jx4bk

Ray

thanks. unfortunately the answer didn’t yet solve the problem. the
problem seems to have nothing to do with the script itself but with
the way capistrano executes it. If anybody has any idea, please have
a look at the ongoing discussion on technoweenie: http://tinyurl.com/
jx4bk Thanks and sorry for the x-posting.

Sebastian