eye 0.7 → 0.8.celluloid15

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/.rubocop.yml +141 -0
  3. data/.travis.yml +5 -3
  4. data/CHANGES.md +9 -1
  5. data/README.md +5 -2
  6. data/Rakefile +6 -6
  7. data/bin/leye +9 -4
  8. data/bin/loader_eye +14 -15
  9. data/examples/custom_check.eye +24 -0
  10. data/examples/custom_trigger.eye +30 -0
  11. data/examples/delayed_job.eye +3 -3
  12. data/examples/dependency.eye +10 -11
  13. data/examples/leye_example/Eyefile +10 -0
  14. data/examples/notify.eye +3 -4
  15. data/examples/plugin/main.eye +5 -5
  16. data/examples/plugin/plugin.rb +10 -2
  17. data/examples/process_thin.rb +8 -8
  18. data/examples/processes/em.rb +18 -12
  19. data/examples/processes/forking.rb +5 -5
  20. data/examples/processes/sample.rb +46 -44
  21. data/examples/puma.eye +9 -8
  22. data/examples/rbenv.eye +5 -5
  23. data/examples/sidekiq.eye +3 -3
  24. data/examples/stress_test.eye +4 -4
  25. data/examples/syslog.eye +1 -1
  26. data/examples/test.eye +1 -2
  27. data/examples/thin-farm.eye +7 -8
  28. data/examples/triggers.eye +13 -15
  29. data/examples/unicorn.eye +12 -13
  30. data/eye.gemspec +16 -14
  31. data/lib/eye.rb +2 -3
  32. data/lib/eye/application.rb +5 -6
  33. data/lib/eye/checker.rb +44 -25
  34. data/lib/eye/checker/children_count.rb +1 -1
  35. data/lib/eye/checker/file_ctime.rb +1 -1
  36. data/lib/eye/checker/http.rb +13 -15
  37. data/lib/eye/checker/nop.rb +1 -0
  38. data/lib/eye/checker/socket.rb +60 -63
  39. data/lib/eye/checker/ssl_socket.rb +5 -5
  40. data/lib/eye/child_process.rb +6 -4
  41. data/lib/eye/cli.rb +74 -46
  42. data/lib/eye/cli/commands.rb +4 -5
  43. data/lib/eye/cli/render.rb +61 -41
  44. data/lib/eye/cli/server.rb +19 -16
  45. data/lib/eye/client.rb +1 -0
  46. data/lib/eye/config.rb +36 -33
  47. data/lib/eye/controller.rb +2 -3
  48. data/lib/eye/controller/commands.rb +1 -1
  49. data/lib/eye/controller/helpers.rb +2 -2
  50. data/lib/eye/controller/load.rb +19 -17
  51. data/lib/eye/controller/options.rb +1 -5
  52. data/lib/eye/controller/send_command.rb +21 -23
  53. data/lib/eye/controller/status.rb +17 -14
  54. data/lib/eye/dsl.rb +6 -1
  55. data/lib/eye/dsl/application_opts.rb +4 -3
  56. data/lib/eye/dsl/chain.rb +2 -2
  57. data/lib/eye/dsl/child_process_opts.rb +3 -3
  58. data/lib/eye/dsl/config_opts.rb +7 -7
  59. data/lib/eye/dsl/group_opts.rb +3 -3
  60. data/lib/eye/dsl/helpers.rb +1 -1
  61. data/lib/eye/dsl/main.rb +4 -3
  62. data/lib/eye/dsl/opts.rb +31 -28
  63. data/lib/eye/dsl/process_opts.rb +13 -7
  64. data/lib/eye/dsl/pure_opts.rb +13 -9
  65. data/lib/eye/dsl/validation.rb +48 -35
  66. data/lib/eye/group.rb +23 -8
  67. data/lib/eye/group/chain.rb +6 -6
  68. data/lib/eye/loader.rb +3 -3
  69. data/lib/eye/local.rb +9 -4
  70. data/lib/eye/logger.rb +11 -4
  71. data/lib/eye/notify.rb +10 -6
  72. data/lib/eye/notify/jabber.rb +1 -1
  73. data/lib/eye/notify/mail.rb +2 -2
  74. data/lib/eye/notify/slack.rb +4 -3
  75. data/lib/eye/process.rb +2 -0
  76. data/lib/eye/process/children.rb +4 -4
  77. data/lib/eye/process/commands.rb +38 -39
  78. data/lib/eye/process/config.rb +22 -16
  79. data/lib/eye/process/controller.rb +5 -19
  80. data/lib/eye/process/data.rb +11 -9
  81. data/lib/eye/process/monitor.rb +86 -76
  82. data/lib/eye/process/notify.rb +10 -10
  83. data/lib/eye/process/scheduler.rb +36 -31
  84. data/lib/eye/process/states.rb +7 -5
  85. data/lib/eye/process/states_history.rb +9 -3
  86. data/lib/eye/process/system.rb +35 -20
  87. data/lib/eye/process/trigger.rb +1 -5
  88. data/lib/eye/process/watchers.rb +12 -9
  89. data/lib/eye/reason.rb +4 -1
  90. data/lib/eye/server.rb +3 -2
  91. data/lib/eye/system.rb +22 -15
  92. data/lib/eye/system_resources.rb +17 -8
  93. data/lib/eye/trigger.rb +18 -16
  94. data/lib/eye/trigger/check_dependency.rb +7 -4
  95. data/lib/eye/trigger/flapping.rb +24 -7
  96. data/lib/eye/trigger/starting_guard.rb +7 -6
  97. data/lib/eye/trigger/stop_children.rb +2 -2
  98. data/lib/eye/trigger/transition.rb +1 -1
  99. data/lib/eye/trigger/wait_dependency.rb +3 -2
  100. data/lib/eye/utils.rb +4 -3
  101. data/lib/eye/utils/alive_array.rb +9 -4
  102. data/lib/eye/utils/celluloid_chain.rb +12 -10
  103. data/lib/eye/utils/mini_active_support.rb +16 -16
  104. data/lib/eye/utils/pmap.rb +2 -0
  105. data/lib/eye/utils/tail.rb +2 -2
  106. metadata +39 -8
  107. data/lib/eye/utils/leak_19.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af465bb7737a6f1891bc3ab6ee5d9ebe9547530a
4
- data.tar.gz: 929efa8c2932925ef6aa2974377982a16e50494e
3
+ metadata.gz: 39b53d19c30acc0229dfdec07e5c135d8cc997fc
4
+ data.tar.gz: 82f8d45c31474a83b479376922899f39cfe9e232
5
5
  SHA512:
6
- metadata.gz: 9bb24f0bc0d47d2345aa0a1f708ad76486cfbe72363cdd6b6410133b912fc8cf47bddde0995422272c7688338ca986386ec3e8b4e9234b09d82adcc9dda155a6
7
- data.tar.gz: edf8b2a9874f4d58423d501bbe130e75109317be53a05d418118782f127ba5b4637d5109674c1621f21ceb5a04022cbaa6ba8864f2ab34a690c1b1b277798b44
6
+ metadata.gz: 30546ea03294ca6ad90a9f6cc6ed82aeacd386163759a08f6ab51051234835eef9591a73b934eb91f0701574e57b016ff7ca8437990a00f826bc7b5bdad3edde
7
+ data.tar.gz: 23e7c50c282eefa9a41420d07704007dc18fc1f1ddfa804f56a659263115db76031be59686dac00499da1eda51db03891b9fa34cc7f6e624f87cb01ce69fd782
@@ -0,0 +1,141 @@
1
+ AllCops:
2
+ Include:
3
+ - '**/*.eye'
4
+ Exclude:
5
+ - 'spec/**/*'
6
+ - 'lib/eye/utils/mini_active_support.rb'
7
+
8
+ Style/ClassAndModuleChildren:
9
+ EnforcedStyle: compact
10
+
11
+ Style/EmptyLinesAroundClassBody:
12
+ EnforcedStyle: empty_lines
13
+
14
+ Style/EmptyLinesAroundModuleBody:
15
+ EnforcedStyle: empty_lines
16
+ Exclude:
17
+ - 'lib/eye.rb'
18
+
19
+ Style/RegexpLiteral:
20
+ EnforcedStyle: percent_r
21
+ Exclude:
22
+ - 'examples/**/*'
23
+
24
+ Style/AccessModifierIndentation:
25
+ EnforcedStyle: outdent
26
+
27
+ Lint/EndAlignment:
28
+ AlignWith: variable
29
+
30
+ Style/IndentHash:
31
+ EnforcedStyle: consistent
32
+
33
+ Style/Lambda:
34
+ Exclude:
35
+ - 'examples/**/*'
36
+
37
+ Style/BlockDelimiters:
38
+ Exclude:
39
+ - 'examples/**/*'
40
+
41
+ Style/CaseIndentation:
42
+ IndentOneStep: true
43
+ IndentWhenRelativeTo: end
44
+
45
+ Style/HashSyntax:
46
+ Exclude:
47
+ - 'lib/eye/process/states.rb'
48
+
49
+ Style/RaiseArgs:
50
+ EnforcedStyle: exploded
51
+
52
+ Style/PercentLiteralDelimiters:
53
+ PreferredDelimiters:
54
+ '%w': '[]'
55
+ '%r': '[]'
56
+ '%': '{}'
57
+
58
+ Metrics/LineLength:
59
+ Max: 142
60
+
61
+ Metrics/PerceivedComplexity:
62
+ Max: 15
63
+ Exclude:
64
+ - 'lib/eye/cli/render.rb'
65
+
66
+ Metrics/BlockNesting:
67
+ Max: 3
68
+ Exclude:
69
+ - 'lib/eye/trigger/starting_guard.rb'
70
+
71
+ Metrics/MethodLength:
72
+ Max: 45
73
+
74
+ Metrics/CyclomaticComplexity:
75
+ Max: 19
76
+
77
+ Metrics/ClassLength:
78
+ Max: 200
79
+
80
+ Metrics/ModuleLength:
81
+ Max: 200
82
+ Exclude:
83
+ - 'lib/eye/process/commands.rb'
84
+
85
+ Metrics/AbcSize:
86
+ Max: 60
87
+
88
+ Style/GuardClause:
89
+ MinBodyLength: 10
90
+
91
+ Style/IfUnlessModifier:
92
+ MaxLineLength: 50
93
+
94
+ Lint/RescueException:
95
+ Exclude:
96
+ - 'lib/eye/checker/socket.rb'
97
+ - 'lib/eye/controller/load.rb'
98
+ - 'lib/eye/logger.rb'
99
+
100
+ Style/RedundantSelf:
101
+ Exclude:
102
+ - 'lib/eye/process/**/*' # self.pid is nicer
103
+
104
+ Style/SignalException:
105
+ EnforcedStyle: only_raise
106
+
107
+ Style/Documentation:
108
+ Enabled: false
109
+
110
+ Style/DoubleNegation:
111
+ Enabled: false
112
+
113
+ Lint/Eval:
114
+ Enabled: false
115
+
116
+ Lint/Void:
117
+ Exclude:
118
+ - Rakefile
119
+ - bin/loader_eye
120
+ - lib/eye/controller.rb
121
+
122
+ Lint/AssignmentInCondition:
123
+ Enabled: false
124
+
125
+ Style/AccessorMethodName:
126
+ Enabled: false
127
+
128
+ Style/SpecialGlobalVars:
129
+ Enabled: false
130
+
131
+ Style/RescueModifier:
132
+ Enabled: false
133
+
134
+ Lint/HandleExceptions:
135
+ Enabled: false
136
+
137
+ Lint/LiteralInInterpolation:
138
+ Exclude:
139
+ - 'lib/eye/notify/jabber.rb'
140
+ - 'lib/eye/notify/slack.rb'
141
+ - 'lib/eye/process/commands.rb'
@@ -2,6 +2,8 @@ language: ruby
2
2
  rvm:
3
3
  - "1.9.3"
4
4
  - "2.0.0"
5
- - "2.1"
6
- - "2.2.2"
7
- script: bundle exec rake split_test N=15
5
+ - "2.1.7"
6
+ - "2.2.3"
7
+ script:
8
+ - bundle exec rake N=16
9
+ - bundle exec rubocop
data/CHANGES.md CHANGED
@@ -1,3 +1,11 @@
1
+ 0.8
2
+ -------
3
+ * info, xinfo, oinfo, history now support -j flag, to output json
4
+ * leye: many fixes (--eyehome, --eyefile)
5
+ * add flapping reretry_in (#152)
6
+ * add check_identity of processes, avoid many bugs with wrong pid_files, or auto changed pids (#62)
7
+ * update Celluloid to 0.17
8
+
1
9
  0.7
2
10
  -------
3
11
  * add `stdall syslog`, example: https://github.com/kostya/eye/blob/master/examples/syslog.eye
@@ -13,7 +21,7 @@
13
21
  * some fixes in flapping
14
22
  * add proxy_url to http check
15
23
  * process with children, shows children history now
16
- * Update Celluloid to 0.16.0
24
+ * update Celluloid to 0.16
17
25
 
18
26
  0.6.4
19
27
  -----
data/README.md CHANGED
@@ -98,7 +98,7 @@ Eye.application 'test' do
98
98
  end
99
99
 
100
100
  # eventmachine process, daemonized with eye
101
- process :event_machine do |p|
101
+ process :event_machine do
102
102
  pid_file 'em.pid'
103
103
  start_command 'ruby em.rb'
104
104
  stdout 'em.log'
@@ -118,7 +118,6 @@ Eye.application 'test' do
118
118
  check :http, url: 'http://127.0.0.1:33233/hello', pattern: /World/,
119
119
  every: 5.seconds, times: [2, 3], timeout: 1.second
120
120
  end
121
-
122
121
  end
123
122
  ```
124
123
 
@@ -137,6 +136,10 @@ foreground load:
137
136
 
138
137
  If the eye daemon has already started and you call the `load` command, the config will be updated (into eye daemon). New objects(applications, groups, processes) will be added and monitored. Processes removed from the config will be removed (and stopped if the process has `stop_on_delete true`). Other objects will update their configs.
139
138
 
139
+ Two global configs loaded by default, if it exists (with the first eye load):
140
+
141
+ /etc/eye.conf
142
+ ~/.eyeconfig
140
143
 
141
144
  Process statuses:
142
145
 
data/Rakefile CHANGED
@@ -1,21 +1,21 @@
1
1
  #!/usr/bin/env rake
2
2
 
3
- require "bundler/gem_tasks"
3
+ require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
5
  require 'coveralls/rake/task'
6
6
 
7
7
  Coveralls::RakeTask.new
8
8
 
9
- task :default => :pspec
9
+ task :default => :split_test
10
10
 
11
- desc "run parallel tests"
11
+ desc 'run parallel tests'
12
12
  task :pspec do
13
13
  dirname = File.expand_path(File.dirname(__FILE__))
14
14
  cmd = "bundle exec parallel_rspec -n #{ENV['N'] || 10} --runtime-log '#{dirname}/spec/weights.txt' #{dirname}/spec"
15
15
  abort unless system(cmd)
16
16
  end
17
17
 
18
- desc "run parallel split tests"
18
+ desc 'run parallel split tests'
19
19
  task :split_test do
20
20
  dirname = File.expand_path(File.dirname(__FILE__))
21
21
  ENV['PARALLEL_SPLIT_TEST_PROCESSES'] = (ENV['N'] || 10).to_s
@@ -39,7 +39,7 @@ task :env do
39
39
  Eye::Process
40
40
  end
41
41
 
42
- desc "graph"
42
+ desc 'graph'
43
43
  task :graph => :env do
44
- StateMachine::Machine.draw("Eye::Process")
44
+ StateMachine::Machine.draw('Eye::Process')
45
45
  end
data/bin/leye CHANGED
@@ -6,7 +6,7 @@ require 'eye'
6
6
  # which looking for Eyefile
7
7
  # like foreman
8
8
 
9
- while true
9
+ loop do
10
10
  if ARGV[0] == '--eyefile'
11
11
  ARGV.shift
12
12
  ENV['EYE_FILE'] = File.expand_path(ARGV.shift.to_s)
@@ -18,13 +18,18 @@ while true
18
18
  end
19
19
  end
20
20
 
21
- unless Eye::Local.eyefile
22
- puts "\033[31mNot found Eyefile (in #{File.expand_path('.')})\033[0m"
21
+ if ENV['EYE_HOME'] && !File.directory?(File.expand_path(ENV['EYE_HOME']))
22
+ puts "\033[31mEYE_HOME is not directory (#{File.expand_path(ENV['EYE_HOME'])})\033[0m"
23
+ exit 1
24
+ end
25
+
26
+ unless Eye::Local.eyefile || ENV['EYE_HOME']
27
+ puts "\033[31mNot found Eyefile (in #{File.expand_path(ENV['EYE_HOME'] || '.')})\033[0m"
23
28
  exit 1
24
29
  end
25
30
 
26
31
  unless ENV.key?('EYE_HOME')
27
- Eye::Local.dir = File.join(File.dirname(Eye::Local.eyefile), '.eye')
32
+ ENV['EYE_HOME'] = File.dirname(Eye::Local.eyefile)
28
33
  end
29
34
 
30
35
  Eye::Local.local_runner = true
@@ -4,39 +4,38 @@ require 'eye/loader'
4
4
  require 'optparse'
5
5
  require 'eye'
6
6
 
7
- options = {:debug => false}
7
+ options = { debug: false }
8
8
 
9
9
  OptionParser.new do |opts|
10
- opts.on( '-h', '--help', 'Display this screen' ) do
10
+ opts.on('-h', '--help', 'Display this screen') do
11
11
  puts opts
12
12
  exit
13
13
  end
14
14
 
15
- opts.on( '-c', '--config CONFIG', 'load with config' ) do |config_path|
15
+ opts.on('-c', '--config CONFIG', 'load with config') do |config_path|
16
16
  options[:config] = config_path
17
17
  end
18
18
 
19
- opts.on( '-s', '--socket SOCKET', 'start listen on socket' ) do |socket_path|
19
+ opts.on('-s', '--socket SOCKET', 'start listen on socket') do |socket_path|
20
20
  options[:socket_path] = socket_path
21
21
  end
22
22
 
23
- opts.on( '-l', '--logger LOGGER', 'custom logger' ) do |logger|
23
+ opts.on('-l', '--logger LOGGER', 'custom logger') do |logger|
24
24
  options[:logger] = logger
25
25
  end
26
26
 
27
- opts.on( '-dr', '--dir DIR', 'Dir for local runner' ) do |dir|
27
+ opts.on('-d', '--dir DIR', 'Dir for local runner') do |dir|
28
28
  Eye::Local.dir = dir
29
29
  Eye::Local.local_runner = true
30
30
  end
31
31
 
32
- opts.on( '-st', '--stop_all', 'Stop all on exit' ) do |stop_all|
32
+ opts.on('-a', '--stop_all', 'Stop all on exit') do
33
33
  options[:stop_all] = true
34
34
  end
35
35
 
36
- opts.on( '-d', '--debug', 'debug info to logger' ) do
36
+ opts.on('-g', '--debug', 'debug info to logger') do
37
37
  options[:debug] = true
38
38
  end
39
-
40
39
  end.parse!
41
40
 
42
41
  Eye::Local.ensure_eye_dir
@@ -61,12 +60,12 @@ Eye::Control.set_proc_line
61
60
 
62
61
  server.async.run
63
62
 
64
- trap("USR1") { Eye::Logger.reopen }
65
- trap("USR2") { GC.start }
66
- trap("INT") { Eye::Logger.info("INT signal <#{$$}>"); exit }
67
- trap("QUIT") { Eye::Logger.info("QUIT signal <#{$$}>"); exit }
68
- trap("TERM") { Eye::Logger.info("TERM signal <#{$$}>"); exit }
63
+ trap('USR1') { Eye::Logger.reopen }
64
+ trap('USR2') { GC.start }
69
65
 
70
66
  at_exit { Eye::Control.command(:stop_all) } if options[:stop_all]
71
67
 
72
- sleep
68
+ begin
69
+ sleep
70
+ rescue Interrupt
71
+ end
@@ -0,0 +1,24 @@
1
+ # This example shows how to write custom checks:
2
+ # We check process procline every 1.second, and if it matches `haha`
3
+ # send TERM signal
4
+
5
+ class MyCheck < Eye::Checker::Custom
6
+
7
+ def get_value
8
+ Eye::SystemResources.args(@pid)
9
+ end
10
+
11
+ def good?(value)
12
+ !(value =~ /haha/)
13
+ end
14
+
15
+ end
16
+
17
+ Eye.app :bla do
18
+ process :a do
19
+ start_command "ruby -e 'sleep 10; $0 = %{HAHA}.downcase; sleep'"
20
+ daemonize true
21
+ pid_file '/tmp/1.pid'
22
+ check :my_check, every: 1.second, fires: -> { send_signal(:TERM) }
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ # send notify when many times crashed process, finally resolved
2
+
3
+ class Eye::Trigger::FixCrash < Eye::Trigger::Custom
4
+
5
+ param :times, Fixnum, nil, 1
6
+ param_default :to, :up
7
+
8
+ def check(_)
9
+ # process states here like this: [..., :starting, :down, :starting, :down, :starting, :up]
10
+ states = process.states_history.states
11
+
12
+ # states to compare with
13
+ compare = [:starting, :down] * times + [:starting, :up]
14
+
15
+ if states[-compare.length..-1] == compare
16
+ process.notify(:info, 'yahho, process up')
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ Eye.app :custom_trigger do
23
+ trigger :fix_crash
24
+
25
+ process :some do
26
+ pid_file '/tmp/custom_trigger_some.pid'
27
+ start_command "ruby -e 's = `cat /tmp/bla`; exit(1) unless s =~ /bla/; loop { sleep 1 } '"
28
+ daemonize!
29
+ end
30
+ end
@@ -1,6 +1,6 @@
1
1
  cwd = File.expand_path(File.join(File.dirname(__FILE__), %w[ ../ ../ ]))
2
2
 
3
- config_path = File.join(cwd, %w{ config dj.yml } )
3
+ config_path = File.join(cwd, %w[ config dj.yml ])
4
4
 
5
5
  workers_count = if File.exist?(config_path)
6
6
  YAML.load_file(config_path).try(:[], :workers) || 5
@@ -15,10 +15,10 @@ Eye.application 'delayed_job' do
15
15
  group 'dj' do
16
16
  chain grace: 5.seconds
17
17
 
18
- (1 .. workers_count).each do |i|
18
+ (1..workers_count).each do |i|
19
19
  process "dj-#{i}" do
20
20
  pid_file "tmp/pids/delayed_job.#{i}.pid"
21
- start_command "rake jobs:work"
21
+ start_command 'rake jobs:work'
22
22
  daemonize true
23
23
  stop_signals [:INT, 30.seconds, :TERM, 10.seconds, :KILL]
24
24
  stdall "log/dj-#{i}.log"
@@ -2,37 +2,36 @@
2
2
 
3
3
  Eye.app :dependency do
4
4
  process(:a) do
5
- start_command "sleep 100"
5
+ start_command 'sleep 100'
6
6
  daemonize true
7
- pid_file "/tmp/test_process_a.pid"
7
+ pid_file '/tmp/test_process_a.pid'
8
8
  end
9
9
 
10
10
  process(:b) do
11
- start_command "sleep 100"
11
+ start_command 'sleep 100'
12
12
  daemonize true
13
- pid_file "/tmp/test_process_b.pid"
13
+ pid_file '/tmp/test_process_b.pid'
14
14
  depend_on :a
15
15
  end
16
16
 
17
17
  process(:c) do
18
- start_command "sleep 100"
18
+ start_command 'sleep 100'
19
19
  daemonize true
20
- pid_file "/tmp/test_process_c.pid"
20
+ pid_file '/tmp/test_process_c.pid'
21
21
  depend_on :a
22
22
  end
23
23
 
24
24
  process(:d) do
25
- start_command "sleep 100"
25
+ start_command 'sleep 100'
26
26
  daemonize true
27
- pid_file "/tmp/test_process_d.pid"
27
+ pid_file '/tmp/test_process_d.pid'
28
28
  depend_on :b
29
29
  end
30
30
 
31
31
  process(:e) do
32
- start_command "sleep 100"
32
+ start_command 'sleep 100'
33
33
  daemonize true
34
- pid_file "/tmp/test_process_e.pid"
34
+ pid_file '/tmp/test_process_e.pid'
35
35
  depend_on [:d, :c]
36
36
  end
37
-
38
37
  end