eye 0.8.celluloid15 → 0.8.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -5
  3. data/CHANGES.md +3 -7
  4. data/README.md +2 -5
  5. data/Rakefile +6 -6
  6. data/bin/leye +4 -9
  7. data/bin/loader_eye +15 -14
  8. data/examples/delayed_job.eye +3 -3
  9. data/examples/dependency.eye +11 -10
  10. data/examples/notify.eye +4 -3
  11. data/examples/plugin/main.eye +5 -5
  12. data/examples/plugin/plugin.rb +2 -10
  13. data/examples/process_thin.rb +8 -8
  14. data/examples/processes/em.rb +12 -18
  15. data/examples/processes/forking.rb +5 -5
  16. data/examples/processes/sample.rb +44 -46
  17. data/examples/puma.eye +8 -9
  18. data/examples/rbenv.eye +5 -5
  19. data/examples/sidekiq.eye +3 -3
  20. data/examples/stress_test.eye +4 -4
  21. data/examples/syslog.eye +1 -1
  22. data/examples/test.eye +2 -1
  23. data/examples/thin-farm.eye +8 -7
  24. data/examples/triggers.eye +15 -13
  25. data/examples/unicorn.eye +13 -12
  26. data/eye.gemspec +14 -16
  27. data/lib/eye.rb +3 -2
  28. data/lib/eye/application.rb +6 -5
  29. data/lib/eye/checker.rb +25 -44
  30. data/lib/eye/checker/children_count.rb +1 -1
  31. data/lib/eye/checker/file_ctime.rb +1 -1
  32. data/lib/eye/checker/http.rb +15 -13
  33. data/lib/eye/checker/nop.rb +0 -1
  34. data/lib/eye/checker/socket.rb +63 -60
  35. data/lib/eye/checker/ssl_socket.rb +5 -5
  36. data/lib/eye/child_process.rb +4 -6
  37. data/lib/eye/cli.rb +46 -74
  38. data/lib/eye/cli/commands.rb +5 -4
  39. data/lib/eye/cli/render.rb +41 -61
  40. data/lib/eye/cli/server.rb +16 -19
  41. data/lib/eye/client.rb +0 -1
  42. data/lib/eye/config.rb +33 -36
  43. data/lib/eye/controller.rb +3 -2
  44. data/lib/eye/controller/commands.rb +1 -1
  45. data/lib/eye/controller/helpers.rb +2 -2
  46. data/lib/eye/controller/load.rb +17 -19
  47. data/lib/eye/controller/options.rb +5 -1
  48. data/lib/eye/controller/send_command.rb +23 -21
  49. data/lib/eye/controller/status.rb +15 -17
  50. data/lib/eye/dsl.rb +1 -6
  51. data/lib/eye/dsl/application_opts.rb +3 -4
  52. data/lib/eye/dsl/chain.rb +2 -2
  53. data/lib/eye/dsl/child_process_opts.rb +3 -3
  54. data/lib/eye/dsl/config_opts.rb +7 -7
  55. data/lib/eye/dsl/group_opts.rb +3 -3
  56. data/lib/eye/dsl/helpers.rb +1 -1
  57. data/lib/eye/dsl/main.rb +3 -4
  58. data/lib/eye/dsl/opts.rb +28 -31
  59. data/lib/eye/dsl/process_opts.rb +7 -13
  60. data/lib/eye/dsl/pure_opts.rb +9 -13
  61. data/lib/eye/dsl/validation.rb +35 -48
  62. data/lib/eye/group.rb +8 -23
  63. data/lib/eye/group/chain.rb +6 -6
  64. data/lib/eye/loader.rb +3 -3
  65. data/lib/eye/local.rb +4 -9
  66. data/lib/eye/logger.rb +4 -11
  67. data/lib/eye/notify.rb +6 -10
  68. data/lib/eye/notify/jabber.rb +1 -1
  69. data/lib/eye/notify/mail.rb +2 -2
  70. data/lib/eye/notify/slack.rb +3 -4
  71. data/lib/eye/process.rb +0 -2
  72. data/lib/eye/process/children.rb +4 -4
  73. data/lib/eye/process/commands.rb +39 -38
  74. data/lib/eye/process/config.rb +16 -22
  75. data/lib/eye/process/controller.rb +19 -5
  76. data/lib/eye/process/data.rb +9 -11
  77. data/lib/eye/process/monitor.rb +76 -86
  78. data/lib/eye/process/notify.rb +10 -10
  79. data/lib/eye/process/scheduler.rb +31 -36
  80. data/lib/eye/process/states.rb +5 -7
  81. data/lib/eye/process/states_history.rb +3 -9
  82. data/lib/eye/process/system.rb +20 -35
  83. data/lib/eye/process/trigger.rb +5 -1
  84. data/lib/eye/process/watchers.rb +9 -12
  85. data/lib/eye/reason.rb +1 -4
  86. data/lib/eye/server.rb +1 -2
  87. data/lib/eye/system.rb +15 -22
  88. data/lib/eye/system_resources.rb +9 -18
  89. data/lib/eye/trigger.rb +16 -18
  90. data/lib/eye/trigger/check_dependency.rb +4 -7
  91. data/lib/eye/trigger/flapping.rb +7 -24
  92. data/lib/eye/trigger/starting_guard.rb +6 -7
  93. data/lib/eye/trigger/stop_children.rb +2 -2
  94. data/lib/eye/trigger/transition.rb +1 -1
  95. data/lib/eye/trigger/wait_dependency.rb +2 -3
  96. data/lib/eye/utils.rb +3 -4
  97. data/lib/eye/utils/alive_array.rb +4 -9
  98. data/lib/eye/utils/celluloid_chain.rb +10 -12
  99. data/lib/eye/utils/leak_19.rb +10 -0
  100. data/lib/eye/utils/mini_active_support.rb +16 -16
  101. data/lib/eye/utils/pmap.rb +0 -2
  102. data/lib/eye/utils/tail.rb +2 -2
  103. metadata +8 -39
  104. data/.rubocop.yml +0 -141
  105. data/examples/custom_check.eye +0 -24
  106. data/examples/custom_trigger.eye +0 -30
  107. data/examples/leye_example/Eyefile +0 -10
@@ -1,5 +1,4 @@
1
1
  module Eye::Dsl::Validation
2
-
3
2
  def self.included(base)
4
3
  base.extend(ClassMethods)
5
4
  end
@@ -7,37 +6,25 @@ module Eye::Dsl::Validation
7
6
  class Error < Exception; end
8
7
 
9
8
  module ClassMethods
10
-
11
9
  def inherited(subclass)
12
- subclass.validates = validates.clone
13
- subclass.should_bes = should_bes.clone
14
- subclass.defaults = defaults.clone
15
- subclass.variants = variants.clone
10
+ subclass.validates = self.validates.clone
11
+ subclass.should_bes = self.should_bes.clone
12
+ subclass.defaults = self.defaults.clone
13
+ subclass.variants = self.variants.clone
16
14
  end
17
15
 
18
16
  attr_accessor :validates, :should_bes, :defaults, :variants
19
17
 
20
- def validates
21
- @validates ||= {}
22
- end
23
-
24
- def should_bes
25
- @should_bes ||= []
26
- end
27
-
28
- def defaults
29
- @defaults ||= {}
30
- end
31
-
32
- def variants
33
- @variants ||= {}
34
- end
18
+ def validates; @validates ||= {}; end
19
+ def should_bes; @should_bes ||= []; end
20
+ def defaults; @defaults ||= {}; end
21
+ def variants; @variants ||= {}; end
35
22
 
36
23
  def param(param, types = [], should_be = false, default = nil, variants = nil)
37
24
  param = param.to_sym
38
25
 
39
- validates[param] = types
40
- should_bes << param if should_be
26
+ self.validates[param] = types
27
+ self.should_bes << param if should_be
41
28
  param_default(param, default)
42
29
  self.variants[param] = variants
43
30
 
@@ -68,38 +55,38 @@ module Eye::Dsl::Validation
68
55
  end
69
56
 
70
57
  def validate(options = {})
71
- options.each { |param, value| validate_param(param, value) }
72
-
73
- should_bes.each do |param|
74
- raise Error, "#{name} for param :#{param} value should be" unless options[param.to_sym] || defaults[param.to_sym]
75
- end
76
- end
77
-
78
- def validate_param(param, value)
79
- param = param.to_sym
80
- types = validates[param]
81
- if !types && param != :type
82
- raise Error, "#{name} unknown param :#{param} value #{value.inspect}"
83
- end
58
+ options.each do |param, value|
59
+ param = param.to_sym
60
+ types = validates[param]
61
+ unless types
62
+ if param != :type
63
+ raise Error, "#{self.name} unknown param :#{param} value #{value.inspect}"
64
+ end
65
+ end
84
66
 
85
- if variants[param] && value && !value.is_a?(Proc)
86
- if value.is_a?(Array)
87
- value = value.reject { |v| v.is_a?(Proc) }
88
- if (value - variants[param]).present?
89
- raise Error, "#{value.inspect} should be within #{variants[param].inspect}"
67
+ if self.variants[param]
68
+ if value && !value.is_a?(Proc)
69
+ if value.is_a?(Array)
70
+ if (value - self.variants[param]).present?
71
+ raise Error, "#{value.inspect} should be within #{self.variants[param].inspect}"
72
+ end
73
+ elsif !self.variants[param].include?(value)
74
+ raise Error, "#{value.inspect} should be within #{self.variants[param].inspect}"
75
+ end
90
76
  end
91
- elsif !variants[param].include?(value)
92
- raise Error, "#{value.inspect} should be within #{variants[param].inspect}"
93
77
  end
94
- end
95
78
 
96
- if types.present?
79
+ next if types.blank?
80
+
97
81
  types = Array(types)
98
- good = types.any? { |type| value.is_a?(type) }
99
- raise Error, "#{name} bad param :#{param} value #{value.inspect}, type #{types.inspect}" unless good
82
+ good = types.any?{|type| value.is_a?(type) }
83
+ raise Error, "#{self.name} bad param :#{param} value #{value.inspect}, type #{types.inspect}" unless good
100
84
  end
101
- end
102
85
 
86
+ should_bes.each do |param|
87
+ raise Error, "#{self.name} for param :#{param} value should be" unless options[param.to_sym] || defaults[param.to_sym]
88
+ end
89
+ end
103
90
  end
104
91
 
105
92
  end
@@ -1,7 +1,6 @@
1
1
  require 'celluloid'
2
2
 
3
3
  class Eye::Group
4
-
5
4
  include Celluloid
6
5
 
7
6
  autoload :Chain, 'eye/group/chain'
@@ -45,12 +44,12 @@ class Eye::Group
45
44
  @processes = @processes.sort_by(&:name)
46
45
  end
47
46
 
48
- def status_data(opts = {})
49
- plist = @processes.map { |p| p.status_data(opts) }
47
+ def status_data(debug = false)
48
+ plist = @processes.map{|p| p.status_data(debug) }
50
49
 
51
50
  h = { name: name, type: :group, subtree: plist }
52
51
 
53
- h[:debug] = debug_data if opts[:debug]
52
+ h[:debug] = debug_data if debug
54
53
 
55
54
  # show current chain
56
55
  if current_scheduled_command
@@ -69,17 +68,16 @@ class Eye::Group
69
68
  end
70
69
 
71
70
  def status_data_short
72
- h = {}
71
+ h = Hash.new
73
72
  @processes.each do |p|
74
- state = p.state
75
- h[state] ||= 0
76
- h[state] += 1
73
+ h[p.state] ||= 0
74
+ h[p.state] += 1
77
75
  end
78
76
  { name: (@name == '__default__' ? 'default' : @name), type: :group, states: h }
79
77
  end
80
78
 
81
79
  def debug_data
82
- { queue: scheduler_actions_list, chain: chain_status }
80
+ {:queue => scheduler_actions_list, :chain => chain_status}
83
81
  end
84
82
 
85
83
  def send_command(command, *args)
@@ -146,23 +144,10 @@ class Eye::Group
146
144
  @processes.include?(obj)
147
145
  end
148
146
 
149
- # to sort groups
150
- def <=>(other)
151
- if hidden
152
- 1
153
- else
154
- if other.hidden
155
- -1
156
- else
157
- name <=> other.name
158
- end
159
- end
160
- end
161
-
162
147
  private
163
148
 
164
149
  def async_schedule(command, *args)
165
- info "send to all processes #{command} #{args.present? ? args * ',' : nil}"
150
+ info "send to all processes #{command} #{args.present? ? args*',' : nil}"
166
151
 
167
152
  @processes.each do |process|
168
153
  process.send_command(command, *args) unless process.skip_group_action?(command)
@@ -11,7 +11,7 @@ private
11
11
 
12
12
  started_at = Time.now
13
13
 
14
- @processes.each do |process|
14
+ @processes.each do | process |
15
15
  if process.skip_group_action?(command)
16
16
  @chain_processes_current = @chain_processes_current.to_i + 1
17
17
  next
@@ -44,7 +44,7 @@ private
44
44
  # sync command, with waiting
45
45
  # this is very hackety, because call method of the process without its scheduler
46
46
  # need to provide some scheduler future
47
- process.last_scheduled_reason = last_scheduled_reason
47
+ process.last_scheduled_reason = self.last_scheduled_reason
48
48
  process.send(command, *args)
49
49
  else
50
50
  # async command
@@ -54,7 +54,7 @@ private
54
54
 
55
55
  def chain_status
56
56
  if @config[:chain]
57
- [:start, :restart].map { |c| @config[:chain][c].try(:[], :grace) }
57
+ [:start, :restart].map{|c| @config[:chain][c].try(:[], :grace) }
58
58
  end
59
59
  end
60
60
 
@@ -67,7 +67,7 @@ private
67
67
  DEFAULT_CHAIN = 0.2
68
68
 
69
69
  def chain_options(command)
70
- command = :start if command == :monitor # HACK: for monitor command, work as start
70
+ command = :start if command == :monitor # hack for monitor command, work as start
71
71
 
72
72
  if @config[:chain] && @config[:chain][command]
73
73
  type = @config[:chain][command].try :[], :type
@@ -76,10 +76,10 @@ private
76
76
  grace = @config[:chain][command].try :[], :grace
77
77
  grace = grace ? (grace.to_f rescue DEFAULT_CHAIN) : DEFAULT_CHAIN
78
78
 
79
- { type: type, grace: grace }
79
+ {:type => type, :grace => grace}
80
80
  else
81
81
  # default chain case
82
- { type: :async, grace: DEFAULT_CHAIN }
82
+ {:type => :async, :grace => DEFAULT_CHAIN}
83
83
  end
84
84
  end
85
85
 
@@ -1,10 +1,10 @@
1
1
  # add gems to $: by `gem` method
2
2
  # this is only way when install eye as system wide
3
3
 
4
- gem 'celluloid', '~> 0.15.0'
5
- gem 'celluloid-io', '~> 0.15.0'
4
+ gem 'celluloid', '~> 0.17.0'
5
+ gem 'celluloid-io', '~> 0.17.0'
6
6
  gem 'nio4r'
7
7
  gem 'timers'
8
8
 
9
9
  gem 'state_machine'
10
- gem 'sigar', '~> 0.7.3'
10
+ gem 'sigar', '~> 0.7.2'
@@ -1,9 +1,7 @@
1
1
  require 'fileutils'
2
2
 
3
3
  module Eye::Local
4
-
5
4
  class << self
6
-
7
5
  def dir
8
6
  @dir ||= begin
9
7
  if root?
@@ -30,7 +28,7 @@ module Eye::Local
30
28
 
31
29
  def home
32
30
  h = ENV['EYE_HOME'] || ENV['HOME']
33
- raise 'HOME undefined, should be HOME or EYE_HOME environment' unless h
31
+ raise "HOME undefined, should be HOME or EYE_HOME environment" unless h
34
32
  h
35
33
  end
36
34
 
@@ -39,7 +37,7 @@ module Eye::Local
39
37
  end
40
38
 
41
39
  def ensure_eye_dir
42
- FileUtils.mkdir_p(dir) unless ENV['EYE_SOCK'] && ENV['EYE_PID']
40
+ FileUtils.mkdir_p(dir)
43
41
  end
44
42
 
45
43
  def socket_path
@@ -74,7 +72,7 @@ module Eye::Local
74
72
  end
75
73
 
76
74
  def eyefile
77
- @eyefile ||= find_eyefile(ENV['EYE_HOME'] || '.')
75
+ @eyefile ||= find_eyefile('.')
78
76
  end
79
77
 
80
78
  def find_eyefile(start_from_dir)
@@ -87,13 +85,10 @@ module Eye::Local
87
85
  until !File.directory?(current) || current == previous
88
86
  filename = File.join(current, 'Eyefile')
89
87
  return filename if File.file?(filename)
90
- previous = current
91
- current = File.expand_path('..', current)
88
+ current, previous = File.expand_path('..', current), current
92
89
  end
93
90
  end
94
91
 
95
92
  attr_accessor :local_runner
96
-
97
93
  end
98
-
99
94
  end
@@ -1,27 +1,23 @@
1
1
  require 'logger'
2
2
 
3
3
  class Eye::Logger
4
-
5
4
  attr_accessor :prefix, :subprefix
6
5
 
7
6
  class InnerLogger < Logger
8
-
9
7
  FORMAT = '%d.%m.%Y %H:%M:%S'
10
8
 
11
9
  def initialize(*args)
12
10
  super
13
11
 
14
- self.formatter = proc do |s, d, _p, m|
12
+ self.formatter = Proc.new do |s, d, p, m|
15
13
  "#{d.strftime(FORMAT)} #{s.ljust(5)} -- #{m}\n"
16
14
  end
17
15
  end
18
-
19
16
  end
20
17
 
21
18
  module ObjectExt
22
-
23
19
  def logger_tag
24
- [Class, Module].include?(self.class) ? to_s : "<#{self.class}>"
20
+ [Class, Module].include?(self.class) ? to_s : "<#{self.class.to_s}>"
25
21
  end
26
22
 
27
23
  def logger_sub_tag
@@ -42,7 +38,6 @@ class Eye::Logger
42
38
  error "#{ex.message} #{ex.backtrace}"
43
39
  # notify here?
44
40
  end
45
-
46
41
  end
47
42
 
48
43
  Logger::Severity.constants.each do |level|
@@ -62,7 +57,6 @@ class Eye::Logger
62
57
  end
63
58
 
64
59
  class << self
65
-
66
60
  attr_reader :dev, :log_level, :args
67
61
 
68
62
  def link_logger(dev, *args)
@@ -80,7 +74,7 @@ class Eye::Logger
80
74
  @inner_logger = dev
81
75
  end
82
76
 
83
- @inner_logger.level = log_level || Logger::INFO
77
+ @inner_logger.level = self.log_level || Logger::INFO
84
78
 
85
79
  rescue Exception
86
80
  @inner_logger = nil
@@ -94,13 +88,12 @@ class Eye::Logger
94
88
 
95
89
  def log_level=(level)
96
90
  @log_level = level
97
- @inner_logger.level = log_level if @inner_logger
91
+ @inner_logger.level = self.log_level if @inner_logger
98
92
  end
99
93
 
100
94
  def inner_logger
101
95
  @inner_logger ||= InnerLogger.new(nil)
102
96
  end
103
-
104
97
  end
105
98
 
106
99
  private
@@ -1,7 +1,6 @@
1
1
  require 'celluloid'
2
2
 
3
3
  class Eye::Notify
4
-
5
4
  include Celluloid
6
5
  include Eye::Dsl::Validation
7
6
 
@@ -9,7 +8,7 @@ class Eye::Notify
9
8
  autoload :Jabber, 'eye/notify/jabber'
10
9
  autoload :Slack, 'eye/notify/slack'
11
10
 
12
- TYPES = { mail: 'Mail', jabber: 'Jabber', slack: 'Slack' }
11
+ TYPES = {:mail => 'Mail', :jabber => 'Jabber', :slack => 'Slack'}
13
12
 
14
13
  def self.get_class(type)
15
14
  klass = eval("Eye::Notify::#{TYPES[type]}") rescue nil
@@ -36,19 +35,19 @@ class Eye::Notify
36
35
 
37
36
  create_proc = lambda do |nh|
38
37
  type = nh[:type]
39
- config = (settings[type] || {}).merge(nh[:opts] || {}).merge(contact: nh[:contact])
38
+ config = (settings[type] || {}).merge(nh[:opts] || {}).merge(:contact => nh[:contact])
40
39
  klass = get_class(type)
41
40
  notify = klass.new(config, message_h)
42
41
  notify.async_notify if notify
43
42
  end
44
43
 
45
44
  if needed_hash.is_a?(Array)
46
- needed_hash.each { |nh| create_proc[nh] }
45
+ needed_hash.each{|nh| create_proc[nh] }
47
46
  else
48
47
  create_proc[needed_hash]
49
48
  end
50
49
 
51
- rescue Object => ex
50
+ rescue Exception, Timeout::Error => ex
52
51
  log_ex(ex)
53
52
  end
54
53
 
@@ -67,7 +66,7 @@ class Eye::Notify
67
66
 
68
67
  def async_notify
69
68
  async.notify
70
- after(TIMEOUT) { terminate }
69
+ after(TIMEOUT){ terminate }
71
70
  end
72
71
 
73
72
  def notify
@@ -103,18 +102,15 @@ class Eye::Notify
103
102
  end
104
103
 
105
104
  class Custom < Eye::Notify
106
-
107
105
  def self.inherited(base)
108
106
  super
109
107
  register(base)
110
108
  end
111
-
112
109
  end
113
110
 
114
- %w[at host message name full_name pid level].each do |name|
111
+ %w{at host message name full_name pid level}.each do |name|
115
112
  define_method("msg_#{name}") do
116
113
  @message_h[name.to_sym]
117
114
  end
118
115
  end
119
-
120
116
  end
@@ -27,4 +27,4 @@ class Eye::Notify::Jabber < Eye::Notify
27
27
  client.close
28
28
  end
29
29
 
30
- end
30
+ end
@@ -41,8 +41,8 @@ class Eye::Notify::Mail < Eye::Notify
41
41
  h << "To: <#{contact}>"
42
42
  h << "Subject: #{message_subject}"
43
43
  h << "Date: #{msg_at.httpdate}"
44
- h << "Message-Id: <#{rand(1_000_000_000).to_s(36)}.#{$$}.#{contact}>"
44
+ h << "Message-Id: <#{rand(1000000000).to_s(36)}.#{$$}.#{contact}>"
45
45
  "#{h * "\n"}\n#{message_body}"
46
46
  end
47
47
 
48
- end
48
+ end