Class: ScoutAgent::Assignment::Start

Inherits:
ScoutAgent::Assignment show all
Defined in:
lib/scout_agent/assignment/start.rb

Instance Attribute Summary

Attributes inherited from ScoutAgent::Assignment

#group, #other_args, #switches, #user

Instance Method Summary collapse

Methods inherited from ScoutAgent::Assignment

#initialize, #prepare_and_execute

Methods included from Tracked

#clear_status, #force_status_database_reload, #status, #status_database, #status_log

Constructor Details

This class inherits a constructor from ScoutAgent::Assignment

Instance Method Details

#executeObject



10
11
12
13
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/scout_agent/assignment/start.rb', line 10

def execute
  unless Plan.pid_dir.exist?
    unless Plan.build_pid_dir(group.gid)
      abort_with_missing_pid_dir
    end
  end
  
  unless switch_group_and_user
    abort_with_wrong_group_or_user
  end
  
  unless test_server_connection(:quiet)
    abort_with_cannot_connect
  end
  
  unless Plan.valid?            and
         Plan.pid_dir.exist?    and
         Plan.pid_dir.readable? and
         Plan.pid_dir.writable?
    abort_with_missing_resources
  end
  
  running_mode = Plan.run_as_daemon? ? " as a daemon" : ""
  puts "Starting #{ScoutAgent.proper_agent_name}#{running_mode}..."
  card = IDCard.new(:lifeline)
  unless card.authorize { not Plan.run_as_daemon? or daemonize }
    other_process = card.pid
    if other_process and other_process != Process.pid
      abort_with_other_process_running(other_process)
    else
      abort_with_failure_to_daemonize
    end
  end
  
  log = ScoutAgent.prepare_wire_tap(:lifeline)
  log.info("Loading monitors.")
  
  lifelines = %w[master communication].map { |agent|
    Lifeline.new(agent, log)
  }
  %w[TERM INT].each do |signal|
    trap(signal) do
      Thread.new do
        lifelines.each { |line| line.terminate }
        Process.waitall
      end
    end
  end
  lifelines.each { |line| line.launch_and_monitor }
  
  lifelines.each { |line| line.join }
end