Class: DaemonSpawnBase
- Inherits:
-
DaemonSpawn::Base
- Object
- DaemonSpawn::Base
- DaemonSpawnBase
- Defined in:
- lib/daemon_spawn_base.rb
Instance Method Summary collapse
-
#initialize(args) ⇒ DaemonSpawnBase
constructor
A new instance of DaemonSpawnBase.
- #start(_) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(args) ⇒ DaemonSpawnBase
Returns a new instance of DaemonSpawnBase.
5 6 7 8 9 10 11 12 |
# File 'lib/daemon_spawn_base.rb', line 5 def initialize(args) GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=) @args = args @procs = @args[:procs] @restart = true super end |
Instance Method Details
#start(_) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/daemon_spawn_base.rb', line 14 def start(_) raise "empty @procs" if !@procs || @procs.empty? # HUP is restart all childs trap("HUP") do stop_all end @args[:before_fork].call if @args[:before_fork] start_all while @restart pid = nil begin pid = Process.wait rescue Errno::ECHILD end process = @procs.detect{|p| p.pid == pid } puts "#{process.name} had just died!" process.start if @restart end rescue stop_all end |
#stop ⇒ Object
44 45 46 47 |
# File 'lib/daemon_spawn_base.rb', line 44 def stop @restart = false stop_all end |