how to run rake task in background in rails

manish nautiyal picture manish nautiyal · May 29, 2013 · Viewed 13.2k times · Source

This is my command

bundle exec rake resque:work QUEUE="*" --trace

I want to run this command on my server as a background process.

please help me.

Answer

lurker picture lurker · May 29, 2013

A method I often use is:

nohup bundle exec rake resque:work QUEUE="*" --trace > rake.out 2>&1 &

This will keep the task running even if you exit your shell. Then if I want to just observe trace output live, I do:

tail -f rake.out

And you can examine rake.out at any time.

If you need to kill it before completion, you can find it with ps and kill the pid.