在Capistrano任务中启动后台进程 [英] launching background process in capistrano task

查看:81
本文介绍了在Capistrano任务中启动后台进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

capistrano任务

capistrano task

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

现在这不起作用:svscanboot进程根本无法运行. 这帮助我找到了sleep: https://github.com/defunkt/resque/issues/284 其他来源指出我是nohupredirectionpty => true,所以我尝试了所有这些.

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!

现在,有人可以向我解释为什么我需要睡眠声明,而nohup有何不同? 从记录来看,如果从用户外壳程序运行,以上所有功能同样运行良好,问题仅在于capistrano.

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.

谢谢

推荐答案

我的简单解决方案是使用要运行的任何代码在远程服务器上创建svscanboot.sh文件.就您而言

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

在上限耙任务中添加此

run "sh +x somefile.sh &"

这对我来说很好.

这篇关于在Capistrano任务中启动后台进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆