reel-eye 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +32 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +170 -0
- data/Rakefile +20 -0
- data/bin/eye +322 -0
- data/bin/loader_eye +58 -0
- data/examples/notify.eye +18 -0
- data/examples/process_thin.rb +29 -0
- data/examples/processes/em.rb +57 -0
- data/examples/processes/forking.rb +20 -0
- data/examples/processes/sample.rb +144 -0
- data/examples/processes/thin.ru +12 -0
- data/examples/puma.eye +34 -0
- data/examples/rbenv.eye +11 -0
- data/examples/sidekiq.eye +23 -0
- data/examples/test.eye +81 -0
- data/examples/thin-farm.eye +29 -0
- data/examples/unicorn.eye +31 -0
- data/eye.gemspec +42 -0
- data/lib/eye.rb +28 -0
- data/lib/eye/application.rb +74 -0
- data/lib/eye/checker.rb +138 -0
- data/lib/eye/checker/cpu.rb +27 -0
- data/lib/eye/checker/file_ctime.rb +25 -0
- data/lib/eye/checker/file_size.rb +34 -0
- data/lib/eye/checker/http.rb +98 -0
- data/lib/eye/checker/memory.rb +27 -0
- data/lib/eye/checker/socket.rb +152 -0
- data/lib/eye/child_process.rb +101 -0
- data/lib/eye/client.rb +32 -0
- data/lib/eye/config.rb +88 -0
- data/lib/eye/control.rb +2 -0
- data/lib/eye/controller.rb +53 -0
- data/lib/eye/controller/commands.rb +73 -0
- data/lib/eye/controller/helpers.rb +61 -0
- data/lib/eye/controller/load.rb +214 -0
- data/lib/eye/controller/options.rb +48 -0
- data/lib/eye/controller/send_command.rb +115 -0
- data/lib/eye/controller/show_history.rb +62 -0
- data/lib/eye/controller/status.rb +131 -0
- data/lib/eye/dsl.rb +48 -0
- data/lib/eye/dsl/application_opts.rb +33 -0
- data/lib/eye/dsl/chain.rb +12 -0
- data/lib/eye/dsl/child_process_opts.rb +8 -0
- data/lib/eye/dsl/config_opts.rb +48 -0
- data/lib/eye/dsl/group_opts.rb +27 -0
- data/lib/eye/dsl/helpers.rb +12 -0
- data/lib/eye/dsl/main.rb +40 -0
- data/lib/eye/dsl/opts.rb +140 -0
- data/lib/eye/dsl/process_opts.rb +21 -0
- data/lib/eye/dsl/pure_opts.rb +110 -0
- data/lib/eye/dsl/validation.rb +59 -0
- data/lib/eye/group.rb +134 -0
- data/lib/eye/group/chain.rb +81 -0
- data/lib/eye/http.rb +31 -0
- data/lib/eye/http/router.rb +25 -0
- data/lib/eye/loader.rb +23 -0
- data/lib/eye/logger.rb +80 -0
- data/lib/eye/notify.rb +86 -0
- data/lib/eye/notify/jabber.rb +30 -0
- data/lib/eye/notify/mail.rb +44 -0
- data/lib/eye/process.rb +86 -0
- data/lib/eye/process/child.rb +58 -0
- data/lib/eye/process/commands.rb +256 -0
- data/lib/eye/process/config.rb +70 -0
- data/lib/eye/process/controller.rb +76 -0
- data/lib/eye/process/data.rb +47 -0
- data/lib/eye/process/monitor.rb +95 -0
- data/lib/eye/process/notify.rb +32 -0
- data/lib/eye/process/scheduler.rb +78 -0
- data/lib/eye/process/states.rb +86 -0
- data/lib/eye/process/states_history.rb +66 -0
- data/lib/eye/process/system.rb +97 -0
- data/lib/eye/process/trigger.rb +54 -0
- data/lib/eye/process/validate.rb +23 -0
- data/lib/eye/process/watchers.rb +69 -0
- data/lib/eye/reason.rb +20 -0
- data/lib/eye/server.rb +52 -0
- data/lib/eye/settings.rb +46 -0
- data/lib/eye/system.rb +154 -0
- data/lib/eye/system_resources.rb +86 -0
- data/lib/eye/trigger.rb +53 -0
- data/lib/eye/trigger/flapping.rb +28 -0
- data/lib/eye/utils.rb +14 -0
- data/lib/eye/utils/alive_array.rb +31 -0
- data/lib/eye/utils/celluloid_chain.rb +70 -0
- data/lib/eye/utils/leak_19.rb +7 -0
- data/lib/eye/utils/tail.rb +20 -0
- metadata +390 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
module Eye::Controller::ShowHistory
|
2
|
+
|
3
|
+
def history_string(*obj_strs)
|
4
|
+
data = history_data(*obj_strs)
|
5
|
+
|
6
|
+
res = []
|
7
|
+
data.each do |name, data|
|
8
|
+
res << detail_process_info(name, data)
|
9
|
+
end
|
10
|
+
|
11
|
+
res * "\n"
|
12
|
+
end
|
13
|
+
|
14
|
+
def history_data(*obj_strs)
|
15
|
+
res = {}
|
16
|
+
get_processes_for_history(*obj_strs).each do |process|
|
17
|
+
res[process.full_name] = process.schedule_history.reject{|c| c[:state] == :check_crash }
|
18
|
+
end
|
19
|
+
res
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def get_processes_for_history(*obj_strs)
|
25
|
+
res = []
|
26
|
+
matched_objects(*obj_strs) do |obj|
|
27
|
+
if (obj.is_a?(Eye::Process) || obj.is_a?(Eye::ChildProcess))
|
28
|
+
res << obj
|
29
|
+
else
|
30
|
+
res += obj.processes.to_a
|
31
|
+
end
|
32
|
+
end
|
33
|
+
Eye::Utils::AliveArray.new(res)
|
34
|
+
end
|
35
|
+
|
36
|
+
def detail_process_info(name, history)
|
37
|
+
return if history.empty?
|
38
|
+
|
39
|
+
res = "\033[1m#{name}\033[0m:\n"
|
40
|
+
history = history.reverse
|
41
|
+
|
42
|
+
history.chunk{|h| [h[:state], h[:reason].to_s] }.each do |_, hist|
|
43
|
+
if hist.size >= 3
|
44
|
+
res << detail_process_info_string(hist[0])
|
45
|
+
res << detail_process_info_string(:state => "... #{hist.size - 2} times", :reason => '...', :at => hist[-1][:at])
|
46
|
+
res << detail_process_info_string(hist[-1])
|
47
|
+
else
|
48
|
+
hist.each do |h|
|
49
|
+
res << detail_process_info_string(h)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
res
|
55
|
+
end
|
56
|
+
|
57
|
+
def detail_process_info_string(h)
|
58
|
+
state = h[:state].to_s.ljust(14)
|
59
|
+
"#{Time.at(h[:at]).to_s(:db)} - #{state} (#{h[:reason]})\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module Eye::Controller::Status
|
2
|
+
|
3
|
+
def info_objects(mask = nil)
|
4
|
+
res = []
|
5
|
+
return @applications unless mask
|
6
|
+
matched_objects(mask){|obj| res << obj }
|
7
|
+
res
|
8
|
+
end
|
9
|
+
|
10
|
+
def info_data(mask = nil)
|
11
|
+
{:subtree => info_objects(mask).map{|a| a.status_data } }
|
12
|
+
end
|
13
|
+
|
14
|
+
def info_data_debug(mask = nil)
|
15
|
+
{:subtree => info_objects(mask).map{|a| a.status_data(true) } }
|
16
|
+
end
|
17
|
+
|
18
|
+
def info_string(mask = nil)
|
19
|
+
make_str(info_data(mask)).to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
def info_string_short
|
23
|
+
make_str({:subtree => @applications.map{|a| a.status_data_short } }).to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def info_string_debug(show_config = false, show_processes = false)
|
27
|
+
actors = Celluloid::Actor.all.map{|actor| actor.instance_variable_get(:@klass) }.group_by{|a| a}.map{|k,v| [k, v.size]}.sort_by{|a|a[1]}.reverse
|
28
|
+
|
29
|
+
str = <<-S
|
30
|
+
About: #{Eye::ABOUT}
|
31
|
+
Info: #{resources_str(Eye::SystemResources.resources($$), false)}
|
32
|
+
Ruby: #{RUBY_DESCRIPTION}
|
33
|
+
Logger: #{Eye::Logger.dev}
|
34
|
+
Socket: #{Eye::Settings::socket_path}
|
35
|
+
Pid: #{Eye::Settings::pid_path}
|
36
|
+
Actors: #{actors.inspect}
|
37
|
+
|
38
|
+
S
|
39
|
+
|
40
|
+
str += make_str(info_data_debug) + "\n" if show_processes.present?
|
41
|
+
|
42
|
+
if show_config.present?
|
43
|
+
str += "\nCurrent config: \n"
|
44
|
+
str += YAML.dump(current_config.to_h)
|
45
|
+
end
|
46
|
+
|
47
|
+
GC.start
|
48
|
+
str
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def make_str(data, level = -1)
|
54
|
+
return nil if data.blank?
|
55
|
+
|
56
|
+
if data.is_a?(Array)
|
57
|
+
data.map{|el| make_str(el, level) }.compact * "\n"
|
58
|
+
else
|
59
|
+
str = nil
|
60
|
+
|
61
|
+
if data[:name]
|
62
|
+
return make_str(data[:subtree], level) if data[:name] == '__default__'
|
63
|
+
|
64
|
+
off = level * 2
|
65
|
+
off_str = ' ' * off
|
66
|
+
name = (data[:type] == :application && data[:state].blank?) ? "\033[1m#{data[:name]}\033[0m" : data[:name].to_s
|
67
|
+
off_len = (data[:type] == :application && !data[:state].blank?) ? 20 : 35
|
68
|
+
str = off_str + (name + ' ').ljust(off_len - off, data[:state] ? '.' : ' ')
|
69
|
+
|
70
|
+
if data[:debug]
|
71
|
+
str += ' | ' + debug_str(data[:debug])
|
72
|
+
|
73
|
+
# for group show chain data
|
74
|
+
if data[:debug][:chain]
|
75
|
+
str += " (chain: #{data[:debug][:chain].map(&:to_i)})"
|
76
|
+
end
|
77
|
+
elsif data[:state]
|
78
|
+
str += ' ' + data[:state].to_s
|
79
|
+
str += ' (' + resources_str(data[:resources]) + ')' if data[:resources].present? && data[:state].to_sym == :up
|
80
|
+
str += " (#{data[:state_reason]} at #{data[:state_changed_at].to_s(:short)})" if data[:state_reason] && data[:state] == 'unmonitored'
|
81
|
+
elsif data[:current_command]
|
82
|
+
chain_progress = if data[:chain_progress]
|
83
|
+
" #{data[:chain_progress][0]} of #{data[:chain_progress][1]}" rescue ''
|
84
|
+
end
|
85
|
+
str += " \e[1;33m[#{data[:current_command]}#{chain_progress}]\033[0m"
|
86
|
+
str += " (#{data[:chain_commands] * ', '})" if data[:chain_commands]
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
if data[:subtree].nil?
|
92
|
+
str
|
93
|
+
elsif data[:subtree].blank? && data[:type] != :application
|
94
|
+
nil
|
95
|
+
else
|
96
|
+
[str, make_str(data[:subtree], level + 1)].compact * "\n"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def resources_str(r, mb = true)
|
102
|
+
return '' if r.blank?
|
103
|
+
|
104
|
+
res = "#{r[:start_time]}, #{r[:cpu]}%"
|
105
|
+
|
106
|
+
if r[:memory]
|
107
|
+
mem = mb ? "#{r[:memory] / 1024}Mb" : "#{r[:memory]}Kb"
|
108
|
+
res += ", #{mem}"
|
109
|
+
end
|
110
|
+
|
111
|
+
res += ", <#{r[:pid]}>"
|
112
|
+
|
113
|
+
res
|
114
|
+
end
|
115
|
+
|
116
|
+
def debug_str(debug)
|
117
|
+
return '' unless debug
|
118
|
+
|
119
|
+
q = 'q(' + (debug[:queue] || []) * ',' + ')'
|
120
|
+
w = 'w(' + (debug[:watchers] || []) * ',' + ')'
|
121
|
+
|
122
|
+
[w, q] * '; '
|
123
|
+
end
|
124
|
+
|
125
|
+
def status_applications(app = nil)
|
126
|
+
apps = app.present? ? @applications.select{|a| a.name == app} : nil
|
127
|
+
apps = @applications unless apps
|
128
|
+
apps
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
data/lib/eye/dsl.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative 'dsl/helpers'
|
2
|
+
|
3
|
+
Eye::BINDING = binding
|
4
|
+
|
5
|
+
class Eye::Dsl
|
6
|
+
|
7
|
+
autoload :Main, 'eye/dsl/main'
|
8
|
+
autoload :ApplicationOpts, 'eye/dsl/application_opts'
|
9
|
+
autoload :GroupOpts, 'eye/dsl/group_opts'
|
10
|
+
autoload :ProcessOpts, 'eye/dsl/process_opts'
|
11
|
+
autoload :ChildProcessOpts, 'eye/dsl/child_process_opts'
|
12
|
+
autoload :Opts, 'eye/dsl/opts'
|
13
|
+
autoload :PureOpts, 'eye/dsl/pure_opts'
|
14
|
+
autoload :Chain, 'eye/dsl/chain'
|
15
|
+
autoload :ConfigOpts, 'eye/dsl/config_opts'
|
16
|
+
autoload :Validation, 'eye/dsl/validation'
|
17
|
+
|
18
|
+
class Error < Exception; end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
attr_accessor :verbose
|
22
|
+
|
23
|
+
def debug(msg = "")
|
24
|
+
puts msg if verbose
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse(content = nil, filename = nil)
|
28
|
+
Eye.parsed_config = Eye::Config.new
|
29
|
+
Eye.parsed_filename = filename
|
30
|
+
|
31
|
+
content = File.read(filename) if content.blank?
|
32
|
+
|
33
|
+
silence_warnings do
|
34
|
+
Kernel.eval(content, Eye::BINDING, filename.to_s)
|
35
|
+
end
|
36
|
+
|
37
|
+
Eye.parsed_config.validate!
|
38
|
+
Eye.parsed_config
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_apps(*args)
|
42
|
+
parse(*args).applications
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# extend here global module
|
48
|
+
Eye.send(:extend, Eye::Dsl::Main)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Eye::Dsl::ApplicationOpts < Eye::Dsl::Opts
|
2
|
+
|
3
|
+
include Eye::Dsl::Chain
|
4
|
+
|
5
|
+
def disallow_options
|
6
|
+
[:pid_file, :start_command]
|
7
|
+
end
|
8
|
+
|
9
|
+
def group(name, &block)
|
10
|
+
Eye::Dsl.debug "=> group #{name}"
|
11
|
+
|
12
|
+
opts = Eye::Dsl::GroupOpts.new(name, self)
|
13
|
+
opts.instance_eval(&block)
|
14
|
+
if cfg = opts.config
|
15
|
+
@config[:groups] ||= {}
|
16
|
+
|
17
|
+
processes = cfg.delete(:processes) || {}
|
18
|
+
@config[:groups][name.to_s] ||= {}
|
19
|
+
@config[:groups][name.to_s].merge!(cfg)
|
20
|
+
@config[:groups][name.to_s][:processes] ||= {}
|
21
|
+
@config[:groups][name.to_s][:processes].merge!(processes)
|
22
|
+
end
|
23
|
+
|
24
|
+
Eye::Dsl.debug "<= group #{name}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def process(name, &block)
|
28
|
+
group("__default__"){ process(name.to_s, &block) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def xgroup(name, &block); end
|
32
|
+
def xprocess(name, &block); end
|
33
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Eye::Dsl::ConfigOpts < Eye::Dsl::PureOpts
|
2
|
+
|
3
|
+
create_options_methods([:logger], String)
|
4
|
+
create_options_methods([:logger_level], Fixnum)
|
5
|
+
create_options_methods([:http], Hash)
|
6
|
+
|
7
|
+
def set_logger(logger)
|
8
|
+
logger.blank? ? super('') : super
|
9
|
+
end
|
10
|
+
|
11
|
+
# ==== contact options ==============================
|
12
|
+
|
13
|
+
Eye::Notify::TYPES.keys.each do |not_system|
|
14
|
+
create_options_methods([not_system], Hash)
|
15
|
+
|
16
|
+
define_method("set_#{not_system}") do |value|
|
17
|
+
value = value.merge(:type => not_system)
|
18
|
+
super(value)
|
19
|
+
Eye::Notify.validate!(value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def contact(contact_name, contact_type, contact, contact_opts = {})
|
24
|
+
raise Eye::Dsl::Error, "unknown contact_type #{contact_type}" unless Eye::Notify::TYPES[contact_type]
|
25
|
+
raise Eye::Dsl::Error, "contact should be a String" unless contact.is_a?(String)
|
26
|
+
|
27
|
+
notify_hash = @config[contact_type] || (@parent && @parent.config[contact_type]) || Eye::parsed_config.settings[contact_type] || {}
|
28
|
+
validate_hash = notify_hash.merge(contact_opts).merge(:type => contact_type)
|
29
|
+
|
30
|
+
Eye::Notify.validate!(validate_hash)
|
31
|
+
|
32
|
+
@config[:contacts] ||= {}
|
33
|
+
@config[:contacts][contact_name.to_s] = {name: contact_name.to_s, type: contact_type,
|
34
|
+
contact: contact, opts: contact_opts}
|
35
|
+
end
|
36
|
+
|
37
|
+
def contact_group(contact_group_name, &block)
|
38
|
+
c = Eye::Dsl::ConfigOpts.new nil, self, false
|
39
|
+
c.instance_eval(&block)
|
40
|
+
cfg = c.config
|
41
|
+
@config[:contacts] ||= {}
|
42
|
+
if cfg[:contacts].present?
|
43
|
+
@config[:contacts][contact_group_name.to_s] = cfg[:contacts].values
|
44
|
+
@config[:contacts].merge!(cfg[:contacts])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Eye::Dsl::GroupOpts < Eye::Dsl::Opts
|
2
|
+
|
3
|
+
include Eye::Dsl::Chain
|
4
|
+
|
5
|
+
def disallow_options
|
6
|
+
[:pid_file, :start_command]
|
7
|
+
end
|
8
|
+
|
9
|
+
def process(name, &block)
|
10
|
+
Eye::Dsl.debug "=> process #{name}"
|
11
|
+
|
12
|
+
opts = Eye::Dsl::ProcessOpts.new(name, self)
|
13
|
+
opts.instance_eval(&block)
|
14
|
+
@config[:processes] ||= {}
|
15
|
+
@config[:processes][name.to_s] = opts.config if opts.config
|
16
|
+
|
17
|
+
Eye::Dsl.debug "<= process #{name}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def xprocess(name, &block); end
|
21
|
+
|
22
|
+
def application
|
23
|
+
parent
|
24
|
+
end
|
25
|
+
alias :app :application
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
# Dsl Helpers
|
3
|
+
|
4
|
+
# current eye parsed config path
|
5
|
+
def current_config_path
|
6
|
+
Eye.parsed_filename && File.symlink?(Eye.parsed_filename) ? File.readlink(Eye.parsed_filename) : Eye.parsed_filename
|
7
|
+
end
|
8
|
+
|
9
|
+
# host name
|
10
|
+
def hostname
|
11
|
+
Eye::System.host
|
12
|
+
end
|
data/lib/eye/dsl/main.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Eye::Dsl::Main
|
2
|
+
attr_accessor :parsed_config, :parsed_filename
|
3
|
+
|
4
|
+
def application(name, &block)
|
5
|
+
Eye::Dsl.debug "=> app: #{name}"
|
6
|
+
opts = Eye::Dsl::ApplicationOpts.new(name)
|
7
|
+
opts.instance_eval(&block)
|
8
|
+
|
9
|
+
@parsed_config.applications[name.to_s] = opts.config if opts.config
|
10
|
+
|
11
|
+
Eye::Dsl.debug "<= app: #{name}"
|
12
|
+
end
|
13
|
+
|
14
|
+
alias :app :application
|
15
|
+
|
16
|
+
def load(glob = '')
|
17
|
+
return if glob.blank?
|
18
|
+
|
19
|
+
Eye::Dsl::Opts.with_parsed_file(glob) do |mask|
|
20
|
+
Dir[mask].each do |path|
|
21
|
+
Eye::Dsl.debug "=> load #{path}"
|
22
|
+
Eye.parsed_filename = path
|
23
|
+
res = Kernel.load(path)
|
24
|
+
Eye.info "load: subload #{path} (#{res})"
|
25
|
+
Eye::Dsl.debug "<= load #{path}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def config(&block)
|
31
|
+
Eye::Dsl.debug "=> config"
|
32
|
+
|
33
|
+
opts = Eye::Dsl::ConfigOpts.new
|
34
|
+
opts.instance_eval(&block)
|
35
|
+
@parsed_config.settings.merge!(opts.config)
|
36
|
+
|
37
|
+
Eye::Dsl.debug "<= config"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/lib/eye/dsl/opts.rb
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
class Eye::Dsl::Opts < Eye::Dsl::PureOpts
|
2
|
+
|
3
|
+
STR_OPTIONS = [ :pid_file, :working_dir, :stdout, :stderr, :stdall, :start_command,
|
4
|
+
:stop_command, :restart_command ]
|
5
|
+
create_options_methods(STR_OPTIONS, String)
|
6
|
+
|
7
|
+
BOOL_OPTIONS = [ :daemonize, :keep_alive, :control_pid, :auto_start, :stop_on_delete]
|
8
|
+
create_options_methods(BOOL_OPTIONS, [TrueClass, FalseClass])
|
9
|
+
|
10
|
+
INTERVAL_OPTIONS = [ :check_alive_period, :start_timeout, :restart_timeout, :stop_timeout, :start_grace,
|
11
|
+
:restart_grace, :stop_grace, :childs_update_period ]
|
12
|
+
create_options_methods(INTERVAL_OPTIONS, [Fixnum, Float])
|
13
|
+
|
14
|
+
OTHER_OPTIONS = [ :environment, :stop_signals ]
|
15
|
+
create_options_methods(OTHER_OPTIONS)
|
16
|
+
|
17
|
+
|
18
|
+
def initialize(name = nil, parent = nil)
|
19
|
+
super(name, parent)
|
20
|
+
|
21
|
+
# ensure delete subobjects which can appears from parent config
|
22
|
+
@config.delete :groups
|
23
|
+
@config.delete :processes
|
24
|
+
|
25
|
+
@config[:application] = parent.name if parent.is_a?(Eye::Dsl::ApplicationOpts)
|
26
|
+
@config[:group] = parent.name if parent.is_a?(Eye::Dsl::GroupOpts)
|
27
|
+
|
28
|
+
# hack for full name
|
29
|
+
@full_name = parent.full_name if @name == '__default__'
|
30
|
+
end
|
31
|
+
|
32
|
+
def checks(type, opts = {})
|
33
|
+
type = type.to_sym
|
34
|
+
raise Eye::Dsl::Error, "unknown checker type #{type}" unless Eye::Checker::TYPES[type]
|
35
|
+
|
36
|
+
opts.merge!(:type => type)
|
37
|
+
Eye::Checker.validate!(opts)
|
38
|
+
|
39
|
+
@config[:checks] ||= {}
|
40
|
+
@config[:checks][type] = opts
|
41
|
+
end
|
42
|
+
|
43
|
+
def triggers(type, opts = {})
|
44
|
+
type = type.to_sym
|
45
|
+
raise Eye::Dsl::Error, "unknown trigger type #{type}" unless Eye::Trigger::TYPES[type]
|
46
|
+
|
47
|
+
opts.merge!(:type => type)
|
48
|
+
Eye::Trigger.validate!(opts)
|
49
|
+
|
50
|
+
@config[:triggers] ||= {}
|
51
|
+
@config[:triggers][type] = opts
|
52
|
+
end
|
53
|
+
|
54
|
+
# clear checks from parent
|
55
|
+
def nochecks(type)
|
56
|
+
type = type.to_sym
|
57
|
+
raise Eye::Dsl::Error, "unknown checker type #{type}" unless Eye::Checker::TYPES[type]
|
58
|
+
@config[:checks].try :delete, type
|
59
|
+
end
|
60
|
+
|
61
|
+
# clear triggers from parent
|
62
|
+
def notriggers(type)
|
63
|
+
type = type.to_sym
|
64
|
+
raise Eye::Dsl::Error, "unknown trigger type #{type}" unless Eye::Trigger::TYPES[type]
|
65
|
+
@config[:triggers].try :delete, type
|
66
|
+
end
|
67
|
+
|
68
|
+
def notify(contact, level = :warn)
|
69
|
+
unless Eye::Process::Notify::LEVELS[level]
|
70
|
+
raise Eye::Dsl::Error, "level should be in #{Eye::Process::Notify::LEVELS.keys}"
|
71
|
+
end
|
72
|
+
|
73
|
+
@config[:notify] ||= {}
|
74
|
+
@config[:notify][contact.to_s] = level
|
75
|
+
end
|
76
|
+
|
77
|
+
def nonotify(contact)
|
78
|
+
@config[:notify] ||= {}
|
79
|
+
@config[:notify].delete(contact.to_s)
|
80
|
+
end
|
81
|
+
|
82
|
+
def set_environment(value)
|
83
|
+
raise Eye::Dsl::Error, "environment should be a hash, but not #{value.inspect}" unless value.is_a?(Hash)
|
84
|
+
@config[:environment] ||= {}
|
85
|
+
@config[:environment].merge!(value)
|
86
|
+
end
|
87
|
+
|
88
|
+
alias :env :environment
|
89
|
+
|
90
|
+
def set_stdall(value)
|
91
|
+
super
|
92
|
+
|
93
|
+
set_stdout value
|
94
|
+
set_stderr value
|
95
|
+
end
|
96
|
+
|
97
|
+
def scoped(&block)
|
98
|
+
h = self.class.new(self.name, self)
|
99
|
+
h.instance_eval(&block)
|
100
|
+
groups = h.config.delete :groups
|
101
|
+
processes = h.config.delete :processes
|
102
|
+
|
103
|
+
if groups.present?
|
104
|
+
config[:groups] ||= {}
|
105
|
+
config[:groups].merge!(groups)
|
106
|
+
end
|
107
|
+
|
108
|
+
if processes.present?
|
109
|
+
config[:processes] ||= {}
|
110
|
+
config[:processes].merge!(processes)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# execute part of config on particular server
|
115
|
+
# array of strings
|
116
|
+
# regexp
|
117
|
+
# string
|
118
|
+
def with_server(glob = nil, &block)
|
119
|
+
on_server = true
|
120
|
+
|
121
|
+
if glob.present?
|
122
|
+
host = Eye::System.host
|
123
|
+
|
124
|
+
if glob.is_a?(Array)
|
125
|
+
on_server = !!glob.any?{|elem| elem == host}
|
126
|
+
elsif glob.is_a?(Regexp)
|
127
|
+
on_server = !!host.match(glob)
|
128
|
+
elsif glob.is_a?(String) || glob.is_a?(Symbol)
|
129
|
+
on_server = (host == glob.to_s)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
scoped do
|
134
|
+
with_condition(on_server, &block)
|
135
|
+
end
|
136
|
+
|
137
|
+
on_server
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|