Module: Eye::Process::Config

Included in:
ChildProcess, Eye::Process
Defined in:
lib/eye/process/config.rb

Constant Summary collapse

DEFAULTS =
{
  :keep_alive => true, # restart when crashed
  :check_alive_period => 5.seconds,

  :start_timeout => 15.seconds,
  :stop_timeout => 10.seconds,
  :restart_timeout => 10.seconds,

  :start_grace => 2.5.seconds, 
  :stop_grace => 0.5.seconds, 
  :restart_grace => 0.5.seconds, 

  :daemonize => false,
  :auto_start => true, # auto start on monitor action

  :childs_update_period => 30.seconds
}

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object



44
45
46
# File 'lib/eye/process/config.rb', line 44

def [](name)
  @config[name]
end

#c(name) ⇒ Object



40
41
42
# File 'lib/eye/process/config.rb', line 40

def c(name)
  @config[name]
end

#control_pid?Boolean

is pid_file under Eye::Process control, or not

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/eye/process/config.rb', line 65

def control_pid?
  return self[:control_pid] unless self[:control_pid].nil?
  !!self[:daemonize]
end

#prepare_config(new_config) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/eye/process/config.rb', line 21

def prepare_config(new_config)
  h = DEFAULTS.merge(new_config)
  h[:pid_file_ex] = Eye::System.normalized_file(h[:pid_file], h[:working_dir]) if h[:pid_file]
  h[:checks] = {} if h[:checks].blank?
  h[:triggers] = {} if h[:triggers].blank?
  h[:childs_update_period] = h[:monitor_children][:childs_update_period] if h[:monitor_children] && h[:monitor_children][:childs_update_period]

  # check speedy flapping by default
  if h[:triggers].blank? || !h[:triggers][:flapping]
    h[:triggers] ||= {}
    h[:triggers][:flapping] = {:type => :flapping, :times => 10, :within => 10.seconds}
  end
  
  h[:stdout] = Eye::System.normalized_file(h[:stdout], h[:working_dir]) if h[:stdout]
  h[:stderr] = Eye::System.normalized_file(h[:stderr], h[:working_dir]) if h[:stderr]

  h    
end

#update_config(new_config = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/eye/process/config.rb', line 48

def update_config(new_config = {})
  new_config = prepare_config(new_config)
  @config = new_config
  @full_name = nil

  debug "update config to: #{@config.inspect}"

  remove_triggers
  add_triggers

  if up?
    # rebuild checks for this process
    from_up; on_up
  end    
end