Class: Smith::AgentBootstrap
- Inherits:
-
Object
- Object
- Smith::AgentBootstrap
- Includes:
- Logger
- Defined in:
- lib/smith/bootstrap.rb
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
Instance Method Summary collapse
- #agent_path(name) ⇒ Object
-
#initialize(name, uuid) ⇒ AgentBootstrap
constructor
A new instance of AgentBootstrap.
- #load_agent ⇒ Object
-
#shutdown ⇒ Object
Clean shutdown of the agent.
- #signal_handlers ⇒ Object
- #start! ⇒ Object
-
#terminate!(exception = nil) ⇒ Object
Exceptional shutdown of the agent.
Methods included from Logger
Constructor Details
#initialize(name, uuid) ⇒ AgentBootstrap
Returns a new instance of AgentBootstrap.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/smith/bootstrap.rb', line 19 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 @agent_name = name @agent_uuid = uuid @agent_filename = agent_path(name) 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
#agent_path(name) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/smith/bootstrap.rb', line 50 def agent_path(name) file_name = "#{name.snake_case}.rb" Smith.agent_paths.each do |path| p = Pathname.new(path).join(file_name) return p if p.exist? end return nil end |
#load_agent ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/smith/bootstrap.rb', line 42 def load_agent @agent_filename = agent_path(@agent_name) logger.debug { "Loading #{@agent_name} from: #{@agent_filename.dirname}" } add_agent_load_path load @agent_filename @agent = Kernel.const_get(@agent_name).new(@agent_uuid) end |
#shutdown ⇒ Object
Clean shutdown of the agent.
87 88 89 90 |
# File 'lib/smith/bootstrap.rb', line 87 def shutdown unlink_pid_file Smith.stop if Smith.running? end |
#signal_handlers ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/smith/bootstrap.rb', line 32 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 { "Agent received: signal #{sig}: #{agent.name} (#{agent.uuid})" } terminate! end end end |
#start! ⇒ Object
59 60 61 62 |
# File 'lib/smith/bootstrap.rb', line 59 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.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/smith/bootstrap.rb', line 68 def terminate!(exception=nil) logger.error { format_exception(exception) } if exception logger.error { "Terminating: #{@agent_uuid}." } if Smith.running? unlink_pid_file Smith.stop else logger.debug { "Reconnecting to AMQP Broker." } Smith.start do unlink_pid_file Smith.stop end end end |