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.

tags: backgroundrb

backgroundrb - failed to find slave socket October 13th, 2007

Ugh. Another madness inducing bug that I post in hopes that others will have easier Googling.

I was trying to spawn backgroundrb processes. Scheduled processes worked, but when I spawned new ones they sometimes do, sometimes don't work. And I was seeing the "failed to find slave socket" error. Couldn't figure it out and Google wasn't immediately helpful. But here is what it appears to break down to.

When it creates socket files in /tmp to it truncates the worker key onto the end of your workers name. Well, there is a limit to how long that file name can be before it blows up. Looks like the name of your worker class, including underscores, needs to be 25 or less characters or it will create an invalid file name and blow up.

See also this ticket, which doesn't mention this error specifically but pointed me to the apparent answer. Hope it saves others my headache for the last week or so.

tags: backgroundrb