Launching Background Process in Capistrano Task

Running a capistrano task in background

I'd suggest making task B an actual Rake task, and then having Capistrano call and immediately background it, e.g. https://stackoverflow.com/a/5829142/3042016

Background task with Capistrano

I found a solution, just add pty: false at the end

run "cd #{deploy_to} && export PORT=#{server_port} && export ENV=#{env} && nohup target/start > /dev/null 2>&1 &" pty: false

Resque Capistrano Deployment in Rails

  1. It really depends on the size of your app. From my experience, generally a single Resque worker isn't much larger than your app's footprint. However, if your Resque worker will instantiate a lot of large objects, the size of the Resque instance could grow very quickly.

  2. Check out the capistrano-resque gem. It provides all this functionality for you, plus more. :)

  3. There are several options for this. A lot of people have followed something similar to this post about running Resque in Production and using the God gem. Personally, I've used a process similar to what is described in this post using Monit. Monit can be a bit of a pain to set up, so I'd strongly recommend checking out the God gem.

Spawn a background process in Ruby

As long as you are working on a POSIX OS you can use fork and exec.

fork = Create a subprocess

exec = Replace current process with another process

You then need to inform that your main-process is not interested in the created subprocesses via Process.detach.

job1 = fork do
exec "/path/to/daemon01"
end

Process.detach(job1)

...


Related Topics



Leave a reply



Submit