1

I want to start Queue Classic (QC) within my Capistrano recipe:

namespace :queue_classic do
  desc "Start QC worker"
  task :start, roles: :web do
    run "cd #{release_path} && RAILS_ENV=production bundle exec rake qc:work"
  end
  after "deploy:restart", "queue_classic:restart"
end

Capistrano runs the line correctly, so that the QC worker starts, but not as a daemon. As a result Capistrano won't continue to run the recipes.

How can I start the QC worker in the background and let Capistrano finish its tasks?

Thank you!

4

2 回答 2

2

I use foreman for this:

  after "deploy:update", "foreman:export"    # Export foreman scripts
  after "deploy:restart", "foreman:restart"   # Restart application scripts
  after "deploy:stop", "foreman:stop"   # Restart application scripts
  after "deploy:start", "foreman:start"

  # Foreman tasks

  desc 'Export the Procfile to Ubuntu upstart scripts'
  task :export, :roles => :queue do
    run "cd #{release_path}; #{sudo} $(rbenv which foreman) export upstart /etc/init -f ./Procfile -a #{application} -u #{user} -l #{release_path}/log/foreman"
  end

  desc "Start the application services"
  task :start, :roles => :queue do
    run "#{sudo} start #{application}"
  end

  desc "Stop the application services"

  task :stop, :roles => :queue do
    run "#{sudo} stop #{application}"
  end

  desc "Restart the application services"
  task :restart, :roles => :queue do
    run "#{sudo} stop #{application}"
    run "#{sudo} start #{application}"
    #run "sudo start #{application} || sudo restart #{application}"
  end

Then in your Procfile put something like

worker: RAILS_ENV=production bundle exec rake qc:work
于 2013-05-25T01:58:50.153 回答
0

Use the & sign at the and and put process in background.

run "cd #{release_path} && RAILS_ENV=production bundle exec rake qc:work &"

Killin and restarting is than a bit tricky, but it could be done using ps, grep and kill.

于 2013-01-30T07:43:06.043 回答