Class: Smith::AgentBootstrap
- Inherits:
-
Object
- Object
- Smith::AgentBootstrap
- Defined in:
- lib/smith/bootstrap.rb
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
Instance Method Summary collapse
-
#initialize(name, uuid) ⇒ AgentBootstrap
constructor
A new instance of AgentBootstrap.
- #load_agent ⇒ Object
-
#shutdown ⇒ Object
Cleanly shutdown of the agent.
- #signal_handlers ⇒ Object
- #start! ⇒ Object
-
#terminate!(exception = nil) ⇒ Object
Exceptional shutdown of the agent.
Methods included from Utils
#agent_directories, check_and_create_directory, class_from_name, class_name_from_path, path_from_class, split_path
Methods included from Logger
Constructor Details
#initialize(name, uuid) ⇒ AgentBootstrap
Returns a new instance of AgentBootstrap.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/smith/bootstrap.rb', line 20 def initialize(name, uuid) Dir.chdir('/') # FIXME # This doesn't do what I think it should. If an exception is # thrown in setup_control_queue, for example, it just kills # the agent without it actually raising the exception. Thread.abort_on_exception = true EventMachine.error_handler { |e| terminate!(e) } @agent_name = name @agent_uuid = uuid end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
15 16 17 |
# File 'lib/smith/bootstrap.rb', line 15 def agent @agent end |
Instance Method Details
#load_agent ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/smith/bootstrap.rb', line 46 def load_agent path = agent_directories(@agent_name) logger.info { "Loading #{@agent_name}" } logger.debug { "Loading #{@agent_name} from: #{path}" } add_agent_load_path(path) load path begin @agent = class_from_name(@agent_name).new(@agent_uuid) rescue NameError => e # TODO: include the class name from the path. logger.fatal { "Cannot instantiate agent. File #{path} exists but doesn't contain the Class: #{@agent_name}." } terminate! false end end |
#shutdown ⇒ Object
Cleanly shutdown of the agent.
88 89 90 91 |
# File 'lib/smith/bootstrap.rb', line 88 def shutdown unlink_pid_file Smith.stop if Smith.running? end |
#signal_handlers ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/smith/bootstrap.rb', line 35 def signal_handlers logger.debug { "Installing default signal handlers" } %w{TERM INT QUIT}.each do |sig| @agent.install_signal_handler(sig) do |sig| logger.error { "Received signal #{sig}: #{agent.name}, UUID: #{agent.uuid}, PID: #{agent.pid}." } terminate! end end end |
#start! ⇒ Object
63 64 65 66 |
# File 'lib/smith/bootstrap.rb', line 63 def start! write_pid_file @agent.run end |
#terminate!(exception = nil) ⇒ Object
Exceptional shutdown of the agent. Note. Whenever this is called it almost certain that the reactor is not going to be running. So it must be restarted and then shutdown again See the note at the in main.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/smith/bootstrap.rb', line 72 def terminate!(exception=nil) handle_excecption(exception) if Smith.running? shutdown else Smith.start do shutdown end end end |