【问题标题】:Gem Daemons - How to run several different daemonsGem Daemons - 如何运行几个不同的守护进程
【发布时间】:2012-06-30 21:24:03
【问题描述】:

基本上我只想在我的 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' (与 'status'/'stop' 完美配合)时,第二个 Daemons.run 永远不会被调用。正确的做法是什么?

【问题讨论】:

    标签: ruby daemon


    【解决方案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
    

    合适吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-02
      • 1970-01-01
      • 1970-01-01
      • 2012-10-13
      • 2014-07-03
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      相关资源
      最近更新 更多