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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35f98731b6e37b345dc0abd6c97ef152004b7c1e
4
- data.tar.gz: e2a074334d09655a98797944a70d582fd712b295
3
+ metadata.gz: a28c6400321b02c8c806845c00a44e1a03502fc7
4
+ data.tar.gz: ae9f9810c4ace92872bed2f54c8e76a7597e480a
5
5
  SHA512:
6
- metadata.gz: a6f3a92d2d04bb5ecc994882039cfdf56039315dbd0a869b7a2756a137367f7feaa62e7b396fcd03f5d1d5f78b3b033862da0338e60a33722287e0fa19296fc8
7
- data.tar.gz: a9642dd51a9fa311b03e2b8b175e18e2a792c1d360886590330c6c36f8fa11b568e7662fe9929f429c1e7edc2602ab68ba0c418fde838f68a37529ccefda31c2
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.0
376
+ * Ruby 2.1
378
377
  * [JRuby][]
379
378
  * [Rubinius][]
380
379
 
@@ -11,44 +11,44 @@ RbConfig = Config unless Object.const_defined?(:RbConfig)
11
11
 
12
12
  # Default options
13
13
  options = {
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"),
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 = "Usage: bluepill [app] cmd [options]"
23
- opts.on('-l', "--logfile LOGFILE", "Path to logfile, defaults to #{options[:log_file]}") do |file|
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', "--base-dir DIR", "Directory to store bluepill socket and pid files, defaults to #{options[:base_dir]}") do |base_dir|
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("-v", "--version") do
31
+ opts.on('-v', '--version') do
32
32
  puts "bluepill, version #{Bluepill::VERSION}"
33
33
  exit
34
34
  end
35
35
 
36
- opts.on("--[no-]privileged", "Allow/disallow to run #{$0} as non-privileged process. disallowed by default") do |v|
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, "Timeout for commands sent to the daemon, in seconds. Defaults to 10.") do |timeout|
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, "Attempts for commands sent to the daemon, in seconds. Defaults to 1.") do |attempts|
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 "Commands:"
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 "See http://github.com/bluepill-rb/bluepill#readme"
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 "You must run bluepill as root or use --no-privileged option."
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($0)) && File.symlink?($0)
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($0)
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 "Usage: bluepill [app] cmd [options]"
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] == "load"
106
+ if options[:command] == 'load'
107
107
  file = ARGV.shift
108
- if File.exists?(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
-
@@ -15,7 +15,7 @@
15
15
  require 'socket'
16
16
 
17
17
  port = ARGV[0].to_i
18
- port = 4242 if port == 0
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') { acceptor.close; children.each {|c| Process.kill('QUIT', c)} }
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') {$0 = "forking_server| QUIT received shutting down gracefully..."; sleep 5; exit}
32
- trap('INT') {$0 = "forking_server| INT received shutting down UN-gracefully..."; sleep 3; exit}
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 #$$ accepting on shared socket (localhost:#{port})"
35
- loop {
36
- socket, addr = acceptor.accept
37
- socket.write "child #$$ echo> "
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 #$$ echo'd: '#{message.strip}'"
52
+ puts "child #{$PROCESS_ID} echo'd: '#{message.strip}'"
43
53
 
44
54
  # cause a spike in mem usage
45
- temp = "*" * (100 * 1024)
46
- }
55
+ '*' * 2**20
56
+ end
47
57
  exit
48
58
  end
49
59
  end
50
60
 
51
- trap('INT') { puts "\nbailing" ; exit }
61
+ trap('INT') do
62
+ puts "\nbailing"
63
+ exit
64
+ end
52
65
 
53
66
  Process.waitall
@@ -1,31 +1,25 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- $LOAD_PATH.push File.expand_path("../lib", __FILE__)
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 = "bluepill"
6
+ s.name = 'bluepill'
9
7
  s.version = Bluepill::VERSION.dup
10
8
  s.platform = Gem::Platform::RUBY
11
- s.authors = ["Arya Asemanfar", "Gary Tsang", "Rohith Ravi"]
12
- s.email = ["entombedvirus@gmail.com"]
13
- s.homepage = "http://github.com/bluepill-rb/bluepill"
14
- s.summary = %q{A process monitor written in Ruby with stability and minimalism in mind.}
15
- 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.}
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 = `git ls-files`.split("\n")
26
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
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
-
@@ -1,7 +1,6 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'rubygems'
3
2
 
4
- require 'bundler/setup' if ENV['BUNDLE_GEMFILE'] && File.exists?(ENV['BUNDLE_GEMFILE'])
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 "bluepill/process"
25
- require "bluepill/process_statistics"
26
- require "bluepill/group"
27
- require "bluepill/logger"
28
- require "bluepill/condition_watch"
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 "bluepill/dsl"
32
- require "bluepill/system"
31
+ require 'bluepill/dsl'
32
+ require 'bluepill/system'
33
33
 
34
- require "bluepill/process_conditions"
34
+ require 'bluepill/process_conditions'
35
35
 
36
- require "bluepill/util/rotational_array"
36
+ require 'bluepill/util/rotational_array'
37
37
 
38
- require "bluepill/version"
38
+ require 'bluepill/version'
@@ -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') : "/var/run/bluepill")
22
- self.pid_file = File.join(self.base_dir, 'pids', self.name + ".pid")
23
- self.pids_dir = File.join(self.base_dir, 'pids', self.name)
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 => self.log_file, :stdout => foreground?).prefix_with(self.name)
27
+ self.logger = ProcessJournal.logger = Bluepill::Logger.new(:log_file => log_file, :stdout => foreground?).prefix_with(self.name)
29
28
 
30
- self.setup_signal_traps
31
- self.setup_pids_dir
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
- begin
46
- self.start_server
47
- rescue StandardError => e
48
- $stderr.puts "Failed to start bluepill:"
49
- $stderr.puts "%s `%s`" % [e.class.name, e.message]
50
- $stderr.puts e.backtrace
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
- self.groups[group_name] ||= Group.new(group_name, :logger => self.logger.prefix_with(group_name))
67
- self.groups[group_name].add_process(process)
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
- protected
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
- self.groups.values.collect do |group|
75
+ groups.values.collect do |group|
78
76
  group.send(method)
79
77
  end.flatten
80
- elsif self.groups.key?(group_name)
81
- self.groups[group_name].send(method, process_name)
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
- self.groups.values.collect do |group|
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 = self.socket.accept
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 { self.send(command, *args) }
103
- rescue Exception => e
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("Got exception in cmd listener: %s `%s`" % [e.class.name, e.message])
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
- self.kill_previous_bluepill
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
- self.logger.reopen
131
+ logger.reopen
134
132
 
135
- $0 = "bluepilld: #{self.name}"
133
+ $0 = "bluepilld: #{name}"
136
134
 
137
- self.groups.each {|_, group| group.determine_initial_state }
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
- self.write_pid_file
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
- self.groups.each { |_, group| group.tick }
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(self.socket.path) if self.socket
159
+ System.delete_if_exists(socket.path) if socket
163
160
  rescue IOError
164
161
  end
165
- System.delete_if_exists(self.pid_file)
162
+ System.delete_if_exists(pid_file)
166
163
  end
167
164
 
168
165
  def setup_signal_traps
169
- terminator = Proc.new do
170
- puts "Terminating..."
166
+ terminator = proc do
167
+ puts 'Terminating...'
171
168
  cleanup
172
169
  @running = false
173
170
  end
174
171
 
175
- Signal.trap("TERM", &terminator)
176
- Signal.trap("INT", &terminator)
172
+ Signal.trap('TERM', &terminator)
173
+ Signal.trap('INT', &terminator)
177
174
 
178
- Signal.trap("HUP") do
179
- self.logger.reopen if self.logger
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(self.pids_dir) unless File.exists?(self.pids_dir)
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, self.pids_dir)
184
+ FileUtils.chmod(0777, pids_dir)
188
185
  end
189
186
 
190
187
  def kill_previous_bluepill
191
- if File.exists?(self.pid_file)
192
- previous_pid = File.read(self.pid_file).to_i
193
- if System.pid_alive?(previous_pid)
194
- begin
195
- ::Process.kill(0, previous_pid)
196
- puts "Killing previous bluepilld[#{previous_pid}]"
197
- ::Process.kill(2, previous_pid)
198
- rescue Exception => e
199
- $stderr.puts "Encountered error trying to kill previous bluepill:"
200
- $stderr.puts "#{e.class}: #{e.message}"
201
- exit(4) unless e.is_a?(Errno::ESRCH)
202
- else
203
- kill_timeout.times do |i|
204
- sleep 0.5
205
- break unless System.pid_alive?(previous_pid)
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
- if System.pid_alive?(previous_pid)
209
- $stderr.puts "Previous bluepilld[#{previous_pid}] didn't die"
210
- exit(4)
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(self.pid_file, 'w') { |x| x.write(::Process.pid) }
211
+ File.open(pid_file, 'w') { |x| x.write(::Process.pid) }
219
212
  end
220
213
  end
221
214
  end