wijet-bluepill 0.0.33

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,59 @@
1
+ module Bluepill
2
+ module Triggers
3
+ class Flapping < Bluepill::Trigger
4
+ TRIGGER_STATES = [:starting, :restarting]
5
+
6
+ PARAMS = [:times, :within, :retry_in]
7
+
8
+ attr_accessor *PARAMS
9
+ attr_reader :timeline
10
+
11
+ def initialize(process, options = {})
12
+ options.reverse_merge!(:times => 5, :within => 1, :retry_in => 5)
13
+
14
+ options.each_pair do |name, val|
15
+ instance_variable_set("@#{name}", val) if PARAMS.include?(name)
16
+ end
17
+
18
+ @timeline = Util::RotationalArray.new(@times)
19
+ super
20
+ end
21
+
22
+ def notify(transition)
23
+ if TRIGGER_STATES.include?(transition.to_name)
24
+ self.timeline << Time.now.to_i
25
+ self.check_flapping
26
+ end
27
+ end
28
+
29
+ def reset!
30
+ @timeline.clear
31
+ super
32
+ end
33
+
34
+ def check_flapping
35
+ num_occurances = (@timeline.nitems == self.times)
36
+
37
+ # The process has not flapped if we haven't encountered enough incidents
38
+ return unless num_occurances
39
+
40
+ # Check if the incident happend within the timeframe
41
+ duration = (@timeline.last - @timeline.first) <= self.within
42
+
43
+ if duration
44
+ self.logger.info "Flapping detected: retrying in #{self.retry_in} seconds"
45
+
46
+ self.schedule_event(:start, self.retry_in)
47
+
48
+ # this happens in the process' thread so we don't have to worry about concurrency issues with this event
49
+ self.dispatch!(:unmonitor)
50
+
51
+ @timeline.clear
52
+
53
+ # This will prevent a transition from happening in the process state_machine
54
+ throw :halt
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,66 @@
1
+ module Bluepill
2
+ module Util
3
+ class RotationalArray < Array
4
+ def initialize(size)
5
+ super(size)
6
+
7
+ @capacity = size
8
+ @counter = 0
9
+ end
10
+
11
+ def push(value)
12
+ idx = rotational_idx(@counter)
13
+ self[idx] = value
14
+
15
+ @counter += 1
16
+ self
17
+ end
18
+
19
+ alias_method :<<, :push
20
+
21
+ def pop
22
+ raise "Cannot call pop on a rotational array"
23
+ end
24
+
25
+ def shift
26
+ raise "Cannot call shift on a rotational array"
27
+ end
28
+
29
+ def unshift
30
+ raise "Cannot call unshift on a rotational array"
31
+ end
32
+
33
+ def last
34
+ return if @counter.zero?
35
+
36
+ self[rotational_idx(@counter - 1)]
37
+ end
38
+
39
+ def first
40
+ return if @counter.zero?
41
+ return self[0] if @counter <= @capacity
42
+
43
+ self[rotational_idx(@counter)]
44
+ end
45
+
46
+ def clear
47
+ @counter = 0
48
+ super
49
+ end
50
+
51
+ def each(&block)
52
+ times = @counter >= @capacity ? @capacity : @counter
53
+ start = @counter >= @capacity ? rotational_idx(@counter) : 0
54
+ times.times do |i|
55
+ block.call(self[rotational_idx(start + i)])
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def rotational_idx(idx)
62
+ idx % @capacity
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module Bluepill
2
+ VERSION = "0.0.32"
3
+ end
@@ -0,0 +1,81 @@
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
+ # I could not figure out a portable way to
15
+ # specify the path to the sample forking server across the diff developer laptops.
16
+ # Since this code is eval'ed we cannot reliably use __FILE__
17
+ process.start_command = "/Users/rohith/work/bluepill/bin/sample_forking_server #{4242 + i}"
18
+ process.stop_command = "kill -INT {{PID}}"
19
+ process.daemonize = true
20
+
21
+ process.start_grace_time = 1.seconds
22
+ process.restart_grace_time = 7.seconds
23
+ process.stop_grace_time = 7.seconds
24
+
25
+ process.uid = "rohith"
26
+ process.gid = "staff"
27
+
28
+ # process.checks :cpu_usage, :every => 10, :below => 0.5, :times => [5, 5]
29
+ process.checks :flapping, :times => 2, :within => 30.seconds, :retry_in => 7.seconds
30
+
31
+ process.monitor_children do |child_process|
32
+ # child_process.checks :cpu_usage,
33
+ # :every => 10,
34
+ # :below => 0.5,
35
+ # :times => [5, 5]
36
+
37
+ # child_process.checks :mem_usage,
38
+ # :every => 3,
39
+ # :below => 600.kilobytes,
40
+ # :times => [3, 5],
41
+ # :fires => [:stop]
42
+
43
+ child_process.stop_command = "kill -QUIT {{PID}}"
44
+ # child_process.checks :flapping, :times => 2, :within => 30.seconds, :retry_in => 7.seconds
45
+ end
46
+ end
47
+ end
48
+
49
+ 0.times do |i|
50
+ app.process("group_process_#{i}") do |process|
51
+ process.group = "group_1"
52
+ process.pid_file = "/Users/rohith/ffs/tmp/pids/mongrel_#{i}.pid"
53
+ process.start_command = "cd ~/ffs && mongrel_rails start -P #{process.pid_file} -p 3000 -d"
54
+
55
+ process.start_grace_time = 10.seconds
56
+
57
+ process.uid = "rohith"
58
+ process.gid = "staff"
59
+
60
+ # process.checks :always_true, :every => 10
61
+ end
62
+ end
63
+
64
+ 1.times do |i|
65
+ app.process("group_process_#{i}") do |process|
66
+ process.uid = "rohith"
67
+ process.gid = "wheel"
68
+
69
+ process.stderr = "/tmp/err.log"
70
+ process.stdout = "/tmp/err.log"
71
+
72
+
73
+ process.group = "grouped"
74
+ process.start_command = %Q{cd /tmp && ruby -e '$stderr.puts("hello stderr");$stdout.puts("hello stdout"); $stdout.flush; $stderr.flush; sleep 10'}
75
+ process.daemonize = true
76
+ process.pid_file = "/tmp/noperm/p_#{process.group}_#{i}.pid"
77
+
78
+ # process.checks :always_true, :every => 5
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,83 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{wijet-bluepill}
8
+ s.version = "0.0.33"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Arya Asemanfar", "Gary Tsang", "Rohith Ravi"]
12
+ s.date = %q{2010-02-04}
13
+ s.default_executable = %q{bluepill}
14
+ s.description = %q{Bluepill keeps your daemons up while taking up as little resources as possible. After all you probably want the resources of your server to be used by whatever daemons you are running rather than the thing that's supposed to make sure they are brought back up, should they die or misbehave.}
15
+ s.email = %q{entombedvirus@gmail.com}
16
+ s.executables = ["bluepill"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".gitignore",
23
+ "DESIGN.md",
24
+ "LICENSE",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/bluepill",
29
+ "bin/bpsv",
30
+ "lib/bluepill.rb",
31
+ "lib/bluepill/application.rb",
32
+ "lib/bluepill/application/client.rb",
33
+ "lib/bluepill/application/server.rb",
34
+ "lib/bluepill/condition_watch.rb",
35
+ "lib/bluepill/controller.rb",
36
+ "lib/bluepill/dsl.rb",
37
+ "lib/bluepill/group.rb",
38
+ "lib/bluepill/logger.rb",
39
+ "lib/bluepill/process.rb",
40
+ "lib/bluepill/process_conditions.rb",
41
+ "lib/bluepill/process_conditions/always_true.rb",
42
+ "lib/bluepill/process_conditions/cpu_usage.rb",
43
+ "lib/bluepill/process_conditions/mem_usage.rb",
44
+ "lib/bluepill/process_conditions/process_condition.rb",
45
+ "lib/bluepill/process_statistics.rb",
46
+ "lib/bluepill/socket.rb",
47
+ "lib/bluepill/system.rb",
48
+ "lib/bluepill/trigger.rb",
49
+ "lib/bluepill/triggers/flapping.rb",
50
+ "lib/bluepill/util/rotational_array.rb",
51
+ "lib/bluepill/version.rb",
52
+ "lib/example.rb",
53
+ "wijet-bluepill.gemspec"
54
+ ]
55
+ s.homepage = %q{http://github.com/wijet/bluepill}
56
+ s.rdoc_options = ["--charset=UTF-8"]
57
+ s.require_paths = ["lib"]
58
+ s.rubygems_version = %q{1.3.5}
59
+ s.summary = %q{A process monitor written in Ruby with stability and minimalism in mind.}
60
+
61
+ if s.respond_to? :specification_version then
62
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
63
+ s.specification_version = 3
64
+
65
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
66
+ s.add_runtime_dependency(%q<daemons>, [">= 1.0.9"])
67
+ s.add_runtime_dependency(%q<blankslate>, [">= 2.1.2.2"])
68
+ s.add_runtime_dependency(%q<state_machine>, [">= 0.8.0"])
69
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
70
+ else
71
+ s.add_dependency(%q<daemons>, [">= 1.0.9"])
72
+ s.add_dependency(%q<blankslate>, [">= 2.1.2.2"])
73
+ s.add_dependency(%q<state_machine>, [">= 0.8.0"])
74
+ s.add_dependency(%q<activesupport>, [">= 2.3.4"])
75
+ end
76
+ else
77
+ s.add_dependency(%q<daemons>, [">= 1.0.9"])
78
+ s.add_dependency(%q<blankslate>, [">= 2.1.2.2"])
79
+ s.add_dependency(%q<state_machine>, [">= 0.8.0"])
80
+ s.add_dependency(%q<activesupport>, [">= 2.3.4"])
81
+ end
82
+ end
83
+
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wijet-bluepill
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.33
5
+ platform: ruby
6
+ authors:
7
+ - Arya Asemanfar
8
+ - Gary Tsang
9
+ - Rohith Ravi
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2010-02-04 00:00:00 +01:00
15
+ default_executable: bluepill
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: daemons
19
+ type: :runtime
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 1.0.9
26
+ version:
27
+ - !ruby/object:Gem::Dependency
28
+ name: blankslate
29
+ type: :runtime
30
+ version_requirement:
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 2.1.2.2
36
+ version:
37
+ - !ruby/object:Gem::Dependency
38
+ name: state_machine
39
+ type: :runtime
40
+ version_requirement:
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.0
46
+ version:
47
+ - !ruby/object:Gem::Dependency
48
+ name: activesupport
49
+ type: :runtime
50
+ version_requirement:
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.3.4
56
+ version:
57
+ description: Bluepill keeps your daemons up while taking up as little resources as possible. After all you probably want the resources of your server to be used by whatever daemons you are running rather than the thing that's supposed to make sure they are brought back up, should they die or misbehave.
58
+ email: entombedvirus@gmail.com
59
+ executables:
60
+ - bluepill
61
+ extensions: []
62
+
63
+ extra_rdoc_files:
64
+ - LICENSE
65
+ - README.md
66
+ files:
67
+ - .gitignore
68
+ - DESIGN.md
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - VERSION
73
+ - bin/bluepill
74
+ - bin/bpsv
75
+ - lib/bluepill.rb
76
+ - lib/bluepill/application.rb
77
+ - lib/bluepill/application/client.rb
78
+ - lib/bluepill/application/server.rb
79
+ - lib/bluepill/condition_watch.rb
80
+ - lib/bluepill/controller.rb
81
+ - lib/bluepill/dsl.rb
82
+ - lib/bluepill/group.rb
83
+ - lib/bluepill/logger.rb
84
+ - lib/bluepill/process.rb
85
+ - lib/bluepill/process_conditions.rb
86
+ - lib/bluepill/process_conditions/always_true.rb
87
+ - lib/bluepill/process_conditions/cpu_usage.rb
88
+ - lib/bluepill/process_conditions/mem_usage.rb
89
+ - lib/bluepill/process_conditions/process_condition.rb
90
+ - lib/bluepill/process_statistics.rb
91
+ - lib/bluepill/socket.rb
92
+ - lib/bluepill/system.rb
93
+ - lib/bluepill/trigger.rb
94
+ - lib/bluepill/triggers/flapping.rb
95
+ - lib/bluepill/util/rotational_array.rb
96
+ - lib/bluepill/version.rb
97
+ - lib/example.rb
98
+ - wijet-bluepill.gemspec
99
+ has_rdoc: true
100
+ homepage: http://github.com/wijet/bluepill
101
+ licenses: []
102
+
103
+ post_install_message:
104
+ rdoc_options:
105
+ - --charset=UTF-8
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: "0"
113
+ version:
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: "0"
119
+ version:
120
+ requirements: []
121
+
122
+ rubyforge_project:
123
+ rubygems_version: 1.3.5
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: A process monitor written in Ruby with stability and minimalism in mind.
127
+ test_files: []
128
+