launching background process in capistrano task

前端 未结 5 685
傲寒
傲寒 2020-12-29 11:59

capistrano task

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


        
相关标签:
5条回答
  • 2020-12-29 12:26

    I think nohup just launches the process in background, so you don't need to explicitly set the last &.

    Did you try

    run "nohup svscanboot >/tmp/svscanboot.log 2>&1"

    (without the ending & to send it to the background).

    That should work and remain running when your current capistrano session is closed.

    0 讨论(0)
  • 2020-12-29 12:30

    Try this

    run "nohup svscanboot >/tmp/svscanboot.log 2>&1 & sleep 5", pty: false
    
    0 讨论(0)
  • 2020-12-29 12:36

    My simple solution would be make svscanboot.sh file at remote server with whatever code you want to run. In your case

    svscanboot >/tmp/svscanboot.log 2>&1
    

    In cap rake task add this

    run "sh +x somefile.sh &"
    

    this works well for me.

    0 讨论(0)
  • 2020-12-29 12:51

    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

    0 讨论(0)
  • 2020-12-29 12:52

    I'd like to share my solution which also works when executing multiple commands. I tried many other variants found online, including the "sleep N" hack.

    run("nohup sh -c 'cd #{release_path} && bundle exec rake task_namespace:task_name RAILS_ENV=production > ~/shared/log/<rakelog>.log &' > /dev/null 2>&1", :pty => true)
    
    0 讨论(0)
提交回复
热议问题