bluepill 0.2.9 → 0.3.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +100 -2
- data/README.md +12 -7
- data/bin/bluepill +8 -2
- data/bluepill.gemspec +1 -1
- data/lib/bluepill/application/lifecycle.rb +44 -34
- data/lib/bluepill/application/listener.rb +1 -1
- data/lib/bluepill/application/previous_daemon.rb +12 -14
- data/lib/bluepill/application.rb +33 -29
- data/lib/bluepill/base_directory.rb +18 -20
- data/lib/bluepill/check_registry.rb +104 -0
- data/lib/bluepill/clock.rb +1 -3
- data/lib/bluepill/condition_watch.rb +45 -54
- data/lib/bluepill/controller/directory.rb +1 -3
- data/lib/bluepill/controller.rb +32 -37
- data/lib/bluepill/dsl/app_proxy.rb +68 -64
- data/lib/bluepill/dsl/attributes.rb +135 -0
- data/lib/bluepill/dsl/process_factory/child_factory.rb +80 -0
- data/lib/bluepill/dsl/process_factory/registry.rb +6 -26
- data/lib/bluepill/dsl/process_factory.rb +83 -84
- data/lib/bluepill/dsl/process_proxy.rb +61 -168
- data/lib/bluepill/dsl.rb +16 -15
- data/lib/bluepill/errors.rb +190 -0
- data/lib/bluepill/group.rb +14 -37
- data/lib/bluepill/logger.rb +55 -97
- data/lib/bluepill/process/attributes.rb +66 -32
- data/lib/bluepill/process/children.rb +4 -6
- data/lib/bluepill/process/pid.rb +41 -35
- data/lib/bluepill/process/state_machine.rb +15 -59
- data/lib/bluepill/process/stop_signals.rb +120 -0
- data/lib/bluepill/process/transition.rb +1 -3
- data/lib/bluepill/process/transition_callbacks.rb +2 -16
- data/lib/bluepill/process/triggers.rb +90 -0
- data/lib/bluepill/process/user_commands.rb +1 -1
- data/lib/bluepill/process/watches.rb +9 -23
- data/lib/bluepill/process.rb +55 -52
- data/lib/bluepill/process_commands/execution.rb +14 -22
- data/lib/bluepill/process_commands/hooks.rb +1 -31
- data/lib/bluepill/process_commands/stop_signals.rb +12 -17
- data/lib/bluepill/process_commands.rb +10 -8
- data/lib/bluepill/process_conditions/always_true.rb +2 -6
- data/lib/bluepill/process_conditions/below_threshold.rb +6 -8
- data/lib/bluepill/process_conditions/cpu_usage.rb +1 -4
- data/lib/bluepill/process_conditions/file_time.rb +8 -9
- data/lib/bluepill/process_conditions/http.rb +28 -67
- data/lib/bluepill/process_conditions/mem_usage.rb +7 -45
- data/lib/bluepill/process_conditions/process_condition.rb +29 -47
- data/lib/bluepill/process_conditions/zombie_process.rb +2 -6
- data/lib/bluepill/process_conditions.rb +5 -14
- data/lib/bluepill/process_journal/cleanup.rb +5 -53
- data/lib/bluepill/process_journal/config.rb +73 -0
- data/lib/bluepill/process_journal/entries.rb +128 -0
- data/lib/bluepill/process_journal/journal.rb +69 -0
- data/lib/bluepill/process_journal/kind.rb +60 -0
- data/lib/bluepill/process_journal/lock.rb +9 -4
- data/lib/bluepill/process_journal.rb +13 -324
- data/lib/bluepill/process_statistics.rb +3 -7
- data/lib/bluepill/socket.rb +19 -17
- data/lib/bluepill/system/command_options.rb +135 -0
- data/lib/bluepill/system/command_result.rb +73 -0
- data/lib/bluepill/system/command_setup.rb +3 -4
- data/lib/bluepill/system/commands.rb +21 -18
- data/lib/bluepill/system/daemon.rb +19 -14
- data/lib/bluepill/system/files.rb +35 -0
- data/lib/bluepill/system/ps.rb +20 -17
- data/lib/bluepill/system/ps_table.rb +7 -9
- data/lib/bluepill/system/usage.rb +155 -0
- data/lib/bluepill/system.rb +7 -192
- data/lib/bluepill/trigger.rb +18 -69
- data/lib/bluepill/triggers/flapping.rb +12 -8
- data/lib/bluepill/units.rb +7 -21
- data/lib/bluepill/version.rb +12 -22
- data/lib/bluepill.rb +1 -1
- data/sig/bluepill/application.rbs +11 -12
- data/sig/bluepill/attributes.rbs +48 -0
- data/sig/bluepill/checks.rbs +40 -40
- data/sig/bluepill/dsl.rbs +97 -60
- data/sig/bluepill/errors.rbs +48 -0
- data/sig/bluepill/logger.rbs +15 -31
- data/sig/bluepill/process.rbs +39 -305
- data/sig/bluepill/process_commands.rbs +235 -0
- data/sig/bluepill/stop_signals.rbs +21 -0
- data/sig/bluepill/system.rbs +154 -99
- data/sig/bluepill/version.rbs +17 -0
- data/sig/bluepill.rbs +1 -17
- data/sig/manifest.yaml +1 -0
- metadata +21 -8
- data/lib/bluepill/deprecation/custom_checks.rb +0 -193
- data/lib/bluepill/deprecation/dsl.rb +0 -141
- data/lib/bluepill/deprecation/options.rb +0 -140
- data/lib/bluepill/deprecation.rb +0 -92
- data/lib/bluepill/dsl/process_factory/children.rb +0 -99
- data/sig/bluepill/deprecation.rbs +0 -87
|
@@ -4,8 +4,9 @@ module Bluepill
|
|
|
4
4
|
# The paths in bluepill's base directory
|
|
5
5
|
#
|
|
6
6
|
# The daemons' sockets are in socks, and their pid files are in pids,
|
|
7
|
-
# next to a directory for each application's processes. The
|
|
8
|
-
#
|
|
7
|
+
# next to a directory for each application's processes. The journals of
|
|
8
|
+
# the processes bluepill starts are in journals. The CLI and the daemon
|
|
9
|
+
# both find them here.
|
|
9
10
|
#
|
|
10
11
|
# @api private
|
|
11
12
|
class BaseDirectory
|
|
@@ -28,27 +29,30 @@ module Bluepill
|
|
|
28
29
|
# @return [void]
|
|
29
30
|
#
|
|
30
31
|
# @api private
|
|
31
|
-
def initialize(path)
|
|
32
|
-
@path = path
|
|
33
|
-
end
|
|
32
|
+
def initialize(path) = @path = path
|
|
34
33
|
|
|
35
34
|
# Return the directory with the daemons' sockets
|
|
36
35
|
#
|
|
37
36
|
# @return [String]
|
|
38
37
|
#
|
|
39
38
|
# @api private
|
|
40
|
-
def sockets_dir
|
|
41
|
-
File.join(path, "socks")
|
|
42
|
-
end
|
|
39
|
+
def sockets_dir = File.join(path, "socks")
|
|
43
40
|
|
|
44
41
|
# Return the directory with the daemons' pid files
|
|
45
42
|
#
|
|
46
43
|
# @return [String]
|
|
47
44
|
#
|
|
48
45
|
# @api private
|
|
49
|
-
def pids_dir
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
def pids_dir = File.join(path, "pids")
|
|
47
|
+
|
|
48
|
+
# Return the directory with the journals of the processes bluepill starts
|
|
49
|
+
#
|
|
50
|
+
# Each application's are in a directory of their own in it.
|
|
51
|
+
#
|
|
52
|
+
# @return [String]
|
|
53
|
+
#
|
|
54
|
+
# @api private
|
|
55
|
+
def journals_dir = File.join(path, "journals")
|
|
52
56
|
|
|
53
57
|
# Return the socket that an application's daemon listens on
|
|
54
58
|
#
|
|
@@ -57,9 +61,7 @@ module Bluepill
|
|
|
57
61
|
# @return [String]
|
|
58
62
|
#
|
|
59
63
|
# @api private
|
|
60
|
-
def socket_file(app)
|
|
61
|
-
File.join(sockets_dir, "#{app}#{SOCKET_EXTENSION}")
|
|
62
|
-
end
|
|
64
|
+
def socket_file(app) = File.join(sockets_dir, "#{app}#{SOCKET_EXTENSION}")
|
|
63
65
|
|
|
64
66
|
# Return an application's daemon's pid file
|
|
65
67
|
#
|
|
@@ -68,9 +70,7 @@ module Bluepill
|
|
|
68
70
|
# @return [String]
|
|
69
71
|
#
|
|
70
72
|
# @api private
|
|
71
|
-
def pid_file(app)
|
|
72
|
-
File.join(pids_dir, "#{app}.pid")
|
|
73
|
-
end
|
|
73
|
+
def pid_file(app) = File.join(pids_dir, "#{app}.pid")
|
|
74
74
|
|
|
75
75
|
# Return the directory with the pid files of an application's processes
|
|
76
76
|
#
|
|
@@ -79,9 +79,7 @@ module Bluepill
|
|
|
79
79
|
# @return [String]
|
|
80
80
|
#
|
|
81
81
|
# @api private
|
|
82
|
-
def process_pids_dir(app)
|
|
83
|
-
File.join(pids_dir, app)
|
|
84
|
-
end
|
|
82
|
+
def process_pids_dir(app) = File.join(pids_dir, app)
|
|
85
83
|
|
|
86
84
|
# Return the names of the applications with a socket
|
|
87
85
|
#
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "did_you_mean"
|
|
4
|
+
|
|
5
|
+
module Bluepill
|
|
6
|
+
# The checks and triggers a config can name, by their underscored class
|
|
7
|
+
# names
|
|
8
|
+
#
|
|
9
|
+
# Every subclass of ProcessConditions::ProcessCondition and of Trigger
|
|
10
|
+
# adds itself when it's defined, in whatever module, so `checks
|
|
11
|
+
# :log_size` finds a LogSize class anywhere. When two classes have the
|
|
12
|
+
# same name, the one defined last wins.
|
|
13
|
+
#
|
|
14
|
+
# @api private
|
|
15
|
+
module CheckRegistry
|
|
16
|
+
# Each class, newest first, with the class it builds on and the methods
|
|
17
|
+
# it must define
|
|
18
|
+
@entries = [] #: Array[[Class, Class, Array[Symbol]]]
|
|
19
|
+
|
|
20
|
+
# Add a check or trigger class
|
|
21
|
+
#
|
|
22
|
+
# @param [Class] klass the class
|
|
23
|
+
# @param [Class] base ProcessConditions::ProcessCondition or Trigger
|
|
24
|
+
# @param [Array<Symbol>] required the methods of the base that the class
|
|
25
|
+
# must define
|
|
26
|
+
#
|
|
27
|
+
# @return [void]
|
|
28
|
+
#
|
|
29
|
+
# @api private
|
|
30
|
+
def self.add(klass, base, required) = @entries.unshift([klass, base, required])
|
|
31
|
+
|
|
32
|
+
# Return the check or trigger class a config names
|
|
33
|
+
#
|
|
34
|
+
# @param [Symbol, String] name the underscored name, such as :mem_usage
|
|
35
|
+
#
|
|
36
|
+
# @return [Class] the ProcessConditions::ProcessCondition or Trigger
|
|
37
|
+
# subclass
|
|
38
|
+
#
|
|
39
|
+
# @raise [ConfigError] when no class has the name, or the class doesn't
|
|
40
|
+
# define the methods a check or trigger needs
|
|
41
|
+
#
|
|
42
|
+
# @api private
|
|
43
|
+
def self.fetch(name)
|
|
44
|
+
key = name.to_s
|
|
45
|
+
entry = @entries.detect { |klass, _, _| check_name(klass).eql?(key) }
|
|
46
|
+
raise ConfigError, unknown_message(key) unless entry
|
|
47
|
+
|
|
48
|
+
klass, base, required = entry
|
|
49
|
+
missing = missing_methods(klass, base, required)
|
|
50
|
+
return klass if missing.empty?
|
|
51
|
+
|
|
52
|
+
raise ConfigError, "#{klass}, the class of check '#{key}', must define #{missing.join(" and ")}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Return the names a config can use, for suggestions
|
|
56
|
+
#
|
|
57
|
+
# @return [Array<String>] the name of every class that defines the
|
|
58
|
+
# methods it needs
|
|
59
|
+
#
|
|
60
|
+
# @api private
|
|
61
|
+
def self.names
|
|
62
|
+
@entries.filter_map { |klass, base, required| check_name(klass) if missing_methods(klass, base, required).empty? }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Return the name a config uses for a class
|
|
66
|
+
#
|
|
67
|
+
# @param [Class] klass the class
|
|
68
|
+
#
|
|
69
|
+
# @return [String, nil] its underscored name without its modules, such
|
|
70
|
+
# as "mem_usage", or nil for a class without a name
|
|
71
|
+
#
|
|
72
|
+
# @api private
|
|
73
|
+
def self.check_name(klass)
|
|
74
|
+
class_name = klass.name
|
|
75
|
+
Util.underscore(class_name.rpartition("::").last) if class_name
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Return the methods a class must define and doesn't
|
|
79
|
+
#
|
|
80
|
+
# @param [Class] klass the class
|
|
81
|
+
# @param [Class] base the class it builds on
|
|
82
|
+
# @param [Array<Symbol>] required the methods it must define
|
|
83
|
+
#
|
|
84
|
+
# @return [Array<Symbol>] the methods it leaves to its base
|
|
85
|
+
#
|
|
86
|
+
# @api private
|
|
87
|
+
def self.missing_methods(klass, base, required)
|
|
88
|
+
required.select { |method| klass.instance_method(method).owner.equal?(base) }
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Return the message for a name no class has, with a suggestion
|
|
92
|
+
#
|
|
93
|
+
# @param [String] name the name
|
|
94
|
+
#
|
|
95
|
+
# @return [String]
|
|
96
|
+
#
|
|
97
|
+
# @api private
|
|
98
|
+
def self.unknown_message(name)
|
|
99
|
+
suggestion = DidYouMean::SpellChecker.new(dictionary: names).correct(name).first
|
|
100
|
+
message = "Unknown check '#{name}'"
|
|
101
|
+
suggestion ? "#{message}. Did you mean '#{suggestion}'?" : message
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
data/lib/bluepill/clock.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "bluepill/check_registry"
|
|
3
4
|
require "bluepill/util/log_error"
|
|
4
5
|
|
|
5
6
|
module Bluepill
|
|
@@ -22,18 +23,17 @@ module Bluepill
|
|
|
22
23
|
#
|
|
23
24
|
# @api private
|
|
24
25
|
#
|
|
25
|
-
# @!attribute
|
|
26
|
-
# Return whether the value
|
|
26
|
+
# @!attribute passed
|
|
27
|
+
# Return whether the value passed the check
|
|
27
28
|
#
|
|
28
|
-
# It's
|
|
29
|
-
# counts toward the watch firing.
|
|
29
|
+
# It's false for a value that counts toward the watch firing.
|
|
30
30
|
#
|
|
31
31
|
# @return [Boolean] whether the value passed the check
|
|
32
32
|
#
|
|
33
33
|
# @api private
|
|
34
34
|
#
|
|
35
35
|
# @api private
|
|
36
|
-
HistoryValue = Struct.new(:value, :
|
|
36
|
+
HistoryValue = Struct.new(:value, :passed)
|
|
37
37
|
|
|
38
38
|
# Return the logger the watch writes its history to
|
|
39
39
|
#
|
|
@@ -56,77 +56,70 @@ module Bluepill
|
|
|
56
56
|
# @api private
|
|
57
57
|
EMPTY_ARRAY = no_events.freeze
|
|
58
58
|
|
|
59
|
-
# The options the watch takes for itself, which the check doesn't get
|
|
60
|
-
#
|
|
61
|
-
# @api private
|
|
62
|
-
WATCH_KEYS = %i[logger fires every times include_children].freeze
|
|
63
|
-
|
|
64
59
|
# Create a watch of a check
|
|
65
60
|
#
|
|
66
61
|
# @param [Symbol] name the check's name, such as :mem_usage
|
|
67
|
-
# @param [
|
|
68
|
-
#
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
#
|
|
62
|
+
# @param [Logger, nil] logger the logger to write to
|
|
63
|
+
# @param [Symbol, Array<Symbol>, nil] fires the events to fire when the
|
|
64
|
+
# check fails
|
|
65
|
+
# @param [Integer, nil] every the seconds between runs
|
|
66
|
+
# @param [Integer, Array<Integer>] times how many of the last values must
|
|
67
|
+
# fail, as a count or as [count, of]
|
|
68
|
+
# @param [Boolean] include_children whether to count the process's
|
|
69
|
+
# children too
|
|
70
|
+
# @param [Hash{Symbol => Object}] condition_options the check's own
|
|
71
|
+
# options, such as below: 100.megabytes
|
|
72
72
|
#
|
|
73
73
|
# @return [void]
|
|
74
74
|
#
|
|
75
|
+
# @raise [ConfigError] for an event a check can't fire
|
|
76
|
+
#
|
|
75
77
|
# @api private
|
|
76
|
-
def initialize(name,
|
|
78
|
+
def initialize(name, logger: nil, fires: :restart, every: nil, times: 1, include_children: false, **condition_options)
|
|
77
79
|
@name = name
|
|
78
|
-
@logger =
|
|
79
|
-
@fires = Array(
|
|
80
|
-
@every =
|
|
80
|
+
@logger = logger
|
|
81
|
+
@fires = events_to_fire(Array(fires))
|
|
82
|
+
@every = every
|
|
81
83
|
# times: 5 means 5 of the last 5, and times: [3, 5] 3 of the last 5
|
|
82
|
-
times = Array(
|
|
84
|
+
times = Array(times) #: Array[Integer]
|
|
83
85
|
@required = times.first #: Integer
|
|
84
86
|
@window = times.last #: Integer
|
|
85
|
-
@include_children =
|
|
87
|
+
@include_children = include_children
|
|
86
88
|
clear_history!
|
|
87
|
-
create_condition(
|
|
89
|
+
create_condition(condition_options)
|
|
88
90
|
end
|
|
89
91
|
|
|
90
|
-
#
|
|
91
|
-
#
|
|
92
|
-
# It first warns about the options that bluepill 0.3.0 rejects.
|
|
92
|
+
# Return the events a check fires, if each is one a process takes
|
|
93
93
|
#
|
|
94
|
-
#
|
|
95
|
-
# initialize can log, and again after, in case that initialize doesn't
|
|
96
|
-
# call super. It gets its options as keyword arguments, which an
|
|
97
|
-
# initialize that takes an options Hash gets as the Hash, so a custom
|
|
98
|
-
# check can take them either way, as bluepill 0.3.0's need keywords.
|
|
94
|
+
# @param [Array<Object>] events what fires: names
|
|
99
95
|
#
|
|
100
|
-
# @
|
|
101
|
-
# created with, which stay as they are
|
|
96
|
+
# @return [Array<Symbol>] the events
|
|
102
97
|
#
|
|
103
|
-
# @
|
|
98
|
+
# @raise [ConfigError] for an event that isn't one of
|
|
99
|
+
# Process::StateMachine::TRANSITIONS
|
|
104
100
|
#
|
|
105
101
|
# @api private
|
|
106
|
-
def
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
Deprecation.check_logger(@process_condition, @logger)
|
|
114
|
-
self.logger = @logger
|
|
102
|
+
def events_to_fire(events)
|
|
103
|
+
known = Process::StateMachine::TRANSITIONS.keys
|
|
104
|
+
unknown = events - known
|
|
105
|
+
return events if unknown.empty?
|
|
106
|
+
|
|
107
|
+
raise ConfigError, "#{@name} can't fire #{unknown.collect(&:inspect).join(", ")}: " \
|
|
108
|
+
"a check fires #{known.collect(&:inspect).join(", ")}"
|
|
115
109
|
end
|
|
116
110
|
|
|
117
|
-
#
|
|
111
|
+
# Create the check, with the options the watch doesn't take for itself
|
|
118
112
|
#
|
|
119
|
-
# The
|
|
120
|
-
#
|
|
113
|
+
# The condition gets the watch's logger as its logger: option, so its
|
|
114
|
+
# own initialize can log once it has called super.
|
|
121
115
|
#
|
|
122
|
-
# @param [
|
|
116
|
+
# @param [Hash{Symbol => Object}] options the check's own options
|
|
123
117
|
#
|
|
124
118
|
# @return [void]
|
|
125
119
|
#
|
|
126
120
|
# @api private
|
|
127
|
-
def
|
|
128
|
-
@
|
|
129
|
-
@process_condition.logger = logger
|
|
121
|
+
def create_condition(options)
|
|
122
|
+
@process_condition = CheckRegistry.fetch(@name).new(**options, logger: @logger)
|
|
130
123
|
end
|
|
131
124
|
|
|
132
125
|
# Return whether the check is due
|
|
@@ -183,7 +176,7 @@ module Bluepill
|
|
|
183
176
|
@history << HistoryValue.new(@process_condition.format_value(value), @process_condition.check?(value))
|
|
184
177
|
logger.info(to_s)
|
|
185
178
|
# Fire when enough of the values in the window failed
|
|
186
|
-
return @fires if @history.count { |v| !v.
|
|
179
|
+
return @fires if @history.count { |v| !v.passed } >= @required
|
|
187
180
|
|
|
188
181
|
EMPTY_ARRAY
|
|
189
182
|
rescue => e
|
|
@@ -215,9 +208,7 @@ module Bluepill
|
|
|
215
208
|
# @return [Util::RotationalArray<HistoryValue>] the new, empty history
|
|
216
209
|
#
|
|
217
210
|
# @api private
|
|
218
|
-
def clear_history!
|
|
219
|
-
@history = Util::RotationalArray.new(@window)
|
|
220
|
-
end
|
|
211
|
+
def clear_history! = @history = Util::RotationalArray.new(@window)
|
|
221
212
|
|
|
222
213
|
# Return the check's name and history, as the log shows it
|
|
223
214
|
#
|
|
@@ -226,7 +217,7 @@ module Bluepill
|
|
|
226
217
|
#
|
|
227
218
|
# @api private
|
|
228
219
|
def to_s
|
|
229
|
-
data = @history.collect { |v| "#{v.value}#{"*" unless v.
|
|
220
|
+
data = @history.collect { |v| "#{v.value}#{"*" unless v.passed}" }.join(", ")
|
|
230
221
|
"#{@name}: [#{data}]\n"
|
|
231
222
|
end
|
|
232
223
|
end
|
data/lib/bluepill/controller.rb
CHANGED
|
@@ -54,14 +54,17 @@ module Bluepill
|
|
|
54
54
|
# It creates the sockets and pids directories, and removes the socket
|
|
55
55
|
# and pid file of each daemon that's no longer running.
|
|
56
56
|
#
|
|
57
|
-
# @param [
|
|
57
|
+
# @param [String] base_dir the directory with the daemons' sockets and
|
|
58
|
+
# pid files
|
|
59
|
+
# @param [String, nil] log_file the log file to tail when a daemon names
|
|
60
|
+
# none
|
|
58
61
|
#
|
|
59
62
|
# @return [void]
|
|
60
63
|
#
|
|
61
64
|
# @api private
|
|
62
|
-
def initialize(
|
|
63
|
-
self.log_file =
|
|
64
|
-
self.base_dir =
|
|
65
|
+
def initialize(base_dir:, log_file: nil)
|
|
66
|
+
self.log_file = log_file
|
|
67
|
+
self.base_dir = base_dir
|
|
65
68
|
@base_directory = BaseDirectory.new(base_dir)
|
|
66
69
|
|
|
67
70
|
setup_dir_structure
|
|
@@ -72,7 +75,7 @@ module Bluepill
|
|
|
72
75
|
#
|
|
73
76
|
# status prints the daemon's status, quit stops the daemon, log tails
|
|
74
77
|
# the log for a process or group, and the PROCESS_COMMANDS go to the
|
|
75
|
-
# daemon.
|
|
78
|
+
# daemon.
|
|
76
79
|
#
|
|
77
80
|
# @param [String] application the application's name
|
|
78
81
|
# @param [String, Symbol] command the command
|
|
@@ -80,6 +83,10 @@ module Bluepill
|
|
|
80
83
|
#
|
|
81
84
|
# @return [void]
|
|
82
85
|
#
|
|
86
|
+
# @raise [UnknownCommandError] for an unknown command
|
|
87
|
+
# @raise [Bluepill::Error] if the daemon can't be reached, runs another
|
|
88
|
+
# version, or answers with an error
|
|
89
|
+
#
|
|
83
90
|
# @api private
|
|
84
91
|
def handle_command(application, command, *args)
|
|
85
92
|
case command.to_sym
|
|
@@ -96,9 +103,7 @@ module Bluepill
|
|
|
96
103
|
|
|
97
104
|
# Send a command to an application's daemon, and return its answer
|
|
98
105
|
#
|
|
99
|
-
# It first checks that the daemon runs this version of bluepill.
|
|
100
|
-
# prints an error that the daemon raised and exits with status 8, and
|
|
101
|
-
# aborts if the daemon isn't running.
|
|
106
|
+
# It first checks that the daemon runs this version of bluepill.
|
|
102
107
|
#
|
|
103
108
|
# @param [String] application the application's name
|
|
104
109
|
# @param [String, Symbol] command the command
|
|
@@ -106,16 +111,22 @@ module Bluepill
|
|
|
106
111
|
#
|
|
107
112
|
# @return [Object] what the daemon answered
|
|
108
113
|
#
|
|
114
|
+
# @raise [ConnectionError] if the daemon isn't running, or doesn't
|
|
115
|
+
# answer
|
|
116
|
+
# @raise [VersionMismatchError] if it runs another version
|
|
117
|
+
# @raise [DaemonError] if it answers with an error that it raised
|
|
118
|
+
#
|
|
109
119
|
# @api private
|
|
110
120
|
def send_to_daemon(application, command, *args)
|
|
111
121
|
verify_version!(application)
|
|
112
122
|
|
|
113
123
|
command = [command, *args].join(":")
|
|
114
124
|
response = Socket.client_command(base_dir, application, command)
|
|
115
|
-
|
|
125
|
+
raise DaemonError, response if response.is_a?(Exception)
|
|
126
|
+
|
|
116
127
|
response
|
|
117
128
|
rescue Errno::ECONNREFUSED
|
|
118
|
-
|
|
129
|
+
raise ConnectionError, "Connection Refused: Server is not running"
|
|
119
130
|
end
|
|
120
131
|
|
|
121
132
|
# Return the pattern that finds a process or group's lines in the log
|
|
@@ -171,19 +182,18 @@ module Bluepill
|
|
|
171
182
|
|
|
172
183
|
# Send one of the PROCESS_COMMANDS to the daemon and print what it did
|
|
173
184
|
#
|
|
174
|
-
# It exits with status 1 for any other command.
|
|
175
|
-
#
|
|
176
185
|
# @param [String] application the application's name
|
|
177
186
|
# @param [String, Symbol] command the command
|
|
178
187
|
# @param [Array<String>] args the group or process, for example
|
|
179
188
|
#
|
|
180
189
|
# @return [void]
|
|
181
190
|
#
|
|
191
|
+
# @raise [UnknownCommandError] for any other command
|
|
192
|
+
#
|
|
182
193
|
# @api private
|
|
183
194
|
def send_process_command(application, command, *args)
|
|
184
195
|
unless Application::PROCESS_COMMANDS.include?(command.to_sym)
|
|
185
|
-
|
|
186
|
-
exit(1)
|
|
196
|
+
raise UnknownCommandError, format("Unknown command `%s` (or application `%s` has not been loaded yet)", command, command)
|
|
187
197
|
end
|
|
188
198
|
|
|
189
199
|
# these need to be sent to the daemon and the results printed out
|
|
@@ -209,40 +219,25 @@ module Bluepill
|
|
|
209
219
|
end
|
|
210
220
|
end
|
|
211
221
|
|
|
212
|
-
#
|
|
213
|
-
#
|
|
214
|
-
# @param [Exception] error the error
|
|
222
|
+
# Check that an application's daemon runs this version of bluepill
|
|
215
223
|
#
|
|
216
|
-
#
|
|
217
|
-
#
|
|
218
|
-
# @api private
|
|
219
|
-
def exit_with_daemon_error(error)
|
|
220
|
-
$stderr.puts "Received error from server:"
|
|
221
|
-
$stderr.puts error.inspect
|
|
222
|
-
# join flattens the backtrace and makes a missing one empty
|
|
223
|
-
$stderr.puts [error.backtrace].join("\n")
|
|
224
|
-
exit(8)
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
# Abort unless an application's daemon runs this version of bluepill
|
|
228
|
-
#
|
|
229
|
-
# A daemon older than 0.2.9 answers with its Version module, which
|
|
230
|
-
# Marshal loads as the CLI's own, so it can't say which version it runs,
|
|
231
|
-
# and the CLI talks to it as before, with a warning, since bluepill
|
|
232
|
-
# 0.3.0's CLI refuses it.
|
|
224
|
+
# A daemon older than 0.3.0 answers with its Version module, which
|
|
225
|
+
# Marshal loads as the CLI's own, so it can't say which version it runs.
|
|
233
226
|
#
|
|
234
227
|
# @param [String] application the application's name
|
|
235
228
|
#
|
|
236
229
|
# @return [void]
|
|
237
230
|
#
|
|
231
|
+
# @raise [VersionMismatchError] if it runs another version
|
|
232
|
+
#
|
|
238
233
|
# @api private
|
|
239
234
|
def verify_version!(application)
|
|
240
235
|
version = Socket.client_command(base_dir, application, "version")
|
|
241
|
-
return
|
|
236
|
+
return if Version.to_s.eql?(version)
|
|
242
237
|
|
|
243
|
-
|
|
238
|
+
raise VersionMismatchError, version.instance_of?(String) ? "#{OUT_OF_DATE}\nDaemon Version: #{version}, CLI Version: #{Version}" : OUT_OF_DATE
|
|
244
239
|
rescue ArgumentError
|
|
245
|
-
|
|
240
|
+
raise VersionMismatchError, OUT_OF_DATE
|
|
246
241
|
end
|
|
247
242
|
end
|
|
248
243
|
end
|