bluepill 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6007963ed9836bc609625037bd170bed8057cf37
4
- data.tar.gz: 0dbdd5043c20fad925290da16d63ef423b18ba83
3
+ metadata.gz: d38d93040875f0423d7d3f567cb2af3e7d1d0cbe
4
+ data.tar.gz: d30780afd0d7f3741a843e6ccccc318c8d34c634
5
5
  SHA512:
6
- metadata.gz: 3a19e7ac04e1373bf37f2fbbeeef3bf827260326aa73573028d735da2acf03517469c6f5442a55826198dbd7b6dffec73b35aafa80e89f53ad1a5708db2d95ad
7
- data.tar.gz: bb395f534f3f5ed497ed76318fcd72c898ff4bf9ff508ea1e657cb5f94e0891e8fea81436241285d299f54e42bcc2cdb036d48a50fd6e198502d9a308c8ef9e6
6
+ metadata.gz: ff47566e5b2b25142c09e6c987fd957c025901d4c8b5e38f8603caa1cb0a7acf516027d180c3dbdc5ac4ac8a248521fce11e219a9890af690729cc67b8634d02
7
+ data.tar.gz: 851beaeaf97d4a22c373d055bd472ef0ac35ba3b0a83ff972c85e4bdbc63581c46f85b606d51e1273d2ff5750aba6a0816e7f9f4829259e4604beb13022c9ed2
data/README.md CHANGED
@@ -342,7 +342,8 @@ end
342
342
 
343
343
  Keep in mind that you still need to set up log rotation (described in the installation section) to keep the log file from growing huge.
344
344
 
345
- ### Extra options
345
+ ### Foreground mode
346
+
346
347
  You can run bluepill in the foreground:
347
348
 
348
349
  ```ruby
@@ -353,6 +354,9 @@ end
353
354
 
354
355
  Note that You must define only one application per config when using foreground mode.
355
356
 
357
+
358
+ y allows you to run bluepill only in the foreground.
359
+
356
360
  ## Links
357
361
 
358
362
  * Code: [http://github.com/bluepill-rb/bluepill](http://github.com/bluepill-rb/bluepill)
@@ -369,8 +373,8 @@ implementations:
369
373
  * Ruby 2.0.0
370
374
  * Ruby 2.1
371
375
  * Ruby 2.2
372
- * JRuby 1.7
373
- * JRuby 9.0.0.0
376
+ * JRuby 1.7 (only in the foreground)
377
+ * JRuby 9.0.0.0 (only in the foreground)
374
378
 
375
379
  If something doesn't work on one of these interpreters, please open an issue.
376
380
 
@@ -1,4 +1,4 @@
1
- #! /usr/bin/env ruby
1
+ #!/usr/bin/env ruby
2
2
  require 'optparse'
3
3
  require 'bluepill'
4
4
 
@@ -72,7 +72,7 @@ if options[:privileged] && ::Process.euid != 0
72
72
  exit(3)
73
73
  end
74
74
 
75
- APPLICATION_COMMANDS = %w(status start stop restart unmonitor quit log)
75
+ APPLICATION_COMMANDS = %w(status start stop restart unmonitor quit log).freeze
76
76
 
77
77
  controller = Bluepill::Controller.new(options.slice(:base_dir, :log_file))
78
78
 
@@ -1,4 +1,4 @@
1
- #! /usr/bin/env ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  # This is a modified version found at http://tomayko.com/writings/unicorn-is-unix
4
4
  # It is modified to trigger various states like increase memory consumption so that
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.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."
14
14
  spec.license = 'MIT'
15
15
 
16
- spec.add_dependency 'activesupport', ['>= 3.2', '< 5']
16
+ spec.add_dependency 'activesupport', ['>= 3.2', '< 6']
17
17
  spec.add_dependency 'blue-daemons', '~> 1.1'
18
18
  spec.add_dependency 'state_machine', '~> 1.1'
19
19
  spec.add_development_dependency 'bundler', '~> 1.3'
@@ -4,7 +4,7 @@ require 'bluepill/process_journal'
4
4
 
5
5
  module Bluepill
6
6
  class Application
7
- PROCESS_COMMANDS = [:start, :stop, :restart, :unmonitor, :status]
7
+ PROCESS_COMMANDS = [:start, :stop, :restart, :unmonitor, :status].freeze
8
8
 
9
9
  attr_accessor :name, :logger, :base_dir, :socket, :pid_file, :kill_timeout
10
10
  attr_accessor :groups, :work_queue
@@ -15,7 +15,7 @@ module Bluepill
15
15
  @times = [@times, @times] unless @times.is_a?(Array) # handles times: 5
16
16
  @include_children = options.delete(:include_children) || false
17
17
 
18
- self.clear_history!
18
+ clear_history!
19
19
 
20
20
  @process_condition = ProcessConditions[@name].new(options)
21
21
  end
@@ -34,7 +34,7 @@ module Bluepill
34
34
  @history << HistoryValue.new(@process_condition.format_value(value), @process_condition.check(value))
35
35
  logger.info(to_s)
36
36
 
37
- return @fires if self.fired?
37
+ return @fires if fired?
38
38
  end
39
39
  EMPTY_ARRAY
40
40
  end
@@ -61,7 +61,7 @@ module Bluepill
61
61
  def send_to_daemon(application, command, *args)
62
62
  verify_version!(application)
63
63
 
64
- command = ([command, *args]).join(':')
64
+ command = [command, *args].join(':')
65
65
  response = Socket.client_command(base_dir, application, command)
66
66
  if response.is_a?(Exception)
67
67
  $stderr.puts 'Received error from server:'
@@ -1,6 +1,6 @@
1
1
  module Bluepill
2
2
  class AppProxy
3
- APP_ATTRIBUTES = [:working_dir, :uid, :gid, :environment, :auto_start]
3
+ APP_ATTRIBUTES = [:working_dir, :uid, :gid, :environment, :auto_start].freeze
4
4
 
5
5
  attr_accessor(*APP_ATTRIBUTES)
6
6
  attr_reader :app
@@ -17,7 +17,7 @@ module Bluepill
17
17
  child_process_block = @attributes.delete(:child_process_block)
18
18
  @attributes[:child_process_factory] = ProcessFactory.new(@attributes, child_process_block) if @attributes[:monitor_children]
19
19
 
20
- self.validate_process! process
20
+ validate_process! process
21
21
  process.to_process
22
22
  end
23
23
 
@@ -28,7 +28,7 @@ module Bluepill
28
28
  attributes[:logger] = logger
29
29
 
30
30
  child = ProcessProxy.new(name, attributes, @process_block)
31
- self.validate_child_process! child
31
+ validate_child_process! child
32
32
  process = child.to_process
33
33
 
34
34
  process.determine_initial_state
@@ -18,7 +18,7 @@ module Bluepill
18
18
  @attributes[Regexp.last_match[1].to_sym] = args.first
19
19
  elsif args.size == 1
20
20
  @attributes[name.to_sym] = args.first
21
- elsif args.size == 0 && name.to_s =~ /^(.*)!$/
21
+ elsif args.empty? && name.to_s =~ /^(.*)!$/
22
22
  @attributes[Regexp.last_match[1].to_sym] = true
23
23
  elsif args.empty? && @attributes.key?(name.to_sym)
24
24
  @attributes[name.to_sym]
@@ -1,6 +1,6 @@
1
1
  module Bluepill
2
2
  class Logger
3
- LOG_METHODS = [:emerg, :alert, :crit, :err, :warning, :notice, :info, :debug]
3
+ LOG_METHODS = [:emerg, :alert, :crit, :err, :warning, :notice, :info, :debug].freeze
4
4
 
5
5
  def initialize(options = {})
6
6
  @options = options
@@ -52,7 +52,7 @@ module Bluepill
52
52
 
53
53
  class LoggerAdapter < ::Logger
54
54
  LOGGER_EQUIVALENTS =
55
- {debug: :debug, err: :error, warning: :warn, info: :info, emerg: :fatal, alert: :warn, crit: :fatal, notice: :info}
55
+ {debug: :debug, err: :error, warning: :warn, info: :info, emerg: :fatal, alert: :warn, crit: :fatal, notice: :info}.freeze
56
56
 
57
57
  LOG_METHODS.each do |method|
58
58
  next if method == LOGGER_EQUIVALENTS[method]
@@ -49,7 +49,7 @@ module Bluepill
49
49
  :group_stop_noblock,
50
50
  :group_unmonitor_noblock,
51
51
 
52
- ]
52
+ ].freeze
53
53
 
54
54
  attr_accessor :name, :watches, :triggers, :logger, :skip_ticks_until, :process_running
55
55
  attr_accessor(*CONFIGURABLE_ATTRIBUTES)
@@ -145,22 +145,22 @@ module Bluepill
145
145
  end
146
146
 
147
147
  def tick
148
- return if self.skipping_ticks?
148
+ return if skipping_ticks?
149
149
  self.skip_ticks_until = nil
150
150
 
151
151
  # clear the memoization per tick
152
152
  @process_running = nil
153
153
 
154
154
  # Deal with thread cleanup here since the stopping state isn't used
155
- clean_threads if self.unmonitored?
155
+ clean_threads if unmonitored?
156
156
 
157
157
  # run state machine transitions
158
158
  super
159
159
 
160
- return unless self.up?
160
+ return unless up?
161
161
  run_watches
162
162
 
163
- return unless self.monitor_children?
163
+ return unless monitor_children?
164
164
  refresh_children!
165
165
  children.each(&:tick)
166
166
  end
@@ -175,7 +175,7 @@ module Bluepill
175
175
  def dispatch!(event, reason = nil)
176
176
  @event_mutex.synchronize do
177
177
  @statistics.record_event(event, reason)
178
- send("#{event}")
178
+ send(event.to_s)
179
179
  end
180
180
  end
181
181
 
@@ -187,7 +187,7 @@ module Bluepill
187
187
  watches.each(&:clear_history!)
188
188
 
189
189
  # Also, when a process changes state, we should re-populate its child list
190
- if self.monitor_children?
190
+ if monitor_children?
191
191
  logger.warning 'Clearing child list'
192
192
  children.clear
193
193
  end
@@ -232,22 +232,22 @@ module Bluepill
232
232
  end
233
233
  end.each do |event, reason| # rubocop:disable Style/MultilineBlockChain
234
234
  break if @transitioned
235
- self.dispatch!(event, reason)
235
+ dispatch!(event, reason)
236
236
  end
237
237
  end
238
238
 
239
239
  def determine_initial_state
240
- if self.process_running?(true)
240
+ if process_running?(true)
241
241
  self.state = 'up'
242
- else
243
- self.state = (auto_start == false) ? 'unmonitored' : 'down' # we need to check for false value
242
+ return
244
243
  end
244
+ self.state = (auto_start == false) ? 'unmonitored' : 'down' # we need to check for false value
245
245
  end
246
246
 
247
247
  def handle_user_command(cmd)
248
248
  case cmd
249
249
  when 'start'
250
- if self.process_running?(true)
250
+ if process_running?(true)
251
251
  logger.warning('Refusing to re-run start command on an already running process.')
252
252
  else
253
253
  dispatch!(:start, 'user initiated')
@@ -279,13 +279,13 @@ module Bluepill
279
279
  ProcessJournal.kill_all_from_journal(name) # be sure nothing else is running from previous runs
280
280
  pre_start_process
281
281
  logger.warning "Executing start command: #{start_command}"
282
- if self.daemonize?
282
+ if daemonize?
283
283
  daemon_id = System.daemonize(start_command, system_command_options)
284
284
  if daemon_id
285
285
  ProcessJournal.append_pid_to_journal(name, daemon_id)
286
- children.each do|child|
286
+ children.each do |child|
287
287
  ProcessJournal.append_pid_to_journal(name, child.actual_pid)
288
- end if self.monitor_children?
288
+ end if monitor_children?
289
289
  end
290
290
  daemon_id
291
291
  else
@@ -430,7 +430,7 @@ module Bluepill
430
430
  if pid_file
431
431
  if File.exist?(pid_file)
432
432
  str = File.read(pid_file)
433
- str.to_i if str.size > 0
433
+ str.to_i unless str.empty?
434
434
  else
435
435
  logger.warning("pid_file #{pid_file} does not exist or cannot be read")
436
436
  nil
@@ -1,10 +1,10 @@
1
1
  module Bluepill
2
2
  module ProcessConditions
3
3
  class MemUsage < ProcessCondition
4
- MB = 1024**2
5
- FORMAT_STR = '%d%s'
6
- MB_LABEL = 'MB'
7
- KB_LABEL = 'KB'
4
+ MB = (1024**2).freeze
5
+ FORMAT_STR = '%d%s'.freeze
6
+ MB_LABEL = 'MB'.freeze
7
+ KB_LABEL = 'KB'.freeze
8
8
 
9
9
  def initialize(options = {})
10
10
  @below = options[:below]
@@ -6,11 +6,11 @@ module Bluepill
6
6
  end
7
7
 
8
8
  def run(_pid, _include_children)
9
- fail 'Implement in subclass!'
9
+ raise 'Implement in subclass!'
10
10
  end
11
11
 
12
12
  def check(_value)
13
- fail 'Implement in subclass!'
13
+ raise 'Implement in subclass!'
14
14
  end
15
15
 
16
16
  def format_value(value)
@@ -103,7 +103,7 @@ module Bluepill
103
103
  def kill_all_pgids_from_journal(journal_name)
104
104
  filename = pgid_journal_filename(journal_name)
105
105
  j = pgid_journal(filename)
106
- if j.length > 0
106
+ if !j.empty?
107
107
  acquire_atomic_fs_lock(filename) do
108
108
  j.each do |pgid|
109
109
  begin
@@ -136,7 +136,7 @@ module Bluepill
136
136
  def kill_all_pids_from_journal(journal_name)
137
137
  filename = pid_journal_filename(journal_name)
138
138
  j = pid_journal(filename)
139
- if j.length > 0
139
+ if !j.empty?
140
140
  acquire_atomic_fs_lock(filename) do
141
141
  j.each do |pid|
142
142
  begin
@@ -5,7 +5,7 @@ module Bluepill
5
5
  # This class represents the system that bluepill is running on.. It's mainly used to memoize
6
6
  # results of running ps auxx etc so that every watch in the every process will not result in a fork
7
7
  module System
8
- APPEND_MODE = 'a'
8
+ APPEND_MODE = 'a'.freeze
9
9
 
10
10
  module_function
11
11
 
@@ -17,7 +17,7 @@ module Bluepill
17
17
  rss: 3,
18
18
  etime: 4,
19
19
  command: 5,
20
- }
20
+ }.freeze
21
21
 
22
22
  def pid_alive?(pid)
23
23
  ::Process.kill(0, pid)
@@ -23,7 +23,7 @@ module Bluepill
23
23
  end
24
24
 
25
25
  def notify(_transition)
26
- fail 'Implement in subclass'
26
+ raise 'Implement in subclass'
27
27
  end
28
28
 
29
29
  def dispatch!(event)
@@ -1,9 +1,9 @@
1
1
  module Bluepill
2
2
  module Triggers
3
3
  class Flapping < Bluepill::Trigger
4
- TRIGGER_STATES = [:starting, :restarting]
4
+ TRIGGER_STATES = [:starting, :restarting].freeze
5
5
 
6
- PARAMS = [:times, :within, :retry_in]
6
+ PARAMS = [:times, :within, :retry_in].freeze
7
7
 
8
8
  attr_accessor(*PARAMS)
9
9
  attr_reader :timeline
@@ -13,7 +13,7 @@ module Bluepill
13
13
  shift if length > @capacity
14
14
  self
15
15
  end
16
- alias_method :<<, :push
16
+ alias << push
17
17
  end
18
18
  end
19
19
  end
@@ -14,7 +14,7 @@ module Bluepill
14
14
 
15
15
  # @return [Integer]
16
16
  def patch
17
- 2
17
+ 3
18
18
  end
19
19
 
20
20
  # @return [Integer, NilClass]
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.1.2
4
+ version: 0.1.3
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: 2016-06-19 00:00:00.000000000 Z
13
+ date: 2017-04-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '3.2'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '5'
24
+ version: '6'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,7 +31,7 @@ dependencies:
31
31
  version: '3.2'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '5'
34
+ version: '6'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: blue-daemons
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -145,9 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  requirements: []
147
147
  rubyforge_project:
148
- rubygems_version: 2.5.1
148
+ rubygems_version: 2.6.11
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: A process monitor written in Ruby with stability and minimalism in mind.
152
152
  test_files: []
153
- has_rdoc: