backgroundrb + capistrano ftw January 21st, 2008

UPDATE: Latest version of script includes the port number(2000 by default) in the pid name.

I've had some ongoing issues getting capistrano and backgroundrb to play nice. So I thought I would do something about it today. I found a nice starting point from some one else. But I wanted to use invoke_command, so that it would be (hopefully) a bit more universal and use/not use sudo as neccesary. Also, if there is no pid file backgroundrb stop doesn't do anything other than fail and stop the execution of the rest of the chain. So I wanted to make it skip over the stop command if the pid file did not exist. So, without further adou here is what I ended up with.

  namespace :backgroundrb do
    desc "stop the backgroundrb server"
    task :stop, :roles => :app do
      invoke_command "sh -c 'if [ -a #{current_path}/log/backgroundrb_2000.pid ]; then #{current_path}/script/backgroundrb stop; fi;'", :via => run_method
    end
    
    desc "start the backgroundrb server"
    task :start, :roles => :app do
      invoke_command "nohup #{current_path}/script/backgroundrb start -d", :via => run_method
    end
    
    desc "restart the backgroundrb server"
    task :restart, :roles => :app do
      deploy.backgroundrb.stop
      deploy.backgroundrb.start
    end
  end
Comments and suggestions on how to improve this or make it more universal are greatly appreciated. Hope it can save somebody else some of my headaches.

Sorry, comments are closed for this article.