bluepill 0.0.68 → 0.0.69
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/bin/bluepill +19 -20
- data/bin/sample_forking_server +26 -13
- data/bluepill.gemspec +12 -18
- data/lib/bluepill.rb +12 -12
- data/lib/bluepill/application.rb +64 -71
- data/lib/bluepill/application/client.rb +0 -2
- data/lib/bluepill/application/server.rb +1 -3
- data/lib/bluepill/condition_watch.rb +12 -7
- data/lib/bluepill/controller.rb +37 -42
- data/lib/bluepill/dsl.rb +1 -2
- data/lib/bluepill/dsl/app_proxy.rb +3 -4
- data/lib/bluepill/dsl/process_factory.rb +40 -44
- data/lib/bluepill/dsl/process_proxy.rb +4 -5
- data/lib/bluepill/group.rb +15 -21
- data/lib/bluepill/logger.rb +4 -4
- data/lib/bluepill/process.rb +107 -109
- data/lib/bluepill/process_conditions.rb +1 -3
- data/lib/bluepill/process_conditions/always_true.rb +2 -3
- data/lib/bluepill/process_conditions/cpu_usage.rb +0 -1
- data/lib/bluepill/process_conditions/file_time.rb +5 -6
- data/lib/bluepill/process_conditions/http.rb +11 -9
- data/lib/bluepill/process_conditions/mem_usage.rb +6 -7
- data/lib/bluepill/process_conditions/process_condition.rb +4 -5
- data/lib/bluepill/process_conditions/running_time.rb +1 -2
- data/lib/bluepill/process_conditions/zombie_process.rb +1 -2
- data/lib/bluepill/process_journal.rb +18 -21
- data/lib/bluepill/process_statistics.rb +2 -4
- data/lib/bluepill/socket.rb +13 -16
- data/lib/bluepill/system.rb +57 -63
- data/lib/bluepill/trigger.rb +9 -11
- data/lib/bluepill/triggers/flapping.rb +12 -16
- data/lib/bluepill/util/rotational_array.rb +1 -2
- data/lib/bluepill/version.rb +1 -2
- metadata +4 -28
- data/.gitignore +0 -12
- data/.rspec +0 -1
- data/.travis.yml +0 -17
- data/Gemfile +0 -27
- data/Rakefile +0 -38
- data/examples/example.rb +0 -87
- data/examples/new_example.rb +0 -89
- data/examples/new_runit_example.rb +0 -29
- data/examples/runit_example.rb +0 -26
- data/local-bluepill +0 -130
- data/spec/lib/bluepill/application_spec.rb +0 -51
- data/spec/lib/bluepill/logger_spec.rb +0 -3
- data/spec/lib/bluepill/process_spec.rb +0 -135
- data/spec/lib/bluepill/process_statistics_spec.rb +0 -24
- data/spec/lib/bluepill/system_spec.rb +0 -45
- data/spec/spec_helper.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a28c6400321b02c8c806845c00a44e1a03502fc7
|
4
|
+
data.tar.gz: ae9f9810c4ace92872bed2f54c8e76a7597e480a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbffdf158f85bf0d606472a3bddd9045453b4aac4c57c0b46104b37f15b78a929885a58a51d90ab72ccf4ad39908407343abced61c4a19b0c64679d945ab641c
|
7
|
+
data.tar.gz: b421ac8a82226cb41c02f50ed528fdcb18e5e425835863c47721bd9c6c65520242221608aa6dedd67939218c112d2ef54e13e32d48376cfefe8a9e2199d42c4b
|
data/README.md
CHANGED
@@ -371,10 +371,9 @@ This library aims to support and is [tested against][travis] the following Ruby
|
|
371
371
|
implementations:
|
372
372
|
|
373
373
|
* Ruby 1.8.7
|
374
|
-
* Ruby 1.9.2
|
375
374
|
* Ruby 1.9.3
|
376
375
|
* Ruby 2.0.0
|
377
|
-
* Ruby 2.1
|
376
|
+
* Ruby 2.1
|
378
377
|
* [JRuby][]
|
379
378
|
* [Rubinius][]
|
380
379
|
|
data/bin/bluepill
CHANGED
@@ -11,44 +11,44 @@ RbConfig = Config unless Object.const_defined?(:RbConfig)
|
|
11
11
|
|
12
12
|
# Default options
|
13
13
|
options = {
|
14
|
-
:log_file =>
|
15
|
-
:base_dir => ENV['BLUEPILL_BASE_DIR'] || (::Process.euid != 0 ? File.join(ENV['HOME'], '.bluepill') :
|
14
|
+
:log_file => '/var/log/bluepill.log',
|
15
|
+
:base_dir => ENV['BLUEPILL_BASE_DIR'] || (::Process.euid != 0 ? File.join(ENV['HOME'], '.bluepill') : '/var/run/bluepill'),
|
16
16
|
:privileged => true,
|
17
17
|
:timeout => 10,
|
18
|
-
:attempts => 1
|
18
|
+
:attempts => 1,
|
19
19
|
}
|
20
20
|
|
21
21
|
OptionParser.new do |opts|
|
22
|
-
opts.banner =
|
23
|
-
opts.on('-l',
|
22
|
+
opts.banner = 'Usage: bluepill [app] cmd [options]'
|
23
|
+
opts.on('-l', '--logfile LOGFILE', "Path to logfile, defaults to #{options[:log_file]}") do |file|
|
24
24
|
options[:log_file] = file
|
25
25
|
end
|
26
26
|
|
27
|
-
opts.on('-c',
|
27
|
+
opts.on('-c', '--base-dir DIR', "Directory to store bluepill socket and pid files, defaults to #{options[:base_dir]}") do |base_dir|
|
28
28
|
options[:base_dir] = base_dir
|
29
29
|
end
|
30
30
|
|
31
|
-
opts.on(
|
31
|
+
opts.on('-v', '--version') do
|
32
32
|
puts "bluepill, version #{Bluepill::VERSION}"
|
33
33
|
exit
|
34
34
|
end
|
35
35
|
|
36
|
-
opts.on(
|
36
|
+
opts.on('--[no-]privileged', "Allow/disallow to run #{$PROGRAM_NAME} as non-privileged process. disallowed by default") do |v|
|
37
37
|
options[:privileged] = v
|
38
38
|
end
|
39
39
|
|
40
|
-
opts.on('-t', '--timeout Seconds', Integer,
|
40
|
+
opts.on('-t', '--timeout Seconds', Integer, 'Timeout for commands sent to the daemon, in seconds. Defaults to 10.') do |timeout|
|
41
41
|
options[:timeout] = timeout
|
42
42
|
end
|
43
43
|
|
44
|
-
opts.on('--attempts Count', Integer,
|
44
|
+
opts.on('--attempts Count', Integer, 'Attempts for commands sent to the daemon, in seconds. Defaults to 1.') do |attempts|
|
45
45
|
options[:attempts] = attempts
|
46
46
|
end
|
47
47
|
|
48
48
|
help = proc do
|
49
49
|
puts opts
|
50
50
|
puts
|
51
|
-
puts
|
51
|
+
puts 'Commands:'
|
52
52
|
puts " load CONFIG_FILE\t\tLoads new instance of bluepill using the specified config file"
|
53
53
|
puts " status\t\t\tLists the status of the proceses for the specified app"
|
54
54
|
puts " start [TARGET]\t\tIssues the start command for the target process or group, defaults to all processes"
|
@@ -58,17 +58,17 @@ OptionParser.new do |opts|
|
|
58
58
|
puts " log [TARGET]\t\tShow the log for the specified process or group, defaults to all for app"
|
59
59
|
puts " quit\t\t\tStop bluepill"
|
60
60
|
puts
|
61
|
-
puts
|
61
|
+
puts 'See http://github.com/bluepill-rb/bluepill#readme'
|
62
62
|
exit
|
63
63
|
end
|
64
64
|
|
65
|
-
opts.on_tail('-h','--help', 'Show this message', &help)
|
65
|
+
opts.on_tail('-h', '--help', 'Show this message', &help)
|
66
66
|
help.call if ARGV.empty?
|
67
67
|
end.parse!
|
68
68
|
|
69
69
|
# Check for root
|
70
70
|
if options[:privileged] && ::Process.euid != 0
|
71
|
-
$stderr.puts
|
71
|
+
$stderr.puts 'You must run bluepill as root or use --no-privileged option.'
|
72
72
|
exit(3)
|
73
73
|
end
|
74
74
|
|
@@ -76,9 +76,9 @@ APPLICATION_COMMANDS = %w(status start stop restart unmonitor quit log)
|
|
76
76
|
|
77
77
|
controller = Bluepill::Controller.new(options.slice(:base_dir, :log_file))
|
78
78
|
|
79
|
-
if controller.running_applications.include?(File.basename($
|
79
|
+
if controller.running_applications.include?(File.basename($PROGRAM_NAME)) && File.symlink?($PROGRAM_NAME)
|
80
80
|
# bluepill was called as a symlink with the name of the target application
|
81
|
-
options[:application] = File.basename($
|
81
|
+
options[:application] = File.basename($PROGRAM_NAME)
|
82
82
|
elsif controller.running_applications.include?(ARGV.first)
|
83
83
|
# the first arg is the application name
|
84
84
|
options[:application] = ARGV.shift
|
@@ -92,7 +92,7 @@ elsif APPLICATION_COMMANDS.include?(ARGV.first)
|
|
92
92
|
controller.running_applications.each_with_index do |app, index|
|
93
93
|
$stderr.puts " #{index + 1}. #{app}"
|
94
94
|
end
|
95
|
-
$stderr.puts
|
95
|
+
$stderr.puts 'Usage: bluepill [app] cmd [options]'
|
96
96
|
exit(1)
|
97
97
|
else
|
98
98
|
# There are none running AND they aren't trying to start one
|
@@ -103,9 +103,9 @@ end
|
|
103
103
|
|
104
104
|
options[:command] = ARGV.shift
|
105
105
|
|
106
|
-
if options[:command] ==
|
106
|
+
if options[:command] == 'load'
|
107
107
|
file = ARGV.shift
|
108
|
-
if File.
|
108
|
+
if File.exist?(file)
|
109
109
|
# Restart the ruby interpreter for the config file so that anything loaded here
|
110
110
|
# does not stay in memory for the daemon
|
111
111
|
ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
|
@@ -122,4 +122,3 @@ else
|
|
122
122
|
target = ARGV.shift
|
123
123
|
controller.handle_command(options[:application], options[:command], target)
|
124
124
|
end
|
125
|
-
|
data/bin/sample_forking_server
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
require 'socket'
|
16
16
|
|
17
17
|
port = ARGV[0].to_i
|
18
|
-
port = 4242 if port
|
18
|
+
port = 4242 if port.zero?
|
19
19
|
|
20
20
|
acceptor = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
|
21
21
|
address = Socket.pack_sockaddr_in(port, '127.0.0.1')
|
@@ -23,31 +23,44 @@ acceptor.bind(address)
|
|
23
23
|
acceptor.listen(10)
|
24
24
|
|
25
25
|
children = []
|
26
|
-
trap('EXIT')
|
27
|
-
|
26
|
+
trap('EXIT') do
|
27
|
+
acceptor.close
|
28
|
+
children.each { |c| Process.kill('QUIT', c) }
|
29
|
+
end
|
28
30
|
|
29
31
|
3.times do
|
30
32
|
children << fork do
|
31
|
-
trap('QUIT')
|
32
|
-
|
33
|
+
trap('QUIT') do
|
34
|
+
$0 = 'forking_server| QUIT received shutting down gracefully...'
|
35
|
+
sleep 5
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
trap('INT') do
|
39
|
+
$0 = 'forking_server| INT received shutting down UN-gracefully...'
|
40
|
+
sleep 3
|
41
|
+
exit
|
42
|
+
end
|
33
43
|
|
34
|
-
puts "child
|
35
|
-
loop
|
36
|
-
socket,
|
37
|
-
socket.write "child
|
44
|
+
puts "child #{$PROCESS_ID} accepting on shared socket (localhost:#{port})"
|
45
|
+
loop do
|
46
|
+
socket, _ = acceptor.accept
|
47
|
+
socket.write "child #{$PROCESS_ID} echo> "
|
38
48
|
socket.flush
|
39
49
|
message = socket.gets
|
40
50
|
socket.write message
|
41
51
|
socket.close
|
42
|
-
puts "child
|
52
|
+
puts "child #{$PROCESS_ID} echo'd: '#{message.strip}'"
|
43
53
|
|
44
54
|
# cause a spike in mem usage
|
45
|
-
|
46
|
-
|
55
|
+
'*' * 2**20
|
56
|
+
end
|
47
57
|
exit
|
48
58
|
end
|
49
59
|
end
|
50
60
|
|
51
|
-
trap('INT')
|
61
|
+
trap('INT') do
|
62
|
+
puts "\nbailing"
|
63
|
+
exit
|
64
|
+
end
|
52
65
|
|
53
66
|
Process.waitall
|
data/bluepill.gemspec
CHANGED
@@ -1,31 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require "bluepill/version"
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'bluepill/version'
|
6
4
|
|
7
5
|
Gem::Specification.new do |s|
|
8
|
-
s.name =
|
6
|
+
s.name = 'bluepill'
|
9
7
|
s.version = Bluepill::VERSION.dup
|
10
8
|
s.platform = Gem::Platform::RUBY
|
11
|
-
s.authors = [
|
12
|
-
s.email = [
|
13
|
-
s.homepage =
|
14
|
-
s.summary =
|
15
|
-
s.description =
|
9
|
+
s.authors = ['Arya Asemanfar', 'Gary Tsang', 'Rohith Ravi']
|
10
|
+
s.email = ['entombedvirus@gmail.com']
|
11
|
+
s.homepage = 'http://github.com/bluepill-rb/bluepill'
|
12
|
+
s.summary = 'A process monitor written in Ruby with stability and minimalism in mind.'
|
13
|
+
s.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."
|
16
14
|
s.license = 'MIT'
|
17
15
|
|
18
16
|
s.add_dependency 'activesupport', ['>= 3', '< 5']
|
19
17
|
s.add_dependency 'blue-daemons', '~> 1.1.11'
|
20
18
|
s.add_dependency 'i18n', '~> 0.5'
|
21
19
|
s.add_dependency 'state_machine', '~> 1.1'
|
22
|
-
|
23
20
|
s.add_development_dependency 'bundler', '~> 1.3'
|
24
21
|
|
25
|
-
s.files =
|
26
|
-
s.
|
27
|
-
s.
|
28
|
-
s.require_paths = ["lib"]
|
29
|
-
s.extra_rdoc_files = ["LICENSE", "README.md"]
|
22
|
+
s.files = %w(CONTRIBUTING.md DESIGN.md LICENSE README.md bluepill.gemspec) + Dir['bin/*'] + Dir['lib/**/*.rb']
|
23
|
+
s.executables = Dir['bin/*'].map { |f| File.basename(f) }
|
24
|
+
s.require_paths = ['lib']
|
30
25
|
end
|
31
|
-
|
data/lib/bluepill.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
require 'rubygems'
|
3
2
|
|
4
|
-
require 'bundler/setup' if ENV['BUNDLE_GEMFILE'] && File.
|
3
|
+
require 'bundler/setup' if ENV['BUNDLE_GEMFILE'] && File.exist?(ENV['BUNDLE_GEMFILE'])
|
5
4
|
|
6
5
|
require 'thread'
|
7
6
|
require 'monitor'
|
@@ -9,6 +8,7 @@ require 'syslog'
|
|
9
8
|
require 'timeout'
|
10
9
|
require 'logger'
|
11
10
|
|
11
|
+
require 'active_support'
|
12
12
|
require 'active_support/inflector'
|
13
13
|
require 'active_support/core_ext/hash'
|
14
14
|
require 'active_support/core_ext/numeric'
|
@@ -21,18 +21,18 @@ require 'bluepill/dsl/app_proxy'
|
|
21
21
|
require 'bluepill/application'
|
22
22
|
require 'bluepill/controller'
|
23
23
|
require 'bluepill/socket'
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
24
|
+
require 'bluepill/process'
|
25
|
+
require 'bluepill/process_statistics'
|
26
|
+
require 'bluepill/group'
|
27
|
+
require 'bluepill/logger'
|
28
|
+
require 'bluepill/condition_watch'
|
29
29
|
require 'bluepill/trigger'
|
30
30
|
require 'bluepill/triggers/flapping'
|
31
|
-
require
|
32
|
-
require
|
31
|
+
require 'bluepill/dsl'
|
32
|
+
require 'bluepill/system'
|
33
33
|
|
34
|
-
require
|
34
|
+
require 'bluepill/process_conditions'
|
35
35
|
|
36
|
-
require
|
36
|
+
require 'bluepill/util/rotational_array'
|
37
37
|
|
38
|
-
require
|
38
|
+
require 'bluepill/version'
|
data/lib/bluepill/application.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
require 'thread'
|
3
2
|
require 'bluepill/system'
|
4
3
|
require 'bluepill/process_journal'
|
@@ -18,17 +17,17 @@ module Bluepill
|
|
18
17
|
self.log_file = options[:log_file]
|
19
18
|
self.base_dir = ProcessJournal.base_dir = options[:base_dir] ||
|
20
19
|
ENV['BLUEPILL_BASE_DIR'] ||
|
21
|
-
(::Process.euid != 0 ? File.join(ENV['HOME'], '.bluepill') :
|
22
|
-
self.pid_file = File.join(
|
23
|
-
self.pids_dir = File.join(
|
20
|
+
(::Process.euid != 0 ? File.join(ENV['HOME'], '.bluepill') : '/var/run/bluepill')
|
21
|
+
self.pid_file = File.join(base_dir, 'pids', self.name + '.pid')
|
22
|
+
self.pids_dir = File.join(base_dir, 'pids', self.name)
|
24
23
|
self.kill_timeout = options[:kill_timeout] || 10
|
25
24
|
|
26
25
|
self.groups = {}
|
27
26
|
|
28
|
-
self.logger = ProcessJournal.logger = Bluepill::Logger.new(:log_file =>
|
27
|
+
self.logger = ProcessJournal.logger = Bluepill::Logger.new(:log_file => log_file, :stdout => foreground?).prefix_with(self.name)
|
29
28
|
|
30
|
-
|
31
|
-
|
29
|
+
setup_signal_traps
|
30
|
+
setup_pids_dir
|
32
31
|
|
33
32
|
@mutex = Mutex.new
|
34
33
|
end
|
@@ -42,14 +41,12 @@ module Bluepill
|
|
42
41
|
end
|
43
42
|
|
44
43
|
def load
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
exit(5)
|
52
|
-
end
|
44
|
+
start_server
|
45
|
+
rescue StandardError => e
|
46
|
+
$stderr.puts('Failed to start bluepill:')
|
47
|
+
$stderr.puts(format('%s `%s`', e.class.name, e.message))
|
48
|
+
$stderr.puts(e.backtrace)
|
49
|
+
exit(5)
|
53
50
|
end
|
54
51
|
|
55
52
|
PROCESS_COMMANDS.each do |command|
|
@@ -63,26 +60,27 @@ module Bluepill
|
|
63
60
|
def add_process(process, group_name = nil)
|
64
61
|
group_name = group_name.to_s if group_name
|
65
62
|
|
66
|
-
|
67
|
-
|
63
|
+
groups[group_name] ||= Group.new(group_name, :logger => logger.prefix_with(group_name))
|
64
|
+
groups[group_name].add_process(process)
|
68
65
|
end
|
69
66
|
|
70
67
|
def version
|
71
68
|
Bluepill::VERSION
|
72
69
|
end
|
73
70
|
|
74
|
-
|
71
|
+
protected
|
72
|
+
|
75
73
|
def send_to_process_or_group(method, group_name, process_name)
|
76
74
|
if group_name.nil? && process_name.nil?
|
77
|
-
|
75
|
+
groups.values.collect do |group|
|
78
76
|
group.send(method)
|
79
77
|
end.flatten
|
80
|
-
elsif
|
81
|
-
|
78
|
+
elsif groups.key?(group_name)
|
79
|
+
groups[group_name].send(method, process_name)
|
82
80
|
elsif process_name.nil?
|
83
81
|
# they must be targeting just by process name
|
84
82
|
process_name = group_name
|
85
|
-
|
83
|
+
groups.values.collect do |group|
|
86
84
|
group.send(method, process_name)
|
87
85
|
end.flatten
|
88
86
|
else
|
@@ -95,18 +93,18 @@ module Bluepill
|
|
95
93
|
@listener_thread = Thread.new do
|
96
94
|
loop do
|
97
95
|
begin
|
98
|
-
client =
|
96
|
+
client = socket.accept
|
99
97
|
client.close_on_exec = true if client.respond_to?(:close_on_exec=)
|
100
|
-
command, *args = client.readline.strip.split(
|
98
|
+
command, *args = client.readline.strip.split(':')
|
101
99
|
response = begin
|
102
|
-
mutex {
|
103
|
-
rescue
|
100
|
+
mutex { send(command, *args) }
|
101
|
+
rescue => e
|
104
102
|
e
|
105
103
|
end
|
106
104
|
client.write(Marshal.dump(response))
|
107
105
|
rescue StandardError => e
|
108
|
-
logger.err(
|
109
|
-
e.backtrace.each {|l| logger.err(l)}
|
106
|
+
logger.err(format('Got exception in cmd listener: %s `%s`', e.class.name, e.message))
|
107
|
+
e.backtrace.each { |l| logger.err(l) }
|
110
108
|
ensure
|
111
109
|
begin
|
112
110
|
client.close
|
@@ -119,7 +117,7 @@ module Bluepill
|
|
119
117
|
end
|
120
118
|
|
121
119
|
def start_server
|
122
|
-
|
120
|
+
kill_previous_bluepill
|
123
121
|
ProcessJournal.kill_all_from_all_journals
|
124
122
|
ProcessJournal.clear_all_atomic_fs_locks
|
125
123
|
|
@@ -130,18 +128,17 @@ module Bluepill
|
|
130
128
|
|
131
129
|
Daemonize.daemonize unless foreground?
|
132
130
|
|
133
|
-
|
131
|
+
logger.reopen
|
134
132
|
|
135
|
-
$0 = "bluepilld: #{
|
133
|
+
$0 = "bluepilld: #{name}"
|
136
134
|
|
137
|
-
|
135
|
+
groups.each { |_, group| group.determine_initial_state }
|
138
136
|
|
137
|
+
write_pid_file
|
138
|
+
self.socket = Bluepill::Socket.server(base_dir, name)
|
139
|
+
start_listener
|
139
140
|
|
140
|
-
|
141
|
-
self.socket = Bluepill::Socket.server(self.base_dir, self.name)
|
142
|
-
self.start_listener
|
143
|
-
|
144
|
-
self.run
|
141
|
+
run
|
145
142
|
end
|
146
143
|
|
147
144
|
def run
|
@@ -149,7 +146,7 @@ module Bluepill
|
|
149
146
|
while @running
|
150
147
|
mutex do
|
151
148
|
System.reset_data
|
152
|
-
|
149
|
+
groups.each { |_, group| group.tick }
|
153
150
|
end
|
154
151
|
sleep 1
|
155
152
|
end
|
@@ -159,63 +156,59 @@ module Bluepill
|
|
159
156
|
ProcessJournal.kill_all_from_all_journals
|
160
157
|
ProcessJournal.clear_all_atomic_fs_locks
|
161
158
|
begin
|
162
|
-
System.delete_if_exists(
|
159
|
+
System.delete_if_exists(socket.path) if socket
|
163
160
|
rescue IOError
|
164
161
|
end
|
165
|
-
System.delete_if_exists(
|
162
|
+
System.delete_if_exists(pid_file)
|
166
163
|
end
|
167
164
|
|
168
165
|
def setup_signal_traps
|
169
|
-
terminator =
|
170
|
-
puts
|
166
|
+
terminator = proc do
|
167
|
+
puts 'Terminating...'
|
171
168
|
cleanup
|
172
169
|
@running = false
|
173
170
|
end
|
174
171
|
|
175
|
-
Signal.trap(
|
176
|
-
Signal.trap(
|
172
|
+
Signal.trap('TERM', &terminator)
|
173
|
+
Signal.trap('INT', &terminator)
|
177
174
|
|
178
|
-
Signal.trap(
|
179
|
-
|
175
|
+
Signal.trap('HUP') do
|
176
|
+
logger.reopen if logger
|
180
177
|
end
|
181
178
|
end
|
182
179
|
|
183
180
|
def setup_pids_dir
|
184
|
-
FileUtils.mkdir_p(
|
181
|
+
FileUtils.mkdir_p(pids_dir) unless File.exist?(pids_dir)
|
185
182
|
# we need everybody to be able to write to the pids_dir as processes managed by
|
186
183
|
# bluepill will be writing to this dir after they've dropped privileges
|
187
|
-
FileUtils.chmod(0777,
|
184
|
+
FileUtils.chmod(0777, pids_dir)
|
188
185
|
end
|
189
186
|
|
190
187
|
def kill_previous_bluepill
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
end
|
188
|
+
return unless File.exist?(pid_file)
|
189
|
+
previous_pid = File.read(pid_file).to_i
|
190
|
+
return unless System.pid_alive?(previous_pid)
|
191
|
+
::Process.kill(0, previous_pid)
|
192
|
+
puts "Killing previous bluepilld[#{previous_pid}]"
|
193
|
+
::Process.kill(2, previous_pid)
|
194
|
+
rescue => e
|
195
|
+
$stderr.puts 'Encountered error trying to kill previous bluepill:'
|
196
|
+
$stderr.puts "#{e.class}: #{e.message}"
|
197
|
+
exit(4) unless e.is_a?(Errno::ESRCH)
|
198
|
+
else
|
199
|
+
kill_timeout.times do |_i|
|
200
|
+
sleep 0.5
|
201
|
+
break unless System.pid_alive?(previous_pid)
|
202
|
+
end
|
207
203
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
204
|
+
if System.pid_alive?(previous_pid)
|
205
|
+
$stderr.puts "Previous bluepilld[#{previous_pid}] didn't die"
|
206
|
+
exit(4)
|
214
207
|
end
|
215
208
|
end
|
216
209
|
|
217
210
|
def write_pid_file
|
218
|
-
File.open(
|
211
|
+
File.open(pid_file, 'w') { |x| x.write(::Process.pid) }
|
219
212
|
end
|
220
213
|
end
|
221
214
|
end
|