bluepill 0.0.49 → 0.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/examples/example.rb +6 -0
- data/examples/new_example.rb +89 -0
- data/examples/new_runit_example.rb +29 -0
- data/lib/bluepill/dsl.rb +5 -1
- data/lib/bluepill/dsl/app_proxy.rb +2 -2
- data/lib/bluepill/dsl/process_proxy.rb +9 -1
- data/lib/bluepill/process.rb +14 -3
- data/lib/bluepill/version.rb +1 -1
- metadata +6 -4
data/examples/example.rb
CHANGED
|
@@ -11,6 +11,9 @@ Bluepill.application(:sample_app) do |app|
|
|
|
11
11
|
app.process("process_#{i}") do |process|
|
|
12
12
|
process.pid_file = "#{ROOT_DIR}/pids/process_#{i}.pid"
|
|
13
13
|
|
|
14
|
+
# Example of use of pid_command option to find memcached process
|
|
15
|
+
# process.pid_command = "ps -ef | awk '/memcached$/{ print $2 }'"
|
|
16
|
+
|
|
14
17
|
# I could not figure out a portable way to
|
|
15
18
|
# specify the path to the sample forking server across the diff developer laptops.
|
|
16
19
|
# Since this code is eval'ed we cannot reliably use __FILE__
|
|
@@ -63,6 +66,8 @@ Bluepill.application(:sample_app) do |app|
|
|
|
63
66
|
|
|
64
67
|
1.times do |i|
|
|
65
68
|
app.process("group_process_#{i}") do |process|
|
|
69
|
+
process.auto_start = false
|
|
70
|
+
|
|
66
71
|
process.uid = "rohith"
|
|
67
72
|
process.gid = "wheel"
|
|
68
73
|
|
|
@@ -79,3 +84,4 @@ Bluepill.application(:sample_app) do |app|
|
|
|
79
84
|
end
|
|
80
85
|
end
|
|
81
86
|
end
|
|
87
|
+
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#! /usr/bin/env ruby
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'bluepill'
|
|
4
|
+
require 'logger'
|
|
5
|
+
|
|
6
|
+
# ATTENTION:
|
|
7
|
+
# You must declare only one application per config when foreground mode specified
|
|
8
|
+
#
|
|
9
|
+
# http://github.com/Undev/runit-man used as example of monitored application.
|
|
10
|
+
|
|
11
|
+
# Note that this syntax supported from bluepill 0.0.50
|
|
12
|
+
|
|
13
|
+
Bluepill.application(:runit_man, :foreground => true) do
|
|
14
|
+
process("runit-man") do
|
|
15
|
+
pid_file "/etc/service/runit-man/supervise/pid"
|
|
16
|
+
|
|
17
|
+
start_command "/usr/bin/sv start runit-man"
|
|
18
|
+
stop_command "/usr/bin/sv stop runit-man"
|
|
19
|
+
restart_command "/usr/bin/sv restart runit-man"
|
|
20
|
+
|
|
21
|
+
start_grace_time 1.seconds
|
|
22
|
+
restart_grace_time 7.seconds
|
|
23
|
+
stop_grace_time 7.seconds
|
|
24
|
+
|
|
25
|
+
checks :http, :within => 30.seconds, :retry_in => 7.seconds, :every => 30.seconds,
|
|
26
|
+
:url => 'http://localhost:4567/', :kind => :success, :pattern => /html/, :timeout => 3.seconds
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
data/lib/bluepill/dsl.rb
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
module Bluepill
|
|
3
3
|
def self.application(app_name, options = {}, &block)
|
|
4
4
|
app_proxy = AppProxy.new(app_name, options)
|
|
5
|
-
|
|
5
|
+
if block.arity == 0
|
|
6
|
+
app_proxy.instance_eval &block
|
|
7
|
+
else
|
|
8
|
+
app_proxy.instance_exec(app_proxy, &block)
|
|
9
|
+
end
|
|
6
10
|
app_proxy.app.load
|
|
7
11
|
end
|
|
8
12
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
2
|
module Bluepill
|
|
3
3
|
class AppProxy
|
|
4
|
-
APP_ATTRIBUTES = [:working_dir, :uid, :gid, :environment]
|
|
4
|
+
APP_ATTRIBUTES = [:working_dir, :uid, :gid, :environment, :auto_start ]
|
|
5
5
|
|
|
6
6
|
attr_accessor *APP_ATTRIBUTES
|
|
7
7
|
attr_reader :app
|
|
@@ -12,7 +12,7 @@ module Bluepill
|
|
|
12
12
|
|
|
13
13
|
def process(process_name, &process_block)
|
|
14
14
|
attributes = {}
|
|
15
|
-
APP_ATTRIBUTES.each {|a| attributes[a] = self.send(a) }
|
|
15
|
+
APP_ATTRIBUTES.each { |a| attributes[a] = self.send(a) }
|
|
16
16
|
|
|
17
17
|
process_factory = ProcessFactory.new(attributes, process_block)
|
|
18
18
|
|
|
@@ -7,12 +7,20 @@ module Bluepill
|
|
|
7
7
|
@attributes = attributes
|
|
8
8
|
@watches = {}
|
|
9
9
|
|
|
10
|
-
process_block.
|
|
10
|
+
if process_block.arity == 0
|
|
11
|
+
instance_eval &process_block
|
|
12
|
+
else
|
|
13
|
+
instance_exec(self, &process_block)
|
|
14
|
+
end
|
|
11
15
|
end
|
|
12
16
|
|
|
13
17
|
def method_missing(name, *args)
|
|
14
18
|
if args.size == 1 && name.to_s =~ /^(.*)=$/
|
|
15
19
|
@attributes[$1.to_sym] = args.first
|
|
20
|
+
elsif args.size == 1
|
|
21
|
+
@attributes[name.to_sym] = args.first
|
|
22
|
+
elsif args.size == 0 && name.to_s =~ /^(.*)!$/
|
|
23
|
+
@attributes[$1.to_sym] = true
|
|
16
24
|
elsif args.empty? && @attributes.key?(name.to_sym)
|
|
17
25
|
@attributes[name.to_sym]
|
|
18
26
|
else
|
data/lib/bluepill/process.rb
CHANGED
|
@@ -32,7 +32,10 @@ module Bluepill
|
|
|
32
32
|
:cache_actual_pid,
|
|
33
33
|
|
|
34
34
|
:monitor_children,
|
|
35
|
-
:child_process_factory
|
|
35
|
+
:child_process_factory,
|
|
36
|
+
|
|
37
|
+
:pid_command,
|
|
38
|
+
:auto_start
|
|
36
39
|
]
|
|
37
40
|
|
|
38
41
|
attr_accessor :name, :watches, :triggers, :logger, :skip_ticks_until, :process_running
|
|
@@ -215,8 +218,7 @@ module Bluepill
|
|
|
215
218
|
if self.process_running?(true)
|
|
216
219
|
self.state = 'up'
|
|
217
220
|
else
|
|
218
|
-
|
|
219
|
-
self.state = 'down'
|
|
221
|
+
self.state = (auto_start == false) ? 'unmonitored' : 'down' # we need to check for false value
|
|
220
222
|
end
|
|
221
223
|
end
|
|
222
224
|
|
|
@@ -338,6 +340,10 @@ module Bluepill
|
|
|
338
340
|
end
|
|
339
341
|
|
|
340
342
|
def actual_pid
|
|
343
|
+
pid_command ? pid_from_command : pid_from_file
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
def pid_from_file
|
|
341
347
|
return @actual_pid if cache_actual_pid? && @actual_pid
|
|
342
348
|
@actual_pid = begin
|
|
343
349
|
if pid_file
|
|
@@ -352,6 +358,11 @@ module Bluepill
|
|
|
352
358
|
end
|
|
353
359
|
end
|
|
354
360
|
|
|
361
|
+
def pid_from_command
|
|
362
|
+
pid = %x{#{pid_command}}.strip
|
|
363
|
+
(pid =~ /\A\d+\z/) ? pid.to_i : nil
|
|
364
|
+
end
|
|
365
|
+
|
|
355
366
|
def actual_pid=(pid)
|
|
356
367
|
@actual_pid = pid
|
|
357
368
|
end
|
data/lib/bluepill/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bluepill
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 123
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 0.0.
|
|
9
|
+
- 50
|
|
10
|
+
version: 0.0.50
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Arya Asemanfar
|
|
@@ -17,7 +17,7 @@ autorequire:
|
|
|
17
17
|
bindir: bin
|
|
18
18
|
cert_chain: []
|
|
19
19
|
|
|
20
|
-
date: 2011-
|
|
20
|
+
date: 2011-06-01 00:00:00 +04:00
|
|
21
21
|
default_executable:
|
|
22
22
|
dependencies:
|
|
23
23
|
- !ruby/object:Gem::Dependency
|
|
@@ -124,6 +124,8 @@ files:
|
|
|
124
124
|
- bin/sample_forking_server
|
|
125
125
|
- bluepill.gemspec
|
|
126
126
|
- examples/example.rb
|
|
127
|
+
- examples/new_example.rb
|
|
128
|
+
- examples/new_runit_example.rb
|
|
127
129
|
- examples/runit_example.rb
|
|
128
130
|
- lib/bluepill.rb
|
|
129
131
|
- lib/bluepill/application.rb
|