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, QueueDefinition, QueueFactory, SelfPipe, UnknownEnvironmentError

Constant Summary collapse

VERSION =
"0.6.11"

Class Method Summary collapse

Methods included from Logger

included

Class Method Details

.acl_cache_pathObject

Return the acl cache path.



65
66
67
68
69
# File 'lib/smith.rb', line 65

def acl_cache_path
  @acl_cache_path = Pathname.new(Smith.config.agency.acl_cache_path).tap do |path|
    check_path(path, true)
  end
end

.acl_pathObject



56
57
58
# File 'lib/smith.rb', line 56

def acl_path
  path_to_pathnames(config.agency.acl_path)
end

.agent_pathsObject



47
48
49
# File 'lib/smith.rb', line 47

def agent_paths
  path_to_pathnames(config.agency.agent_path)
end

.cache_pathObject



60
61
62
# File 'lib/smith.rb', line 60

def cache_path
  Pathname.new(config.agency.cache_path).expand_path
end

.compile_aclsObject



71
72
73
74
# File 'lib/smith.rb', line 71

def compile_acls
  @compiler = ACLCompiler.new
  @compiler.compile
end

.configObject



35
36
37
# File 'lib/smith.rb', line 35

def config
  Config.get
end

.config_pathObject



39
40
41
# File 'lib/smith.rb', line 39

def config_path
  Smith.config.path
end

.connectionObject

Raises:

  • (RuntimeError)


26
27
28
29
# File 'lib/smith.rb', line 26

def connection
  raise RuntimeError, "You must run this in a Smith.start block" if @connection.nil?
  @connection
end

.environmentObject



31
32
33
# File 'lib/smith.rb', line 31

def environment
  ENV['SMITH_ENV'] || 'development'
end

.hostnameObject

Convenience method to get the hostname



52
53
54
# File 'lib/smith.rb', line 52

def hostname
  Socket.gethostname
end

.root_pathObject



43
44
45
# File 'lib/smith.rb', line 43

def root_path
  Pathname.new(__FILE__).dirname.parent.expand_path
end

.running?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/smith.rb', line 76

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



80
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 80

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

  EM.set_descriptor_table_size(Smith.config.eventmachine.file_descriptors)

  connection_settings = config.amqp.broker.merge(
    :on_tcp_connection_failure => method(:tcp_connection_failure_handler),
    :on_possible_authentication_failure => method(:authentication_failure_handler))

  AMQP.start(connection_settings) do |connection|
    @connection = connection

    connection.on_connection do
      logger.info { "Connected to: AMQP Broker: #{broker_identifier(connection)}" } unless opts[:quiet]
    end

    # FIXME This should go in the config.
    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 the broker is gracefully shutdown we get a 320. Log a nice message.
      if connection_close.reply_code == 320
        logger.warn { "AMQP Broker shutdown: #{broker_identifier(connection)}" }
      else
        logger.warn {  connection_close.reply_text }
      end
    end

    # This will be the last thing run by the reactor.
    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