Module: Redmon

Extended by:
Redmon
Included in:
Redmon
Defined in:
lib/redmon.rb,
lib/redmon/app.rb,
lib/redmon/redis.rb,
lib/redmon/config.rb,
lib/redmon/worker.rb,
lib/redmon/helpers.rb,
lib/redmon/version.rb

Defined Under Namespace

Modules: Helpers, Redis Classes: App, Config, Worker

Constant Summary collapse

VERSION =
"0.0.10"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configObject



6
7
8
# File 'lib/redmon/config.rb', line 6

def self.config
  @config ||= Config.new
end

.configure {|config| ... } ⇒ Object

Yields:



2
3
4
# File 'lib/redmon/config.rb', line 2

def self.configure
  yield config
end

Instance Method Details

#log(msg) ⇒ Object



46
47
48
# File 'lib/redmon.rb', line 46

def log(msg)
  puts "[#{Time.now.strftime('%y-%m-%d %H:%M:%S')}] #{msg}"
end

#run(opts = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/redmon.rb', line 7

def run(opts={})
  config.apply opts
  start_em
rescue Exception => e
  unless e.is_a?(SystemExit)
    log "!!! Redmon has shit the bed, restarting... #{e.message}"
    e.backtrace.each { |line| log line }
    sleep(1)
    run(opts)
  end
end

#shutdown(code) ⇒ Object



42
43
44
# File 'lib/redmon.rb', line 42

def shutdown(code)
  EM.stop
end

#start_appObject



28
29
30
31
32
33
34
35
36
# File 'lib/redmon.rb', line 28

def start_app
  require 'thin'
  Thin::Server.start(*config.web_interface) do
    run Redmon::App.new
  end
  log "listening on http##{config.web_interface.join(':')}"
rescue Exception => e
  log "Can't start Redmon::App. port in use? Error: #{e}"
end

#start_emObject



19
20
21
22
23
24
25
26
# File 'lib/redmon.rb', line 19

def start_em
  EM.run do
    trap 'TERM', &method(:shutdown)
    trap 'INT',  &method(:shutdown)
    start_app    if config.app
    start_worker if config.worker
  end
end

#start_workerObject



38
39
40
# File 'lib/redmon.rb', line 38

def start_worker
  Worker.new.run!
end