Skip to content


Capistrano + Fetcher/Daemonize

So I’ve spent the afternoon slogging through this little problem. Something tells me I’m going to be referring to this post again and again.

Are you using the fetcher plugin and Capistrano for deployment? Hey, me too! Apparently I’m the only one in the world who didn’t immediately know how to make them work together though.

Here are my Capistrano tasks for starting/stopping/restarting my fetcher daemons:

after "deploy:restart", "fetcher:restart"

namespace :fetcher do
  desc "Stop the fetcher_mailer daemons"
  task :stop, :roles => :app do
    run "RAILS_ENV=#{rails_env} ruby #{current_path}/script/mailer_daemon_fetcher stop"
  end

  desc "Start the fetcher_mailer daemons"
  task :start, :roles => :app do
    run "RAILS_ENV=#{rails_env} nohup /opt/ruby-enterprise/bin/ruby #{current_path}/script/mailer_daemon_fetcher start", :pty => true
  end

  desc "Restart (cycle) the fetcher_mailer daemons"
  task :restart, :roles => :app do
    stop
    start
  end
end

The real key here is on the :start task, there are two things you need to do to get the shell to let go of the process.:

  1. Add the nohup to your command. If you don’t do this the process goes into the background, and as soon as the shell exits the OS says “SIGHUP” (“you don’t have to go home, but you can’t stay here.”)
  2. The second thing is the :pty => true. This tells Capistrano to request a pseudo terminal. I don’t know all the nitty gritty, and have neither the time nor the inclination to dig in and find out why.

So there you go, add a nohup and :pty => true and then you can get your fetcher daemon backgrounded.

Posted in Rails, Ruby, Software Development, Tips and Tricks.

Tagged with , , , , , , .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.