bluepill 0.0.68 → 0.0.69

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -2
  3. data/bin/bluepill +19 -20
  4. data/bin/sample_forking_server +26 -13
  5. data/bluepill.gemspec +12 -18
  6. data/lib/bluepill.rb +12 -12
  7. data/lib/bluepill/application.rb +64 -71
  8. data/lib/bluepill/application/client.rb +0 -2
  9. data/lib/bluepill/application/server.rb +1 -3
  10. data/lib/bluepill/condition_watch.rb +12 -7
  11. data/lib/bluepill/controller.rb +37 -42
  12. data/lib/bluepill/dsl.rb +1 -2
  13. data/lib/bluepill/dsl/app_proxy.rb +3 -4
  14. data/lib/bluepill/dsl/process_factory.rb +40 -44
  15. data/lib/bluepill/dsl/process_proxy.rb +4 -5
  16. data/lib/bluepill/group.rb +15 -21
  17. data/lib/bluepill/logger.rb +4 -4
  18. data/lib/bluepill/process.rb +107 -109
  19. data/lib/bluepill/process_conditions.rb +1 -3
  20. data/lib/bluepill/process_conditions/always_true.rb +2 -3
  21. data/lib/bluepill/process_conditions/cpu_usage.rb +0 -1
  22. data/lib/bluepill/process_conditions/file_time.rb +5 -6
  23. data/lib/bluepill/process_conditions/http.rb +11 -9
  24. data/lib/bluepill/process_conditions/mem_usage.rb +6 -7
  25. data/lib/bluepill/process_conditions/process_condition.rb +4 -5
  26. data/lib/bluepill/process_conditions/running_time.rb +1 -2
  27. data/lib/bluepill/process_conditions/zombie_process.rb +1 -2
  28. data/lib/bluepill/process_journal.rb +18 -21
  29. data/lib/bluepill/process_statistics.rb +2 -4
  30. data/lib/bluepill/socket.rb +13 -16
  31. data/lib/bluepill/system.rb +57 -63
  32. data/lib/bluepill/trigger.rb +9 -11
  33. data/lib/bluepill/triggers/flapping.rb +12 -16
  34. data/lib/bluepill/util/rotational_array.rb +1 -2
  35. data/lib/bluepill/version.rb +1 -2
  36. metadata +4 -28
  37. data/.gitignore +0 -12
  38. data/.rspec +0 -1
  39. data/.travis.yml +0 -17
  40. data/Gemfile +0 -27
  41. data/Rakefile +0 -38
  42. data/examples/example.rb +0 -87
  43. data/examples/new_example.rb +0 -89
  44. data/examples/new_runit_example.rb +0 -29
  45. data/examples/runit_example.rb +0 -26
  46. data/local-bluepill +0 -130
  47. data/spec/lib/bluepill/application_spec.rb +0 -51
  48. data/spec/lib/bluepill/logger_spec.rb +0 -3
  49. data/spec/lib/bluepill/process_spec.rb +0 -135
  50. data/spec/lib/bluepill/process_statistics_spec.rb +0 -24
  51. data/spec/lib/bluepill/system_spec.rb +0 -45
  52. data/spec/spec_helper.rb +0 -26
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  module Bluepill
3
2
  class Trigger
4
3
  @implementations = {}
@@ -20,15 +19,15 @@ module Bluepill
20
19
  end
21
20
 
22
21
  def reset!
23
- self.cancel_all_events
22
+ cancel_all_events
24
23
  end
25
24
 
26
- def notify(transition)
27
- raise "Implement in subclass"
25
+ def notify(_transition)
26
+ fail 'Implement in subclass'
28
27
  end
29
28
 
30
29
  def dispatch!(event)
31
- self.process.dispatch!(event, self.class.name.split("::").last)
30
+ process.dispatch!(event, self.class.name.split('::').last)
32
31
  end
33
32
 
34
33
  def schedule_event(event, delay)
@@ -38,7 +37,7 @@ module Bluepill
38
37
  sleep delay.to_f
39
38
  trigger.dispatch!(event)
40
39
  trigger.mutex.synchronize do
41
- trigger.scheduled_events.delete_if { |_, thread| thread == Thread.current }
40
+ trigger.scheduled_events.delete_if { |_, t| t == Thread.current }
42
41
  end
43
42
  rescue StandardError => e
44
43
  trigger.logger.err(e)
@@ -46,15 +45,14 @@ module Bluepill
46
45
  end
47
46
  end
48
47
 
49
- self.scheduled_events.push([event, thread])
48
+ scheduled_events.push([event, thread])
50
49
  end
51
50
 
52
51
  def cancel_all_events
53
- self.logger.info "Canceling all scheduled events"
54
- self.mutex.synchronize do
55
- self.scheduled_events.each {|_, thread| thread.kill}
52
+ logger.info 'Canceling all scheduled events'
53
+ mutex.synchronize do
54
+ scheduled_events.each { |_, thread| thread.kill }
56
55
  end
57
56
  end
58
-
59
57
  end
60
58
  end
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  module Bluepill
3
2
  module Triggers
4
3
  class Flapping < Bluepill::Trigger
@@ -6,7 +5,7 @@ module Bluepill
6
5
 
7
6
  PARAMS = [:times, :within, :retry_in]
8
7
 
9
- attr_accessor *PARAMS
8
+ attr_accessor(*PARAMS)
10
9
  attr_reader :timeline
11
10
 
12
11
  def initialize(process, options = {})
@@ -21,10 +20,9 @@ module Bluepill
21
20
  end
22
21
 
23
22
  def notify(transition)
24
- if TRIGGER_STATES.include?(transition.to_name)
25
- self.timeline << Time.now.to_i
26
- self.check_flapping
27
- end
23
+ return unless TRIGGER_STATES.include?(transition.to_name)
24
+ timeline << Time.now.to_i
25
+ check_flapping
28
26
  end
29
27
 
30
28
  def reset!
@@ -34,22 +32,20 @@ module Bluepill
34
32
 
35
33
  def check_flapping
36
34
  # The process has not flapped if we haven't encountered enough incidents
37
- return unless (@timeline.compact.length == self.times)
35
+ return unless @timeline.compact.length == times
38
36
 
39
37
  # Check if the incident happend within the timeframe
40
- duration = (@timeline.last - @timeline.first) <= self.within
38
+ return unless @timeline.last - @timeline.first <= within
41
39
 
42
- if duration
43
- self.logger.info "Flapping detected: retrying in #{self.retry_in} seconds"
40
+ logger.info "Flapping detected: retrying in #{retry_in} seconds"
44
41
 
45
- self.schedule_event(:start, self.retry_in) unless self.retry_in == 0 # retry_in zero means "do not retry, ever"
46
- self.schedule_event(:unmonitor, 0)
42
+ schedule_event(:start, retry_in) unless retry_in.zero? # retry_in zero means "do not retry, ever"
43
+ schedule_event(:unmonitor, 0)
47
44
 
48
- @timeline.clear
45
+ @timeline.clear
49
46
 
50
- # This will prevent a transition from happening in the process state_machine
51
- throw :halt
52
- end
47
+ # This will prevent a transition from happening in the process state_machine
48
+ throw :halt
53
49
  end
54
50
  end
55
51
  end
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  module Bluepill
3
2
  module Util
4
3
  class RotationalArray < Array
@@ -11,7 +10,7 @@ module Bluepill
11
10
  def push(value)
12
11
  super(value)
13
12
 
14
- self.shift if self.length > @capacity
13
+ shift if length > @capacity
15
14
  self
16
15
  end
17
16
  alias_method :<<, :push
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  module Bluepill
3
- VERSION = "0.0.68"
2
+ VERSION = '0.0.69'
4
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bluepill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.68
4
+ version: 0.0.69
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arya Asemanfar
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-07-20 00:00:00.000000000 Z
13
+ date: 2014-11-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -99,27 +99,16 @@ executables:
99
99
  - bpsv
100
100
  - sample_forking_server
101
101
  extensions: []
102
- extra_rdoc_files:
103
- - LICENSE
104
- - README.md
102
+ extra_rdoc_files: []
105
103
  files:
106
- - ".gitignore"
107
- - ".rspec"
108
- - ".travis.yml"
109
104
  - CONTRIBUTING.md
110
105
  - DESIGN.md
111
- - Gemfile
112
106
  - LICENSE
113
107
  - README.md
114
- - Rakefile
115
108
  - bin/bluepill
116
109
  - bin/bpsv
117
110
  - bin/sample_forking_server
118
111
  - bluepill.gemspec
119
- - examples/example.rb
120
- - examples/new_example.rb
121
- - examples/new_runit_example.rb
122
- - examples/runit_example.rb
123
112
  - lib/bluepill.rb
124
113
  - lib/bluepill/application.rb
125
114
  - lib/bluepill/application/client.rb
@@ -150,13 +139,6 @@ files:
150
139
  - lib/bluepill/triggers/flapping.rb
151
140
  - lib/bluepill/util/rotational_array.rb
152
141
  - lib/bluepill/version.rb
153
- - local-bluepill
154
- - spec/lib/bluepill/application_spec.rb
155
- - spec/lib/bluepill/logger_spec.rb
156
- - spec/lib/bluepill/process_spec.rb
157
- - spec/lib/bluepill/process_statistics_spec.rb
158
- - spec/lib/bluepill/system_spec.rb
159
- - spec/spec_helper.rb
160
142
  homepage: http://github.com/bluepill-rb/bluepill
161
143
  licenses:
162
144
  - MIT
@@ -181,11 +163,5 @@ rubygems_version: 2.2.2
181
163
  signing_key:
182
164
  specification_version: 4
183
165
  summary: A process monitor written in Ruby with stability and minimalism in mind.
184
- test_files:
185
- - spec/lib/bluepill/application_spec.rb
186
- - spec/lib/bluepill/logger_spec.rb
187
- - spec/lib/bluepill/process_spec.rb
188
- - spec/lib/bluepill/process_statistics_spec.rb
189
- - spec/lib/bluepill/system_spec.rb
190
- - spec/spec_helper.rb
166
+ test_files: []
191
167
  has_rdoc:
data/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- *.sw?
2
- .DS_Store
3
- coverage/
4
- .yardoc/
5
- doc/
6
- pkg/
7
- *.gem
8
- .bundle/
9
- Gemfile.lock
10
- .idea
11
- bluepill.log
12
-
data/.rspec DELETED
@@ -1 +0,0 @@
1
- -r ./spec/spec_helper.rb -c -f progress
@@ -1,17 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.8.7
4
- - 1.9.2
5
- - 1.9.3
6
- - 2.0.0
7
- - 2.1
8
- - jruby-18mode
9
- - jruby-19mode
10
- - jruby-head
11
- - rbx-2
12
- - ruby-head
13
- matrix:
14
- allow_failures:
15
- - rvm: jruby-head
16
- - rvm: ruby-head
17
- fast_finish: true
data/Gemfile DELETED
@@ -1,27 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in bluepill.gemspec
4
- gemspec
5
-
6
- if RUBY_PLATFORM =~ /jruby|java/ || RUBY_VERSION =~ /1.8|1.9.2/
7
- gem 'activesupport', '~> 3.0'
8
- else
9
- gem 'activesupport', '~> 4.1'
10
- end
11
-
12
- gem 'rake'
13
-
14
- group :doc do
15
- # YARD helper for ruby 1.8 (already embedded into ruby 1.9)
16
- gem 'ripper', :platforms => :mri_18
17
- gem 'maruku', '>= 0.7'
18
- gem 'yard', '>= 0.8'
19
- end
20
-
21
- group :test do
22
- gem 'coveralls', :require => false, :platforms => [:mri_19, :mri_20, :mri_21]
23
- gem 'faker', '>= 1.2'
24
- gem 'rest-client', '~> 1.6.0', :platforms => [:jruby, :ruby_18]
25
- gem 'rspec', '>= 3'
26
- gem 'simplecov', '>= 0.4', :platforms => :ruby_19
27
- end
data/Rakefile DELETED
@@ -1,38 +0,0 @@
1
- begin
2
- require 'bundler'
3
- Bundler::GemHelper.install_tasks
4
- rescue LoadError
5
- $stderr.puts "Bundler not installed. You should install it with: gem install bundler"
6
- end
7
-
8
- $LOAD_PATH << File.expand_path('./lib', File.dirname(__FILE__))
9
- require 'bluepill/version'
10
-
11
- begin
12
- require 'rspec/core/rake_task'
13
-
14
- RSpec::Core::RakeTask.new
15
-
16
- if RUBY_VERSION >= '1.9'
17
- RSpec::Core::RakeTask.new(:cov) do |t|
18
- ENV['ENABLE_SIMPLECOV'] = '1'
19
- t.ruby_opts = '-w'
20
- t.rcov_opts = %q[-Ilib --exclude "spec/*,gems/*"]
21
- end
22
- end
23
- rescue LoadError
24
- $stderr.puts "RSpec not available. Install it with: gem install rspec-core rspec-expectations rr faker"
25
- end
26
-
27
- begin
28
- require 'yard'
29
- YARD::Rake::YardocTask.new do |yard|
30
- yard.options << "--title='bluepill #{Bluepill::VERSION}'"
31
-
32
- end
33
- rescue LoadError
34
- $stderr.puts "Please install YARD with: gem install yard"
35
- end
36
-
37
- task :test => :spec
38
- task :default => :spec
@@ -1,87 +0,0 @@
1
- require 'rubygems'
2
- require 'bluepill'
3
- require 'logger'
4
-
5
- ROOT_DIR = "/tmp/bp"
6
-
7
- # Watch with
8
- # watch -n0.2 'ps axu | egrep "(CPU|forking|bluepill|sleep)" | grep -v grep | sort'
9
- Bluepill.application(:sample_app) do |app|
10
- 0.times do |i|
11
- app.process("process_#{i}") do |process|
12
- process.pid_file = "#{ROOT_DIR}/pids/process_#{i}.pid"
13
-
14
- # Example of use of pid_command option to find memcached process
15
- # process.pid_command = "ps -ef | awk '/memcached$/{ print $2 }'"
16
-
17
- # I could not figure out a portable way to
18
- # specify the path to the sample forking server across the diff developer laptops.
19
- # Since this code is eval'ed we cannot reliably use __FILE__
20
- process.start_command = "/Users/rohith/work/bluepill/bin/sample_forking_server #{4242 + i}"
21
- process.stop_command = "kill -INT {{PID}}"
22
- process.daemonize = true
23
-
24
- process.start_grace_time = 1.seconds
25
- process.restart_grace_time = 7.seconds
26
- process.stop_grace_time = 7.seconds
27
-
28
- process.uid = "rohith"
29
- process.gid = "staff"
30
-
31
- # process.checks :cpu_usage, :every => 10, :below => 0.5, :times => [5, 5]
32
- process.checks :flapping, :times => 2, :within => 30.seconds, :retry_in => 7.seconds
33
-
34
- process.monitor_children do |child_process|
35
- # child_process.checks :cpu_usage,
36
- # :every => 10,
37
- # :below => 0.5,
38
- # :times => [5, 5]
39
-
40
- # child_process.checks :mem_usage,
41
- # :every => 3,
42
- # :below => 600.kilobytes,
43
- # :times => [3, 5],
44
- # :fires => [:stop]
45
-
46
- child_process.stop_command = "kill -QUIT {{PID}}"
47
- # child_process.checks :flapping, :times => 2, :within => 30.seconds, :retry_in => 7.seconds
48
- end
49
- end
50
- end
51
-
52
- 0.times do |i|
53
- app.process("group_process_#{i}") do |process|
54
- process.group = "group_1"
55
- process.pid_file = "/Users/rohith/ffs/tmp/pids/mongrel_#{i}.pid"
56
- process.start_command = "cd ~/ffs && mongrel_rails start -P #{process.pid_file} -p 3000 -d"
57
-
58
- process.start_grace_time = 10.seconds
59
-
60
- process.uid = "rohith"
61
- process.gid = "staff"
62
-
63
- # process.checks :always_true, :every => 10
64
- end
65
- end
66
-
67
- 1.times do |i|
68
- app.process("group_process_#{i}") do |process|
69
- process.auto_start = false
70
-
71
- process.uid = "rohith"
72
- process.gid = "wheel"
73
-
74
- process.stderr = "/tmp/err.log"
75
- process.stdout = "/tmp/err.log"
76
-
77
-
78
- process.group = "grouped"
79
- process.start_command = %Q{cd /tmp && ruby -e '$stderr.puts("hello stderr");$stdout.puts("hello stdout"); $stdout.flush; $stderr.flush; sleep 10'}
80
- process.daemonize = true
81
- process.pid_file = "/tmp/noperm/p_#{process.group}_#{i}.pid"
82
-
83
- # process.checks :always_true, :every => 5
84
- end
85
- end
86
- end
87
-
@@ -1,89 +0,0 @@
1
- require 'rubygems'
2
- require 'bluepill'
3
- require 'logger'
4
-
5
- # Note that this syntax supported from bluepill 0.0.50
6
-
7
- ROOT_DIR = "/tmp/bp"
8
-
9
- # Watch with
10
- # watch -n0.2 'ps axu | egrep "(CPU|forking|bluepill|sleep)" | grep -v grep | sort'
11
- Bluepill.application(:sample_app) do
12
- 0.times do |i|
13
- process("process_#{i}") do
14
- pid_file "#{ROOT_DIR}/pids/process_#{i}.pid"
15
-
16
- # Example of use of pid_command option to find memcached process
17
- # pid_command = "ps -ef | awk '/memcached$/{ print $2 }'"
18
-
19
- # I could not figure out a portable way to
20
- # specify the path to the sample forking server across the diff developer laptops.
21
- # Since this code is eval'ed we cannot reliably use __FILE__
22
- start_command "/Users/rohith/work/bluepill/bin/sample_forking_server #{4242 + i}"
23
- stop_command "kill -INT {{PID}}"
24
- daemonize!
25
-
26
- start_grace_time 1.seconds
27
- restart_grace_time 7.seconds
28
- stop_grace_time 7.seconds
29
-
30
- uid "rohith"
31
- gid "staff"
32
-
33
- # checks :cpu_usage, :every => 10, :below => 0.5, :times => [5, 5]
34
- checks :flapping, :times => 2, :within => 30.seconds, :retry_in => 7.seconds
35
-
36
- monitor_children do
37
- # checks :cpu_usage,
38
- # :every => 10,
39
- # :below => 0.5,
40
- # :times => [5, 5]
41
-
42
- # checks :mem_usage,
43
- # :every => 3,
44
- # :below => 600.kilobytes,
45
- # :times => [3, 5],
46
- # :fires => [:stop]
47
-
48
- stop_command "kill -QUIT {{PID}}"
49
- # checks :flapping, :times => 2, :within => 30.seconds, :retry_in => 7.seconds
50
- end
51
- end
52
- end
53
-
54
- 0.times do |i|
55
- process("group_process_#{i}") do
56
- group "group_1"
57
- pid_file "/Users/rohith/ffs/tmp/pids/mongrel_#{i}.pid"
58
- start_command "cd ~/ffs && mongrel_rails start -P #{pid_file} -p 3000 -d"
59
-
60
- start_grace_time 10.seconds
61
-
62
- uid "rohith"
63
- gid "staff"
64
-
65
- # checks :always_true, :every => 10
66
- end
67
- end
68
-
69
- 1.times do |i|
70
- process("group_process_#{i}") do
71
- auto_start false
72
-
73
- uid "rohith"
74
- gid "wheel"
75
-
76
- stderr "/tmp/err.log"
77
- stdout "/tmp/err.log"
78
-
79
-
80
- group "grouped"
81
- start_command %Q{cd /tmp && ruby -e '$stderr.puts("hello stderr");$stdout.puts("hello stdout"); $stdout.flush; $stderr.flush; sleep 10'}
82
- daemonize!
83
- pid_file "/tmp/noperm/p_#{group}_#{i}.pid"
84
-
85
- # checks :always_true, :every => 5
86
- end
87
- end
88
- end
89
-