Class: Eye::ChildProcess

Inherits:
Object show all
Includes:
Celluloid, Process::Commands, Process::Config, Process::Data, Process::Notify, Process::Scheduler, Process::System, Process::Watchers
Defined in:
lib/eye/child_process.rb

Constant Summary

Constants included from Process::Notify

Process::Notify::LEVELS

Constants included from Process::Config

Process::Config::DEFAULTS

Instance Attribute Summary collapse

Attributes included from Process::Scheduler

#current_scheduled_command, #last_scheduled_at, #last_scheduled_command, #last_scheduled_reason

Instance Method Summary collapse

Methods included from Process::Scheduler

#execute_proc, included, #schedule, #schedule_history, #schedule_in, #scheduled_action, #scheduler_actions_list, #scheduler_clear_pending_list, #scheduler_freeze, #scheduler_freeze?, #scheduler_unfreeze

Methods included from Process::Notify

#notify

Methods included from Process::Data

#app_name, #debug_data, #environment_string, #group_name, #group_name_pure, #self_status_data, #shell_string, #sub_object?

Methods included from Process::System

#clear_pid_file, #compare_identity, #daemonize, #execute, #execute_async, #execute_sync, #expand_path, #failsafe_load_pid, #failsafe_save_pid, #get_identity, #load_pid_from_file, #pid_file_ctime, #process_pid_running?, #process_really_running?, #save_pid_to_file, #send_signal, #wait_for_condition

Methods included from Process::Watchers

#add_watchers, #remove_watchers

Methods included from Process::Config

#[], #c, #control_pid?, #prepare_config, #skip_group_action?, #update_config

Methods included from Process::Commands

#restart_process, #start_process, #stop_process

Constructor Details

#initialize(pid, config = {}, logger_prefix = nil, parent = nil) ⇒ ChildProcess

Returns a new instance of ChildProcess.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/eye/child_process.rb', line 30

def initialize(pid, config = {}, logger_prefix = nil, parent = nil)
  raise 'Empty pid' unless pid

  @pid = pid
  @parent = parent
  @config = prepare_config(config)
  @name = "child-#{pid}"
  @full_name = [logger_prefix, @name].join(':')

  @watchers = {}

  debug { "start monitoring CHILD config: #{@config.inspect}" }

  start_checkers
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



28
29
30
# File 'lib/eye/child_process.rb', line 28

def config
  @config
end

#full_nameObject (readonly)

Returns the value of attribute full_name.



28
29
30
# File 'lib/eye/child_process.rb', line 28

def full_name
  @full_name
end

#nameObject (readonly)

Returns the value of attribute name.



28
29
30
# File 'lib/eye/child_process.rb', line 28

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



28
29
30
# File 'lib/eye/child_process.rb', line 28

def parent
  @parent
end

#pidObject (readonly)

Returns the value of attribute pid.



28
29
30
# File 'lib/eye/child_process.rb', line 28

def pid
  @pid
end

#watchersObject (readonly)

Returns the value of attribute watchers.



28
29
30
# File 'lib/eye/child_process.rb', line 28

def watchers
  @watchers
end

Instance Method Details

#deleteObject



83
84
# File 'lib/eye/child_process.rb', line 83

def delete
end

#destroyObject



86
87
88
89
# File 'lib/eye/child_process.rb', line 86

def destroy
  remove_watchers
  terminate
end

#logger_tagObject



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

def logger_tag
  full_name
end

#monitorObject



77
78
# File 'lib/eye/child_process.rb', line 77

def monitor
end

#prepare_command(command) ⇒ Object

override



99
100
101
# File 'lib/eye/child_process.rb', line 99

def prepare_command(command) # override
  super.gsub('{PARENT_PID}', @parent.pid.to_s)
end

#restartObject



69
70
71
72
73
74
75
# File 'lib/eye/child_process.rb', line 69

def restart
  if self[:restart_command]
    execute_restart_command
  else
    stop
  end
end

#send_command(command, *args) ⇒ Object



58
59
60
# File 'lib/eye/child_process.rb', line 58

def send_command(command, *args)
  schedule command, *args, Eye::Reason::User.new(command)
end

#signal(sig) ⇒ Object



91
92
93
# File 'lib/eye/child_process.rb', line 91

def signal(sig)
  send_signal(sig) if pid
end

#startObject



62
63
# File 'lib/eye/child_process.rb', line 62

def start
end

#stateObject



50
51
52
# File 'lib/eye/child_process.rb', line 50

def state
  :up
end

#status_data(opts = {}) ⇒ Object



95
96
97
# File 'lib/eye/child_process.rb', line 95

def status_data(opts = {})
  self_status_data(opts)
end

#stopObject



65
66
67
# File 'lib/eye/child_process.rb', line 65

def stop
  kill_process
end

#unmonitorObject



80
81
# File 'lib/eye/child_process.rb', line 80

def unmonitor
end

#up?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/eye/child_process.rb', line 54

def up?
  state == :up
end