Class: ScoutAgent::Lifeline
- Inherits:
-
Object
- Object
- ScoutAgent::Lifeline
- Includes:
- Tracked
- Defined in:
- lib/scout_agent/lifeline.rb
Constant Summary collapse
- NO_CONTACT_TIMEOUT =
3
- CHECK_IN_FREQUENCY =
gives us three check ins before a cutoff
0.99
- TERM_TO_KILL_PAUSE =
1
- RELAUNCH_FREQUENCIES =
[0, 1, 1, 2, 3, 5, 8, 13]
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
Instance Method Summary collapse
-
#initialize(agent, log = WireTap.new(nil)) ⇒ Lifeline
constructor
Interface ###.
- #join ⇒ Object
- #launch_and_monitor ⇒ Object
- #terminate ⇒ Object
Methods included from Tracked
#clear_status, #force_status_database_reload, #status_database, #status_log
Constructor Details
#initialize(agent, log = WireTap.new(nil)) ⇒ Lifeline
Interface ###
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/scout_agent/lifeline.rb', line 15 def initialize(agent, log = WireTap.new(nil)) @agent = agent @log = log @parent_pid = Process.pid @child_pid = nil @reader = nil @writer = nil @launch_and_monitor_thread = nil @check_in_with_parent_thread = nil @code = nil @last_launch = nil @relaunch_index = 0 at_my_exit do clear_status end end |
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
35 36 37 |
# File 'lib/scout_agent/lifeline.rb', line 35 def log @log end |
Instance Method Details
#join ⇒ Object
64 65 66 67 68 |
# File 'lib/scout_agent/lifeline.rb', line 64 def join if Process.pid == @parent_pid and @launch_and_monitor_thread @launch_and_monitor_thread.join end end |
#launch_and_monitor ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/scout_agent/lifeline.rb', line 37 def launch_and_monitor @launch_and_monitor_thread = Thread.new do Thread.current.abort_on_exception = true loop do wait_for_launch prepare_pipe launch_child close_writer monitor_child restart_child end end end |
#terminate ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/scout_agent/lifeline.rb', line 51 def terminate if Process.pid == @parent_pid # stop monitoring log.info("Stopping the monitoring for '#{@agent}'.") @launch_and_monitor_thread.exit if @launch_and_monitor_thread # ask child process to exit log.info("Asking '#{@agent}' to stop.") IDCard.new(@agent).signal("TERM") end rescue Errno::ESRCH # no such process # if already exited, so we are fine end |