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 +4 -4
- data/README.md +7 -3
- data/bin/bluepill +2 -2
- data/bin/sample_forking_server +1 -1
- data/bluepill.gemspec +1 -1
- data/lib/bluepill/application.rb +1 -1
- data/lib/bluepill/condition_watch.rb +2 -2
- data/lib/bluepill/controller.rb +1 -1
- data/lib/bluepill/dsl/app_proxy.rb +1 -1
- data/lib/bluepill/dsl/process_factory.rb +2 -2
- data/lib/bluepill/dsl/process_proxy.rb +1 -1
- data/lib/bluepill/logger.rb +2 -2
- data/lib/bluepill/process.rb +16 -16
- data/lib/bluepill/process_conditions/mem_usage.rb +4 -4
- data/lib/bluepill/process_conditions/process_condition.rb +2 -2
- data/lib/bluepill/process_journal.rb +2 -2
- data/lib/bluepill/system.rb +2 -2
- data/lib/bluepill/trigger.rb +1 -1
- data/lib/bluepill/triggers/flapping.rb +2 -2
- data/lib/bluepill/util/rotational_array.rb +1 -1
- data/lib/bluepill/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d38d93040875f0423d7d3f567cb2af3e7d1d0cbe
|
4
|
+
data.tar.gz: d30780afd0d7f3741a843e6ccccc318c8d34c634
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
###
|
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
|
|
data/bin/bluepill
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
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
|
|
data/bin/sample_forking_server
CHANGED
data/bluepill.gemspec
CHANGED
@@ -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', '<
|
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'
|
data/lib/bluepill/application.rb
CHANGED
@@ -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
|
-
|
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
|
37
|
+
return @fires if fired?
|
38
38
|
end
|
39
39
|
EMPTY_ARRAY
|
40
40
|
end
|
data/lib/bluepill/controller.rb
CHANGED
@@ -61,7 +61,7 @@ module Bluepill
|
|
61
61
|
def send_to_daemon(application, command, *args)
|
62
62
|
verify_version!(application)
|
63
63
|
|
64
|
-
command =
|
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:'
|
@@ -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
|
-
|
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
|
-
|
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.
|
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]
|
data/lib/bluepill/logger.rb
CHANGED
@@ -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]
|
data/lib/bluepill/process.rb
CHANGED
@@ -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
|
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
|
155
|
+
clean_threads if unmonitored?
|
156
156
|
|
157
157
|
# run state machine transitions
|
158
158
|
super
|
159
159
|
|
160
|
-
return unless
|
160
|
+
return unless up?
|
161
161
|
run_watches
|
162
162
|
|
163
|
-
return unless
|
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(
|
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
|
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
|
-
|
235
|
+
dispatch!(event, reason)
|
236
236
|
end
|
237
237
|
end
|
238
238
|
|
239
239
|
def determine_initial_state
|
240
|
-
if
|
240
|
+
if process_running?(true)
|
241
241
|
self.state = 'up'
|
242
|
-
|
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
|
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
|
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
|
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
|
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
|
5
|
-
FORMAT_STR = '%d%s'
|
6
|
-
MB_LABEL
|
7
|
-
KB_LABEL
|
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
|
-
|
9
|
+
raise 'Implement in subclass!'
|
10
10
|
end
|
11
11
|
|
12
12
|
def check(_value)
|
13
|
-
|
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.
|
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.
|
139
|
+
if !j.empty?
|
140
140
|
acquire_atomic_fs_lock(filename) do
|
141
141
|
j.each do |pid|
|
142
142
|
begin
|
data/lib/bluepill/system.rb
CHANGED
@@ -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)
|
data/lib/bluepill/trigger.rb
CHANGED
@@ -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
|
data/lib/bluepill/version.rb
CHANGED
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.
|
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:
|
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: '
|
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: '
|
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.
|
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:
|