Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

launching background process in capistrano task

capistrano task

namespace :service do
  desc "start daemontools (svscan/supervise/svscanboot)"
  task :start, :roles => :app do
    sudo "svscanboot&"
  end
end

Now this doesn't work: the svscanboot process simply doesn't run. This helped me find sleep: https://github.com/defunkt/resque/issues/284 other sources pointed me to nohup, redirection, and pty => true, so I tried all these.

run "nohup svscanboot >/tmp/svscanboot.log 2>&1 &"   # NO
run "(svscanboot&) && sleep 1"                       # NO
run "(nohup svscanboot&) && sleep 1"                 # YES!

Now, could anyone explain to me why i need the sleep statement and what difference does nohup make? For the record all the above run equally well if run from user shell, problem is only in the context of capistrano.

thanks

like image 621
Viktor Trón Avatar asked Jun 04 '12 23:06

Viktor Trón


1 Answers

Try forking the process as explained here: Spawn a background process in Ruby

You should be able to do something like this:

job1 = fork do
  run "svscanboot"
end

Process.detach(job1)

As well, checkout this: Starting background tasks with Capistrano

like image 194
Jonathan MacDonald Avatar answered Nov 09 '22 23:11

Jonathan MacDonald