Module: Smith
- Includes:
- Logger
- Defined in:
- lib/smith/commands/agency/restart.rb,
lib/smith.rb,
lib/smith/agent.rb,
lib/smith/cache.rb,
lib/smith/utils.rb,
lib/smith/config.rb,
lib/smith/daemon.rb,
lib/smith/logger.rb,
lib/smith/command.rb,
lib/smith/version.rb,
lib/smith/bootstrap.rb,
lib/smith/self_pipe.rb,
lib/smith/acl_parser.rb,
lib/smith/exceptions.rb,
lib/smith/agent_cache.rb,
lib/smith/amqp_errors.rb,
lib/smith/acl_compiler.rb,
lib/smith/agent_config.rb,
lib/smith/command_base.rb,
lib/smith/object_count.rb,
lib/smith/agent_process.rb,
lib/smith/messaging/util.rb,
lib/smith/commands/common.rb,
lib/smith/messaging/queue.rb,
lib/smith/agent_monitoring.rb,
lib/smith/messaging/sender.rb,
lib/smith/commands/template.rb,
lib/smith/messaging/factory.rb,
lib/smith/messaging/requeue.rb,
lib/smith/queue_definitions.rb,
lib/smith/application/agency.rb,
lib/smith/messaging/receiver.rb,
lib/smith/messaging/responder.rb,
lib/smith/commands/agency/kill.rb,
lib/smith/commands/agency/list.rb,
lib/smith/commands/agency/stop.rb,
lib/smith/commands/smithctl/rm.rb,
lib/smith/commands/agency/group.rb,
lib/smith/commands/agency/start.rb,
lib/smith/commands/smithctl/acl.rb,
lib/smith/commands/smithctl/pop.rb,
lib/smith/commands/smithctl/top.rb,
lib/smith/messaging/acl/default.rb,
lib/smith/commands/agency/agents.rb,
lib/smith/commands/agency/logger.rb,
lib/smith/commands/smithctl/dump.rb,
lib/smith/commands/smithctl/push.rb,
lib/smith/messaging/amqp_options.rb,
lib/smith/commands/agency/version.rb,
lib/smith/messaging/queue_factory.rb,
lib/smith/commands/agency/metadata.rb,
lib/smith/commands/smithctl/status.rb,
lib/smith/messaging/acl_type_cache.rb,
lib/smith/messaging/message_counter.rb,
lib/smith/commands/smithctl/commands.rb,
lib/smith/commands/smithctl/firehose.rb,
lib/smith/messaging/queue_definition.rb,
lib/smith/commands/smithctl/subscribe.rb,
lib/smith/commands/agency/object_count.rb
Overview
FIXME. This needs to be either fixed up or removed. It dumps the output into the log at the moment which isn’t the place for it. It should also be a smithctl command rather than an agency command.
Defined Under Namespace
Modules: ACL, AgentProcessObserver, Commands, LoggeMethods, Logger, Messaging, ObjectCount, QueueDefinitions, Utils
Classes: ACLCompiler, ACLParser, AclTypeCache, Agency, AgencyRunning, Agent, AgentBootstrap, AgentCache, AgentConfig, AgentMonitoring, AgentProcess, Cache, Command, CommandBase, Config, ConfigNotFoundError, Daemon, MissingConfigItemError, QueueDefinition, QueueFactory, SelfPipe, UnknownEnvironmentError
Constant Summary
collapse
- VERSION =
"0.8.2"
Class Method Summary
collapse
Methods included from Logger
included
Class Method Details
.acl_cache_directory ⇒ Object
Return the acl cache path.
66
67
68
69
70
|
# File 'lib/smith.rb', line 66
def acl_cache_directory
cache_directory.join('acl').tap do |path|
check_path(path, true)
end
end
|
.acl_directories ⇒ Object
57
58
59
|
# File 'lib/smith.rb', line 57
def acl_directories
config.agency.acl_directories
end
|
.agent_directories ⇒ Object
48
49
50
|
# File 'lib/smith.rb', line 48
def agent_directories
config.agency.agent_directories
end
|
.cache_directory ⇒ Object
.compile_acls ⇒ Object
72
73
74
75
|
# File 'lib/smith.rb', line 72
def compile_acls
@compiler = ACLCompiler.new
@compiler.compile
end
|
.config ⇒ Object
36
37
38
|
# File 'lib/smith.rb', line 36
def config
Config.get
end
|
.config_path ⇒ Object
40
41
42
|
# File 'lib/smith.rb', line 40
def config_path
Smith.config.path
end
|
.connection ⇒ Object
27
28
29
30
|
# File 'lib/smith.rb', line 27
def connection
raise RuntimeError, "You must run this in a Smith.start block" if @connection.nil?
@connection
end
|
.environment ⇒ Object
32
33
34
|
# File 'lib/smith.rb', line 32
def environment
ENV['SMITH_ENV'] || 'development'
end
|
.hostname ⇒ Object
Convenience method to get the hostname
53
54
55
|
# File 'lib/smith.rb', line 53
def hostname
Socket.gethostname
end
|
.root_path ⇒ Object
44
45
46
|
# File 'lib/smith.rb', line 44
def root_path
Pathname.new(__FILE__).dirname.parent.expand_path
end
|
.running? ⇒ Boolean
77
78
79
|
# File 'lib/smith.rb', line 77
def running?
EM.reactor_running?
end
|
.shutdown_hook(&block) ⇒ Object
133
134
135
|
# File 'lib/smith.rb', line 133
def shutdown_hook(&block)
EM.add_shutdown_hook(&block)
end
|
.start(opts = {}, &block) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/smith.rb', line 81
def start(opts={}, &block)
if EM.epoll? && Smith.config.eventmachine.epoll
logger.debug { "Using epoll for I/O event notification." }
EM.epoll
end
if EM.kqueue? && Smith.config.eventmachine.kqueue
logger.debug { "Using kqueue for I/O event notification." }
EM.kqueue
end
connection_settings = {
:on_tcp_connection_failure => method(:tcp_connection_failure_handler),
:on_possible_authentication_failure => method(:authentication_failure_handler)
}
AMQP.start(config.amqp.broker.uri.to_s, connection_settings) do |connection|
@connection = connection
connection.on_connection do
logger.info { "Connected to: AMQP Broker: #{broker_identifier(connection)}" } unless opts[:quiet]
end
reconnection_delay = 5
connection.on_tcp_connection_loss do |connection, settings|
logger.info { "Reconnecting to AMQP Broker: #{broker_identifier(connection)} in #{reconnection_delay}s" }
connection.reconnect(false, reconnection_delay)
end
connection.after_recovery do |connection|
logger.info { "Connection with AMQP Broker restored: #{broker_identifier(connection)}" } unless opts[:quiet]
end
connection.on_error do |connection, connection_close|
if connection_close.reply_code == 320
logger.warn { "AMQP Broker shutdown: #{broker_identifier(connection)}" }
else
logger.warn { connection_close.reply_text }
end
end
shutdown_hook { logger.debug { "Reactor Stopped" } }
block.call
end
end
|
.stop(immediately = false, &blk) ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/smith.rb', line 137
def stop(immediately=false, &blk)
shutdown_hook(&blk) if blk
if running?
if immediately
EM.next_tick do
@connection.close { EM.stop_event_loop }
end
else
EM.add_timer(1) do
@connection.close { EM.stop_event_loop }
end
end
else
logger.fatal { "Eventmachine is not running, exiting with prejudice" }
exit!
end
end
|