9

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.

manish nautiyal
  • 2,556
  • 3
  • 27
  • 34

2 Answers2

34

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.

lurker
  • 56,987
  • 9
  • 69
  • 103
  • `tail -f rake.out` does not show me the console output from the rake process. How to see the console output? – LINGS Jul 24 '14 at 17:18
  • @LINGS when I use teh above technique, I do get the rake console output. What does your command line look like? – lurker Jul 24 '14 at 19:50
  • So I execute `nohup bundle exec rake pr:monitor --trace > monitor.out 2>&1 &`. When I `tail -f monitor.out`, I get `** Invoke pr:monitor (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute pr:monitor` – LINGS Jul 27 '14 at 16:20
  • @LINGS if you run that without the `nohup` and without the `> monitor.out 2>&1 &` do you get any more output than that? Maybe it's an issue with the `rake` task? Perhaps you should open a stackoverflow.com question for the issue. – lurker Jul 27 '14 at 17:35
  • Assume after run the daemon task you have closed the terminal(console) . Now reopen and go the folder and `ps` doesn't give the background task. So how to kill it? – isaman kumara May 31 '19 at 08:31
8

Just in case somebody finds this 4 years later, bundle has an elegant way of doing this now. For example if you want to run sidekiq in the background you can do:

bundle exec sidekiq -e production -d -L ./log/sidekiq.log 

The -d daemonizes to run in the background, but you will also need to use the -L to provide a logfile, else bundler will refuse to run your command in the background (deamonize). Tested with bundler version 1.15.4

Update Oct 2019. While the command still works in general, the specific command above will no longer work for sidekiq 6.0+, you'll need to use Upstart or Systemd if you use Linux: https://github.com/mperham/sidekiq/wiki/Deployment#running-your-own-process

brod
  • 244
  • 3
  • 8