Class: ProcessHellFire

Inherits:
Object
  • Object
show all
Defined in:
lib/process_control.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProcessHellFire

Returns a new instance of ProcessHellFire.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/process_control.rb', line 15

def initialize
  @exec = ''
  @orig_exec = ''
  @wait_until_timeout = 0
  @wait_until_proc = nil
  @kill_children = kill_children
  @interval = interval
  @restart_items = []
  @exec_live_cfg = ''
  @exec_maintenance_cfg = ''
  @kill_signal = 'TERM'
  @restart = true
  @usr1= ''
  @mode = 'live'
end

Instance Attribute Details

#execObject

Returns the value of attribute exec.



14
15
16
# File 'lib/process_control.rb', line 14

def exec
  @exec
end

#exec_live_cfgObject

Returns the value of attribute exec_live_cfg.



14
15
16
# File 'lib/process_control.rb', line 14

def exec_live_cfg
  @exec_live_cfg
end

#exec_maintenance_cfgObject

Returns the value of attribute exec_maintenance_cfg.



14
15
16
# File 'lib/process_control.rb', line 14

def exec_maintenance_cfg
  @exec_maintenance_cfg
end

#intervalObject

Returns the value of attribute interval.



14
15
16
# File 'lib/process_control.rb', line 14

def interval
  @interval
end

#kill_childrenObject

Returns the value of attribute kill_children.



14
15
16
# File 'lib/process_control.rb', line 14

def kill_children
  @kill_children
end

#kill_signalObject

Returns the value of attribute kill_signal.



14
15
16
# File 'lib/process_control.rb', line 14

def kill_signal
  @kill_signal
end

#usr1Object

Returns the value of attribute usr1.



14
15
16
# File 'lib/process_control.rb', line 14

def usr1
  @usr1
end

Instance Method Details

#loggerObject



31
32
33
34
35
36
37
38
# File 'lib/process_control.rb', line 31

def logger
  begin
    require BASE + '/lib/log'
    include InlineLogger
  rescue => e
    puts "EEEEE: #{e.inspect}"
  end
end

#monitorObject

Raises:

  • (StandardError)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/process_control.rb', line 51

def monitor
  raise StandardError if @exec == '' || @interval < 2
  set_traps
  while true
    exec = use_exec
    pids = ProcessMgt.pids_with_children(:search => exec, :exclude => 'process_control')
    res=false
    @restart_items.each { |item|
      begin
        next unless item.respond_to?(:call)
        res = item.call
        break if res == true
      rescue => e
      end
    }
    if (pids == '' || res) && @restart
      restart 
    end
    sleep @interval
  end
end

#restart_on_condition(condition) ⇒ Object



46
47
48
# File 'lib/process_control.rb', line 46

def restart_on_condition(condition)
  @restart_items << condition
end

#wait_until(timeout = 10, proc_ = '') ⇒ Object

Raises:

  • (StandardError)


40
41
42
43
44
# File 'lib/process_control.rb', line 40

def wait_until(timeout=10, proc_='')
  raise StandardError unless proc_.kind_of?(Proc)
  @wait_until_timeout = timeout
  @wait_until_proc = proc_
end