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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGE3MGMyMzNhZDBlYmQ5ZTdmYWEyMDMxODljMTgzODRlOGJjNzY5Nw==
4
+ ZjNkZTlhODlmNzc5YmZjNzhlZDVmYmVmZDQ0MGFjYjBhYzY0NDYzYg==
5
5
  data.tar.gz: !binary |-
6
- NDY3NTA4MzliNzZjN2ZkYTg1OGM4OGIwODk3NWRkYzJlOWE3MzM3Yg==
6
+ MmNmM2ExMTcwMDMxOGI3NjEwNjAxYWFkNGZkY2MxNDIxNTNkYTI3Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTM4ZTdkZmI2ZGViN2JlYjZmZjg0NmUyOTFjZWY1OGMyOGQ5NTEwMDY0Yjg0
10
- MDdjMmJkMTI1ZTU2NDk4MjFjMjBlYTRmZWI5NzMwMTU1M2YzZTM3M2I1YzQx
11
- OWQyMzYwMjliODM5YmVjM2RhMmY2MTgzYzZhYjBjZWRjNmJmOTg=
9
+ YjJlYzQwZWY4OTY2MzUzODAzYzUzZDg5ZDU4MTJmMTk5NTE1YWEzYmMzMDBl
10
+ OGUwYmU0MjI0NjFiMjU3N2NlYjQ1N2E5YjZkMmZmMjhkZDRlYjVhMDRjMDY4
11
+ ZDE3ZGE1NjVhNzBkMzY3NGEzZmM1NzNiMzhjMzEwMTZmNjk1YjQ=
12
12
  data.tar.gz: !binary |-
13
- ODVjMTcyZGFlZTQyNzczMWM2MDU2MWU4Mzc0NDI0MzBlZGRmNzNkYjQyNTQ2
14
- ZWExZjcyMTVjYjUxNTc4MDY4Yjc3YTliZTQ4MmU1ZDdmMWNkOTUxYTVlOGQx
15
- ODliODNkY2Q5ZTNlNzA1N2FlZjhiOGVlNWQ0MzlhN2E2MzFiZjY=
13
+ NWVhZmIwZTcxOWY3N2RhMmFhM2JlN2M2NjU3OGQ1NjdkYjQxMDRiZWViYTQy
14
+ YWFjOWU3MjdlMjZlZTRhOTczY2U2NWQ0ZmNlYjRjMWM4ZjgzZDg1NzM0YzNm
15
+ MTYxYjcyOTBjZTg5NGYzNjczYzU4YTAzNTZkMTM2MTBkYjhkMDY=
@@ -54,7 +54,7 @@ Eye::Control # preload
54
54
 
55
55
  if config
56
56
  res = server.command('load', config)
57
- exit if res.values.any? { |r| r[:error] }
57
+ exit(1) if res.values.any? { |r| r[:error] }
58
58
  end
59
59
 
60
60
  Eye::Control.set_proc_line
data/lib/eye.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Eye
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2.pre"
3
3
  ABOUT = "Eye v#{VERSION} (c) 2012-2014 @kostya"
4
4
  PROCLINE = "eye monitoring v#{VERSION}"
5
5
 
@@ -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 :(", :yellow
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)
@@ -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)
@@ -31,8 +31,6 @@ class Eye::Controller
31
31
 
32
32
  attr_reader :applications, :current_config
33
33
 
34
- exclusive :load # load is hard command, so better to run it safely blocked
35
-
36
34
  def initialize
37
35
  @applications = []
38
36
  @current_config = Eye::Config.new
@@ -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
@@ -25,7 +25,7 @@ module Eye::Controller::Load
25
25
 
26
26
  set_proc_line
27
27
 
28
- info "<= loading: #{obj_strs}, in: <#{$$}>"
28
+ info "<= loading: #{obj_strs}"
29
29
 
30
30
  res
31
31
  end
@@ -22,6 +22,12 @@ module Eye::Controller::SendCommand
22
22
  end
23
23
  end
24
24
 
25
+ def user_command(cmd, *args)
26
+ matched_objects(*args) do |obj|
27
+ obj.send_command :user_command, cmd
28
+ end
29
+ end
30
+
25
31
  private
26
32
 
27
33
  class Error < Exception; end
@@ -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)
@@ -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
@@ -113,6 +113,10 @@ class Eye::Group
113
113
  async_schedule :signal, sig
114
114
  end
115
115
 
116
+ def user_command(cmd)
117
+ async_schedule :user_command, cmd
118
+ end
119
+
116
120
  def break_chain
117
121
  info 'break chain'
118
122
  scheduler_clear_pending_list
@@ -10,7 +10,7 @@ class Eye::Logger
10
10
  super
11
11
 
12
12
  self.formatter = Proc.new do |s, d, p, m|
13
- "#{d.strftime(FORMAT)} #{s.ljust(5)} -- #{m}\n"
13
+ "#{d.strftime(FORMAT)} $#{$$} #{s.ljust(5)} -- #{m}\n"
14
14
  end
15
15
  end
16
16
  end
@@ -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, :watchers, :config, :states_history,
21
- :children, :triggers, :name, :state_reason, :flapping_times,
22
- :parent_pid
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]
@@ -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
@@ -70,4 +70,10 @@ module Eye::Process::Controller
70
70
  send_signal(sig) if self.pid
71
71
  end
72
72
 
73
+ def user_command(name)
74
+ if self[:user_commands] && c = self[:user_commands][name.to_sym]
75
+ execute_user_command(name, c)
76
+ end
77
+ end
78
+
73
79
  end
@@ -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
@@ -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
@@ -24,13 +24,13 @@ class Eye::Server
24
24
  text = socket.read
25
25
 
26
26
  begin
27
- command, *args = Marshal.load(text)
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(command, *args)
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.1
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-06-07 00:00:00.000000000 Z
11
+ date: 2014-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid