Class: ScoutAgent::Assignment::Start
- Inherits:
-
ScoutAgent::Assignment
- Object
- ScoutAgent::Assignment
- ScoutAgent::Assignment::Start
- Defined in:
- lib/scout_agent/assignment/start.rb
Overview
Invoke with:
sudo scout_agent start
This command starts the Scout agent, if it is not already running.
The agent requires super user privileges to prepare it’s environment, but it will relenquish these privileges before it begins normal work.
The agent daemonizes itself as part of the startup process (unless configured not to) and thus will detach from your terminal. It will still be running happily in the background. You can check up on it with the status command, if you like.
Instance Attribute Summary
Attributes inherited from ScoutAgent::Assignment
#group, #other_args, #switches, #user
Instance Method Summary collapse
-
#execute ⇒ Object
Runs the start command.
Methods inherited from ScoutAgent::Assignment
choose_group, choose_user, #initialize, plan, #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
#execute ⇒ Object
Runs the start command.
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/scout_agent/assignment/start.rb', line 26 def execute # build the directory for PID file storage, if needed unless Plan.pid_dir.exist? unless Plan.build_pid_dir(group.gid) abort_with_missing_pid_dir end end # switch to the selected user and group unless switch_group_and_user abort_with_wrong_group_or_user end # test our ability to reach the server unless test_server_connection(:quiet) abort_with_cannot_connect end # make a final check to see if everything looks properly prepared unless Plan.valid? and Plan.pid_dir.exist? and Plan.pid_dir.readable? and Plan.pid_dir.writable? abort_with_missing_resources end # make sure we are the only process running and daemonize, if configured running_mode = Plan.run_as_daemon? ? " as a daemon" : "" puts "Starting #{ScoutAgent.proper_agent_name}#{running_mode}..." card = IDCard.new(:lifeline) unless card. { 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 # prepare the log log = ScoutAgent.prepare_wire_tap(:lifeline) log.info("Loading monitors.") # load configured agents agents = %w[master] agents << "communication" if Plan.enable_xmpp? # start each agent through a Lifeline monitor lifelines = agents.map { |agent| Lifeline.new(agent, log) } %w[TERM INT].each do |signal| trap(signal) do lifelines.each { |line| line.terminate } end end lifelines.each do |line| line.launch_and_monitor end # wait for all monitors to finish lifelines.each do |line| line.join end # wait for all children to obey our stop command Process.waitall end |