eye 0.6.1 → 0.6.2.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/bin/loader_eye +1 -1
- data/lib/eye.rb +1 -1
- data/lib/eye/cli.rb +8 -1
- data/lib/eye/cli/server.rb +3 -1
- data/lib/eye/controller.rb +0 -2
- data/lib/eye/controller/commands.rb +4 -2
- data/lib/eye/controller/load.rb +1 -1
- data/lib/eye/controller/send_command.rb +6 -0
- data/lib/eye/dsl/main.rb +7 -0
- data/lib/eye/dsl/opts.rb +32 -0
- data/lib/eye/group.rb +4 -0
- data/lib/eye/logger.rb +1 -1
- data/lib/eye/process.rb +3 -3
- data/lib/eye/process/commands.rb +23 -0
- data/lib/eye/process/controller.rb +6 -0
- data/lib/eye/process/system.rb +14 -1
- data/lib/eye/process/validate.rb +0 -10
- data/lib/eye/server.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjNkZTlhODlmNzc5YmZjNzhlZDVmYmVmZDQ0MGFjYjBhYzY0NDYzYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmNmM2ExMTcwMDMxOGI3NjEwNjAxYWFkNGZkY2MxNDIxNTNkYTI3Mw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjJlYzQwZWY4OTY2MzUzODAzYzUzZDg5ZDU4MTJmMTk5NTE1YWEzYmMzMDBl
|
10
|
+
OGUwYmU0MjI0NjFiMjU3N2NlYjQ1N2E5YjZkMmZmMjhkZDRlYjVhMDRjMDY4
|
11
|
+
ZDE3ZGE1NjVhNzBkMzY3NGEzZmM1NzNiMzhjMzEwMTZmNjk1YjQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWVhZmIwZTcxOWY3N2RhMmFhM2JlN2M2NjU3OGQ1NjdkYjQxMDRiZWViYTQy
|
14
|
+
YWFjOWU3MjdlMjZlZTRhOTczY2U2NWQ0ZmNlYjRjMWM4ZjgzZDg1NzM0YzNm
|
15
|
+
MTYxYjcyOTBjZTg5NGYzNjczYzU4YTAzNTZkMTM2MTBkYjhkMDY=
|
data/bin/loader_eye
CHANGED
data/lib/eye.rb
CHANGED
data/lib/eye/cli.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
gem 'thor'
|
2
4
|
require 'thor'
|
3
5
|
|
@@ -88,7 +90,7 @@ class Eye::Cli < Thor
|
|
88
90
|
# remove pid_file
|
89
91
|
File.delete(Eye::Local.pid_path) if File.exists?(Eye::Local.pid_path)
|
90
92
|
|
91
|
-
say "Quit
|
93
|
+
say "Quit ಠ╭╮ಠ", :yellow
|
92
94
|
end
|
93
95
|
|
94
96
|
[:start, :stop, :restart, :unmonitor, :monitor, :delete, :match].each do |_cmd|
|
@@ -158,6 +160,11 @@ class Eye::Cli < Thor
|
|
158
160
|
rescue Interrupt
|
159
161
|
end
|
160
162
|
|
163
|
+
desc "user_command CMD [MASK]", "execute user_command (dsl command)"
|
164
|
+
def user_command(cmd, *args)
|
165
|
+
send_command(:user_command, cmd, *args)
|
166
|
+
end
|
167
|
+
|
161
168
|
private
|
162
169
|
|
163
170
|
def error!(msg)
|
data/lib/eye/cli/server.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Eye::Cli::Server
|
2
4
|
private
|
3
5
|
|
@@ -64,7 +66,7 @@ private
|
|
64
66
|
configs.unshift(Eye::Local.eyeconfig) if File.exists?(Eye::Local.eyeconfig)
|
65
67
|
configs << Eye::Local.eyefile if Eye::Local.local_runner
|
66
68
|
|
67
|
-
say 'Eye started!', :green
|
69
|
+
say 'Eye started! ㋡', :green
|
68
70
|
|
69
71
|
if !configs.empty?
|
70
72
|
say_load_result cmd(:load, *configs)
|
data/lib/eye/controller.rb
CHANGED
@@ -17,11 +17,13 @@ module Eye::Controller::Commands
|
|
17
17
|
when :start, :stop, :restart, :unmonitor, :monitor, :break_chain
|
18
18
|
send_command(cmd, *args)
|
19
19
|
when :delete
|
20
|
-
exclusive{ send_command(cmd, *args) }
|
20
|
+
exclusive { send_command(cmd, *args) }
|
21
21
|
when :signal
|
22
22
|
signal(*args)
|
23
|
+
when :user_command
|
24
|
+
user_command(*args)
|
23
25
|
when :load
|
24
|
-
load(*args)
|
26
|
+
exclusive { load(*args) }
|
25
27
|
when :quit
|
26
28
|
quit
|
27
29
|
when :stop_all
|
data/lib/eye/controller/load.rb
CHANGED
data/lib/eye/dsl/main.rb
CHANGED
@@ -25,8 +25,10 @@ module Eye::Dsl::Main
|
|
25
25
|
def load(glob = '')
|
26
26
|
return if glob.blank?
|
27
27
|
|
28
|
+
loaded = false
|
28
29
|
Eye::Dsl::Opts.with_parsed_file(glob) do |mask|
|
29
30
|
Dir[mask].each do |path|
|
31
|
+
loaded = true
|
30
32
|
Eye::Dsl.debug "=> load #{path}"
|
31
33
|
Eye.parsed_filename = path
|
32
34
|
res = Kernel.load(path)
|
@@ -34,6 +36,11 @@ module Eye::Dsl::Main
|
|
34
36
|
Eye::Dsl.debug "<= load #{path}"
|
35
37
|
end
|
36
38
|
end
|
39
|
+
|
40
|
+
unless loaded
|
41
|
+
puts "Warning! Eye.load not found: '#{glob}'"
|
42
|
+
warn "not found: '#{glob}'"
|
43
|
+
end
|
37
44
|
end
|
38
45
|
|
39
46
|
def config(&block)
|
data/lib/eye/dsl/opts.rb
CHANGED
@@ -68,6 +68,19 @@ class Eye::Dsl::Opts < Eye::Dsl::PureOpts
|
|
68
68
|
alias trigger triggers
|
69
69
|
alias notrigger notriggers
|
70
70
|
|
71
|
+
def command(cmd, arg)
|
72
|
+
@config[:user_commands] ||= {}
|
73
|
+
|
74
|
+
if arg.is_a?(Array)
|
75
|
+
validate_signals(arg)
|
76
|
+
elsif arg.is_a?(String)
|
77
|
+
else
|
78
|
+
raise Eye::Dsl::Error, "unknown command #{cmd.inspect} type should be String or Array"
|
79
|
+
end
|
80
|
+
|
81
|
+
@config[:user_commands][cmd.to_sym] = arg
|
82
|
+
end
|
83
|
+
|
71
84
|
def notify(contact, level = :warn)
|
72
85
|
unless Eye::Process::Notify::LEVELS[level]
|
73
86
|
raise Eye::Dsl::Error, "level should be in #{Eye::Process::Notify::LEVELS.keys}"
|
@@ -82,6 +95,11 @@ class Eye::Dsl::Opts < Eye::Dsl::PureOpts
|
|
82
95
|
@config[:notify].delete(contact.to_s)
|
83
96
|
end
|
84
97
|
|
98
|
+
def set_stop_signals(value)
|
99
|
+
super
|
100
|
+
validate_signals(value)
|
101
|
+
end
|
102
|
+
|
85
103
|
def set_environment(value)
|
86
104
|
raise Eye::Dsl::Error, "environment should be a hash, but not #{value.inspect}" unless value.is_a?(Hash)
|
87
105
|
@config[:environment] ||= {}
|
@@ -148,4 +166,18 @@ class Eye::Dsl::Opts < Eye::Dsl::PureOpts
|
|
148
166
|
on_server
|
149
167
|
end
|
150
168
|
|
169
|
+
private
|
170
|
+
|
171
|
+
def validate_signals(signals = nil)
|
172
|
+
return unless signals
|
173
|
+
raise Eye::Dsl::Error, "signals should be Array" unless signals.is_a?(Array)
|
174
|
+
s = signals.clone
|
175
|
+
while s.present?
|
176
|
+
sig = s.shift
|
177
|
+
timeout = s.shift
|
178
|
+
raise Eye::Dsl::Error, "signal should be String, Symbol, Fixnum, not #{sig.inspect}" if sig && ![String, Symbol, Fixnum].include?(sig.class)
|
179
|
+
raise Eye::Dsl::Error, "signal sleep should be Numeric, not #{timeout.inspect}" if timeout && ![Fixnum, Float].include?(timeout.class)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
151
183
|
end
|
data/lib/eye/group.rb
CHANGED
data/lib/eye/logger.rb
CHANGED
data/lib/eye/process.rb
CHANGED
@@ -17,9 +17,9 @@ class Eye::Process
|
|
17
17
|
autoload :Scheduler, 'eye/process/scheduler'
|
18
18
|
autoload :Validate, 'eye/process/validate'
|
19
19
|
|
20
|
-
attr_accessor :pid, :
|
21
|
-
:
|
22
|
-
:
|
20
|
+
attr_accessor :pid, :parent_pid,
|
21
|
+
:watchers, :config, :states_history,
|
22
|
+
:children, :triggers, :name, :state_reason, :flapping_times
|
23
23
|
|
24
24
|
def initialize(config)
|
25
25
|
raise 'you must supply a pid_file location' unless config[:pid_file]
|
data/lib/eye/process/commands.rb
CHANGED
@@ -277,4 +277,27 @@ private
|
|
277
277
|
sleep grace
|
278
278
|
end
|
279
279
|
|
280
|
+
def execute_user_command(name, cmd)
|
281
|
+
info "executing user command #{name} #{cmd.inspect}"
|
282
|
+
|
283
|
+
# cmd is string, or array of signals
|
284
|
+
if cmd.is_a?(String)
|
285
|
+
res = execute(cmd, config.merge(:timeout => 120))
|
286
|
+
error "cmd #{cmd} error #{res.inspect}" if res[:error]
|
287
|
+
elsif cmd.is_a?(Array)
|
288
|
+
signals = cmd.clone
|
289
|
+
signal = signals.shift
|
290
|
+
send_signal(signal)
|
291
|
+
|
292
|
+
while signals.present?
|
293
|
+
delay = signals.shift
|
294
|
+
signal = signals.shift
|
295
|
+
sleep (delay.to_f)
|
296
|
+
send_signal(signal) if signal
|
297
|
+
end
|
298
|
+
else
|
299
|
+
warn "unknown user command #{c}"
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
280
303
|
end
|
data/lib/eye/process/system.rb
CHANGED
@@ -3,10 +3,23 @@ require 'timeout'
|
|
3
3
|
module Eye::Process::System
|
4
4
|
|
5
5
|
def load_pid_from_file
|
6
|
-
if File.exists?(self[:pid_file_ex])
|
6
|
+
res = if File.exists?(self[:pid_file_ex])
|
7
7
|
_pid = File.read(self[:pid_file_ex]).to_i
|
8
8
|
_pid > 0 ? _pid : nil
|
9
9
|
end
|
10
|
+
|
11
|
+
# check pid from pid_file, in case when server reboot, or something
|
12
|
+
# sometimes pid can be one of the eye-self(lwp) pid, we dont want
|
13
|
+
# eye to die
|
14
|
+
if res && res != self.pid
|
15
|
+
cmd = Eye::Sigar.proc_args(res)[0].to_s rescue ''
|
16
|
+
if res == $$ || cmd.start_with?(Eye::PROCLINE)
|
17
|
+
error "Wtf? O_o load eye-self(lwp) pid_file #{res} #{$$} '#{cmd}'"
|
18
|
+
return
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
res
|
10
23
|
end
|
11
24
|
|
12
25
|
def set_pid_from_file
|
data/lib/eye/process/validate.rb
CHANGED
@@ -28,16 +28,6 @@ module Eye::Process::Validate
|
|
28
28
|
raise Error, "working_dir '#{config[:working_dir]}' is invalid" unless File.directory?(config[:working_dir])
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
32
|
-
if config[:stop_signals]
|
33
|
-
s = config[:stop_signals].clone
|
34
|
-
while s.present?
|
35
|
-
sig = s.shift
|
36
|
-
timeout = s.shift
|
37
|
-
raise Error, "signal should be String, Symbol, Fixnum, not #{sig.inspect}" if sig && ![String, Symbol, Fixnum].include?(sig.class)
|
38
|
-
raise Error, "signal sleep should be Numeric, not #{timeout.inspect}" if timeout && ![Fixnum, Float].include?(timeout.class)
|
39
|
-
end
|
40
|
-
end
|
41
31
|
end
|
42
32
|
|
43
33
|
end
|
data/lib/eye/server.rb
CHANGED
@@ -24,13 +24,13 @@ class Eye::Server
|
|
24
24
|
text = socket.read
|
25
25
|
|
26
26
|
begin
|
27
|
-
|
27
|
+
cmd, *args = Marshal.load(text)
|
28
28
|
rescue => ex
|
29
29
|
error "Failed to read from socket: #{ex.message}"
|
30
30
|
return
|
31
31
|
end
|
32
32
|
|
33
|
-
response = command(
|
33
|
+
response = command(cmd, *args)
|
34
34
|
socket.write(Marshal.dump(response))
|
35
35
|
|
36
36
|
rescue Errno::EPIPE
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eye
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Makarchev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|