感谢@xvidun,我找到了解决办法:使用god。
关键的过程是:如何使非守护进程作为守护进程启动。 “nohup ... &”不适合我。所以我尝试了上帝,这太棒了!
在我的情况下,这个过程中我要运行是:
$ cd /sg552/workspace/m-video-fetcher
$ nohup ruby script/start_fetch.rb &
这里是我做的工作:
第一步:创建一个上帝的配置文件:
# file name: fetcher.god
RAILS_ROOT = '/sg552/workspace/m-video-fetcher'
God.watch do |w|
w.name = 'fetcher'
w.dir = RAILS_ROOT
w.start = "ruby script/start_fetch.rb"
w.log = "#{RAILS_ROOT}/fetcher_stdout.log"
w.keepalive
end
step2:
$ god start -c fetcher.god
第三步:
# in the view, give users the interface to restart this job.
# in the controller:
def restart_fetch_for_all_plans
result = `god stop fetcher && god start fetcher`
redirect_to :back, :notice => "fetcher restarted, #{result}"
end