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.13"
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.config ⇒ Object
6
7
8
|
# File 'lib/redmon/config.rb', line 6
def self.config
@config ||= Config.new
end
|
2
3
4
|
# File 'lib/redmon/config.rb', line 2
def self.configure
yield config
end
|
Instance Method Details
#log(msg) ⇒ Object
51
52
53
|
# File 'lib/redmon.rb', line 51
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
46
47
48
49
|
# File 'lib/redmon.rb', line 46
def shutdown(code)
log "Shutting down"
EM.stop
end
|
#start_app ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/redmon.rb', line 28
def start_app
require 'thin'
base_path = config.base_path
Thin::Server.start(*config.web_interface, signals: false) do
app = Redmon::App.new
map base_path do
run app
end
end
log "listening on http://#{config.web_interface.join(':')}#{base_path}"
rescue Exception => e
log "Can't start Redmon::App. port in use? Error: #{e}"
end
|
#start_em ⇒ Object
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_worker ⇒ Object
42
43
44
|
# File 'lib/redmon.rb', line 42
def start_worker
Worker.new.run!
end
|