eye 0.8.pre2 → 0.8.rc

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +141 -0
  3. data/.travis.yml +5 -3
  4. data/README.md +1 -2
  5. data/Rakefile +5 -5
  6. data/bin/leye +9 -4
  7. data/bin/loader_eye +14 -15
  8. data/examples/custom_check.eye +24 -0
  9. data/examples/custom_trigger.eye +3 -1
  10. data/examples/delayed_job.eye +3 -3
  11. data/examples/dependency.eye +10 -11
  12. data/examples/leye_example/Eyefile +10 -0
  13. data/examples/notify.eye +3 -4
  14. data/examples/plugin/main.eye +5 -5
  15. data/examples/plugin/plugin.rb +10 -2
  16. data/examples/process_thin.rb +8 -8
  17. data/examples/processes/em.rb +18 -12
  18. data/examples/processes/forking.rb +5 -5
  19. data/examples/processes/sample.rb +46 -44
  20. data/examples/puma.eye +9 -8
  21. data/examples/rbenv.eye +5 -5
  22. data/examples/sidekiq.eye +3 -3
  23. data/examples/stress_test.eye +4 -4
  24. data/examples/syslog.eye +1 -1
  25. data/examples/test.eye +1 -2
  26. data/examples/thin-farm.eye +7 -8
  27. data/examples/triggers.eye +13 -15
  28. data/examples/unicorn.eye +12 -13
  29. data/eye.gemspec +14 -12
  30. data/lib/eye.rb +2 -3
  31. data/lib/eye/application.rb +5 -6
  32. data/lib/eye/checker.rb +36 -19
  33. data/lib/eye/checker/children_count.rb +1 -1
  34. data/lib/eye/checker/file_ctime.rb +1 -1
  35. data/lib/eye/checker/http.rb +13 -15
  36. data/lib/eye/checker/nop.rb +1 -0
  37. data/lib/eye/checker/socket.rb +60 -63
  38. data/lib/eye/checker/ssl_socket.rb +5 -5
  39. data/lib/eye/child_process.rb +6 -4
  40. data/lib/eye/cli.rb +50 -41
  41. data/lib/eye/cli/commands.rb +4 -5
  42. data/lib/eye/cli/render.rb +61 -41
  43. data/lib/eye/cli/server.rb +19 -16
  44. data/lib/eye/client.rb +1 -0
  45. data/lib/eye/config.rb +19 -19
  46. data/lib/eye/controller.rb +2 -3
  47. data/lib/eye/controller/commands.rb +1 -1
  48. data/lib/eye/controller/helpers.rb +2 -2
  49. data/lib/eye/controller/load.rb +18 -12
  50. data/lib/eye/controller/options.rb +1 -5
  51. data/lib/eye/controller/send_command.rb +21 -23
  52. data/lib/eye/controller/status.rb +17 -15
  53. data/lib/eye/dsl.rb +3 -0
  54. data/lib/eye/dsl/application_opts.rb +4 -3
  55. data/lib/eye/dsl/chain.rb +2 -2
  56. data/lib/eye/dsl/child_process_opts.rb +3 -3
  57. data/lib/eye/dsl/config_opts.rb +7 -7
  58. data/lib/eye/dsl/group_opts.rb +3 -3
  59. data/lib/eye/dsl/helpers.rb +1 -1
  60. data/lib/eye/dsl/main.rb +4 -3
  61. data/lib/eye/dsl/opts.rb +31 -28
  62. data/lib/eye/dsl/process_opts.rb +13 -7
  63. data/lib/eye/dsl/pure_opts.rb +13 -9
  64. data/lib/eye/dsl/validation.rb +48 -35
  65. data/lib/eye/group.rb +20 -6
  66. data/lib/eye/group/chain.rb +6 -6
  67. data/lib/eye/loader.rb +1 -1
  68. data/lib/eye/local.rb +9 -4
  69. data/lib/eye/logger.rb +11 -4
  70. data/lib/eye/notify.rb +10 -6
  71. data/lib/eye/notify/jabber.rb +1 -1
  72. data/lib/eye/notify/mail.rb +2 -2
  73. data/lib/eye/notify/slack.rb +4 -3
  74. data/lib/eye/process.rb +2 -0
  75. data/lib/eye/process/children.rb +4 -4
  76. data/lib/eye/process/commands.rb +28 -31
  77. data/lib/eye/process/config.rb +21 -19
  78. data/lib/eye/process/data.rb +11 -9
  79. data/lib/eye/process/monitor.rb +30 -29
  80. data/lib/eye/process/notify.rb +10 -10
  81. data/lib/eye/process/scheduler.rb +36 -31
  82. data/lib/eye/process/states.rb +5 -4
  83. data/lib/eye/process/states_history.rb +9 -3
  84. data/lib/eye/process/system.rb +5 -4
  85. data/lib/eye/process/trigger.rb +1 -5
  86. data/lib/eye/process/watchers.rb +6 -9
  87. data/lib/eye/reason.rb +4 -1
  88. data/lib/eye/server.rb +2 -1
  89. data/lib/eye/system.rb +16 -13
  90. data/lib/eye/system_resources.rb +13 -8
  91. data/lib/eye/trigger.rb +18 -16
  92. data/lib/eye/trigger/check_dependency.rb +7 -4
  93. data/lib/eye/trigger/flapping.rb +24 -7
  94. data/lib/eye/trigger/starting_guard.rb +7 -6
  95. data/lib/eye/trigger/stop_children.rb +2 -2
  96. data/lib/eye/trigger/transition.rb +1 -1
  97. data/lib/eye/trigger/wait_dependency.rb +3 -2
  98. data/lib/eye/utils.rb +4 -3
  99. data/lib/eye/utils/alive_array.rb +9 -4
  100. data/lib/eye/utils/celluloid_chain.rb +12 -10
  101. data/lib/eye/utils/mini_active_support.rb +16 -16
  102. data/lib/eye/utils/pmap.rb +2 -0
  103. data/lib/eye/utils/tail.rb +2 -2
  104. metadata +34 -4
  105. data/lib/eye/utils/leak_19.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9b7bd7917fbb58bb490f4f436c4c61736127eb4
4
- data.tar.gz: 240e3c98f60432b0f43c2895e52782adf99d750f
3
+ metadata.gz: c82745fa85f30eae42687f61dde6724bd5ed1bcd
4
+ data.tar.gz: cf600cf41608a73e8512cc0dedc885c63509a2c8
5
5
  SHA512:
6
- metadata.gz: f809b87646a8a2e3092df493af89fdc26155f88d01c6709df3a5efe50dda2c3bdbef0a99306bb54d86faaf387e9727e8341f2bbdb3578e15d8a14c3a28f8536a
7
- data.tar.gz: 4af77bcf0306370cabaf0bbbbc0a635460e658177ecee12d2e6381a15decac7dabd52847bbe603912b9288f42a9e6a396cd746527ddc2c7190c20c0515132bb7
6
+ metadata.gz: b6e01c90b2c7b1d3eef6cc6b7eda39aa29a6601b994b9c33897a81e2cb41a11356e00389ec1252aeb1f2295d3f950250a6216ab50abe768cd9a469cf7f24eb6e
7
+ data.tar.gz: 0e07121c4ef3fe34eac78a2b82b736ff298dcb7912df26506838ccc14aa0c5f020a9aa9a275adecbd6109181a6941704d4ac0ef007c960a9682512b6ad3ea7a2
@@ -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 N=15
5
+ - "2.1.7"
6
+ - "2.2.3"
7
+ script:
8
+ - bundle exec rake N=16
9
+ - bundle exec rubocop
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
 
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
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
 
@@ -8,14 +8,14 @@ Coveralls::RakeTask.new
8
8
 
9
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
@@ -1,6 +1,7 @@
1
1
  # send notify when many times crashed process, finally resolved
2
2
 
3
3
  class Eye::Trigger::FixCrash < Eye::Trigger::Custom
4
+
4
5
  param :times, Fixnum, nil, 1
5
6
  param_default :to, :up
6
7
 
@@ -12,9 +13,10 @@ class Eye::Trigger::FixCrash < Eye::Trigger::Custom
12
13
  compare = [:starting, :down] * times + [:starting, :up]
13
14
 
14
15
  if states[-compare.length..-1] == compare
15
- process.notify(:info, "yahho, process up")
16
+ process.notify(:info, 'yahho, process up')
16
17
  end
17
18
  end
19
+
18
20
  end
19
21
 
20
22
  Eye.app :custom_trigger do
@@ -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
@@ -0,0 +1,10 @@
1
+
2
+ Eye.application :test_leye do
3
+ 5.times do |i|
4
+ process "test-#{i}" do
5
+ start_command "sleep 200"
6
+ daemonize!
7
+ pid_file "#{i}.pid"
8
+ end
9
+ end
10
+ end
@@ -1,7 +1,7 @@
1
1
  # Notify example
2
2
 
3
3
  Eye.config do
4
- mail :host => "mx.some.host", :port => 25, :domain => "some.host"
4
+ mail host: 'mx.some.host', port: 25, domain: 'some.host'
5
5
  contact :errors, :mail, 'error@some.host'
6
6
  contact :dev, :mail, 'dev@some.host'
7
7
  end
@@ -11,9 +11,8 @@ Eye.application :some do
11
11
 
12
12
  process :some_process do
13
13
  notify :dev, :info
14
- pid_file "1.pid"
14
+ pid_file '1.pid'
15
15
 
16
- #...
16
+ # ...
17
17
  end
18
-
19
18
  end