基本上我只想在我的ruby脚本中运行几个守护进程:
require 'daemons'
Daemons.run path_1, { :ARGV => ['start'], :app_name => 'app1', :multiple => true, ... }
Daemons.run path_2, { :ARGV => ['start'], :app_name => 'app2', :multiple => true, ... }
但是当ARGV [0] =='start'时,第二个Daemons.run从未被调用(与'status'/'stop'完美配合)。什么是正确的方法?
答案 0 :(得分:1)
来自http://daemons.rubyforge.org
3-从另一个应用程序控制一堆守护进程
布局:你有一个应用程序my_app.rb想要运行一堆服务器任务作为守护程序进程。
# this is my_app.rb
require 'rubygems' # if you use RubyGems
require 'daemons'
task1 = Daemons.call(:multiple => true) do
# first server task
loop {
conn = accept_conn()
serve(conn)
}
end
task2 = Daemons.call do
# second server task
loop {
something_different()
}
end
# the parent process continues to run
# we can even control our tasks, for example stop them
task1.stop
task2.stop
exit
适合吗?