overman 0.0.1 → 0.88.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +54 -0
- data/bin/foreman-runner +41 -0
- data/bin/overman +7 -0
- data/data/example/Procfile +4 -0
- data/data/example/Procfile.without_colon +2 -0
- data/data/example/error +7 -0
- data/data/example/log/neverdie.log +4 -0
- data/data/example/spawnee +14 -0
- data/data/example/spawner +7 -0
- data/data/example/ticker +14 -0
- data/data/example/utf8 +11 -0
- data/data/export/bluepill/master.pill.erb +28 -0
- data/data/export/daemon/master.conf.erb +14 -0
- data/data/export/daemon/process.conf.erb +8 -0
- data/data/export/daemon/process_master.conf.erb +2 -0
- data/data/export/launchd/launchd.plist.erb +33 -0
- data/data/export/runit/log/run.erb +7 -0
- data/data/export/runit/run.erb +4 -0
- data/data/export/supervisord/app.conf.erb +31 -0
- data/data/export/systemd/master.target.erb +5 -0
- data/data/export/systemd/process.service.erb +21 -0
- data/data/export/upstart/master.conf.erb +2 -0
- data/data/export/upstart/process.conf.erb +15 -0
- data/data/export/upstart/process_master.conf.erb +2 -0
- data/lib/foreman/cli.rb +167 -0
- data/lib/foreman/distribution.rb +9 -0
- data/lib/foreman/engine/cli.rb +105 -0
- data/lib/foreman/engine.rb +494 -0
- data/lib/foreman/env.rb +29 -0
- data/lib/foreman/export/base.rb +170 -0
- data/lib/foreman/export/bluepill.rb +12 -0
- data/lib/foreman/export/daemon.rb +28 -0
- data/lib/foreman/export/inittab.rb +42 -0
- data/lib/foreman/export/launchd.rb +22 -0
- data/lib/foreman/export/runit.rb +34 -0
- data/lib/foreman/export/supervisord.rb +16 -0
- data/lib/foreman/export/systemd.rb +34 -0
- data/lib/foreman/export/upstart.rb +46 -0
- data/lib/foreman/export.rb +36 -0
- data/lib/foreman/helpers.rb +45 -0
- data/lib/foreman/process.rb +81 -0
- data/lib/foreman/procfile.rb +100 -0
- data/lib/foreman/vendor/thor/lib/thor/actions/create_file.rb +103 -0
- data/lib/foreman/vendor/thor/lib/thor/actions/create_link.rb +59 -0
- data/lib/foreman/vendor/thor/lib/thor/actions/directory.rb +118 -0
- data/lib/foreman/vendor/thor/lib/thor/actions/empty_directory.rb +135 -0
- data/lib/foreman/vendor/thor/lib/thor/actions/file_manipulation.rb +327 -0
- data/lib/foreman/vendor/thor/lib/thor/actions/inject_into_file.rb +103 -0
- data/lib/foreman/vendor/thor/lib/thor/actions.rb +318 -0
- data/lib/foreman/vendor/thor/lib/thor/base.rb +656 -0
- data/lib/foreman/vendor/thor/lib/thor/command.rb +133 -0
- data/lib/foreman/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +85 -0
- data/lib/foreman/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
- data/lib/foreman/vendor/thor/lib/thor/core_ext/ordered_hash.rb +129 -0
- data/lib/foreman/vendor/thor/lib/thor/error.rb +32 -0
- data/lib/foreman/vendor/thor/lib/thor/group.rb +281 -0
- data/lib/foreman/vendor/thor/lib/thor/invocation.rb +177 -0
- data/lib/foreman/vendor/thor/lib/thor/line_editor/basic.rb +35 -0
- data/lib/foreman/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
- data/lib/foreman/vendor/thor/lib/thor/line_editor.rb +17 -0
- data/lib/foreman/vendor/thor/lib/thor/parser/argument.rb +70 -0
- data/lib/foreman/vendor/thor/lib/thor/parser/arguments.rb +175 -0
- data/lib/foreman/vendor/thor/lib/thor/parser/option.rb +146 -0
- data/lib/foreman/vendor/thor/lib/thor/parser/options.rb +220 -0
- data/lib/foreman/vendor/thor/lib/thor/parser.rb +4 -0
- data/lib/foreman/vendor/thor/lib/thor/rake_compat.rb +71 -0
- data/lib/foreman/vendor/thor/lib/thor/runner.rb +322 -0
- data/lib/foreman/vendor/thor/lib/thor/shell/basic.rb +436 -0
- data/lib/foreman/vendor/thor/lib/thor/shell/color.rb +149 -0
- data/lib/foreman/vendor/thor/lib/thor/shell/html.rb +126 -0
- data/lib/foreman/vendor/thor/lib/thor/shell.rb +81 -0
- data/lib/foreman/vendor/thor/lib/thor/util.rb +268 -0
- data/lib/foreman/vendor/thor/lib/thor/version.rb +3 -0
- data/lib/foreman/vendor/thor/lib/thor.rb +492 -0
- data/lib/foreman/version.rb +5 -0
- data/lib/foreman.rb +17 -0
- data/man/overman.1 +181 -0
- data/spec/foreman/cli_spec.rb +111 -0
- data/spec/foreman/engine_spec.rb +114 -0
- data/spec/foreman/export/base_spec.rb +19 -0
- data/spec/foreman/export/bluepill_spec.rb +37 -0
- data/spec/foreman/export/daemon_spec.rb +97 -0
- data/spec/foreman/export/inittab_spec.rb +40 -0
- data/spec/foreman/export/launchd_spec.rb +31 -0
- data/spec/foreman/export/runit_spec.rb +36 -0
- data/spec/foreman/export/supervisord_spec.rb +38 -0
- data/spec/foreman/export/systemd_spec.rb +155 -0
- data/spec/foreman/export/upstart_spec.rb +118 -0
- data/spec/foreman/export_spec.rb +24 -0
- data/spec/foreman/helpers_spec.rb +26 -0
- data/spec/foreman/process_spec.rb +70 -0
- data/spec/foreman/procfile_spec.rb +65 -0
- data/spec/foreman_spec.rb +16 -0
- data/spec/helper_spec.rb +19 -0
- data/spec/resources/Procfile +5 -0
- data/spec/resources/Procfile.bad +2 -0
- data/spec/resources/bin/echo +2 -0
- data/spec/resources/bin/env +2 -0
- data/spec/resources/bin/test +2 -0
- data/spec/resources/bin/utf8 +2 -0
- data/spec/resources/export/bluepill/app-concurrency.pill +49 -0
- data/spec/resources/export/bluepill/app.pill +81 -0
- data/spec/resources/export/daemon/app-alpha-1.conf +7 -0
- data/spec/resources/export/daemon/app-alpha-2.conf +7 -0
- data/spec/resources/export/daemon/app-alpha.conf +2 -0
- data/spec/resources/export/daemon/app-bravo-1.conf +7 -0
- data/spec/resources/export/daemon/app-bravo.conf +2 -0
- data/spec/resources/export/daemon/app.conf +14 -0
- data/spec/resources/export/inittab/inittab.concurrency +4 -0
- data/spec/resources/export/inittab/inittab.default +6 -0
- data/spec/resources/export/launchd/launchd-a.default +29 -0
- data/spec/resources/export/launchd/launchd-b.default +29 -0
- data/spec/resources/export/launchd/launchd-c.default +30 -0
- data/spec/resources/export/runit/app-alpha-1/log/run +7 -0
- data/spec/resources/export/runit/app-alpha-1/run +4 -0
- data/spec/resources/export/runit/app-alpha-2/log/run +7 -0
- data/spec/resources/export/runit/app-alpha-2/run +4 -0
- data/spec/resources/export/runit/app-bravo-1/log/run +7 -0
- data/spec/resources/export/runit/app-bravo-1/run +4 -0
- data/spec/resources/export/supervisord/app-alpha-1.conf +42 -0
- data/spec/resources/export/supervisord/app-alpha-2.conf +22 -0
- data/spec/resources/export/systemd/app-alpha.1.service +18 -0
- data/spec/resources/export/systemd/app-alpha.2.service +18 -0
- data/spec/resources/export/systemd/app-alpha.target +2 -0
- data/spec/resources/export/systemd/app-bravo.1.service +18 -0
- data/spec/resources/export/systemd/app-bravo.target +2 -0
- data/spec/resources/export/systemd/app.target +5 -0
- data/spec/resources/export/upstart/app-alpha-1.conf +11 -0
- data/spec/resources/export/upstart/app-alpha-2.conf +11 -0
- data/spec/resources/export/upstart/app-alpha.conf +2 -0
- data/spec/resources/export/upstart/app-bravo-1.conf +11 -0
- data/spec/resources/export/upstart/app-bravo.conf +2 -0
- data/spec/resources/export/upstart/app.conf +2 -0
- data/spec/spec_helper.rb +190 -0
- metadata +144 -16
- data/lib/overman/version.rb +0 -5
- data/lib/overman.rb +0 -1
@@ -0,0 +1,492 @@
|
|
1
|
+
require "set"
|
2
|
+
require "foreman/vendor/thor/lib/thor/base"
|
3
|
+
|
4
|
+
class Foreman::Thor
|
5
|
+
class << self
|
6
|
+
# Allows for custom "Command" package naming.
|
7
|
+
#
|
8
|
+
# === Parameters
|
9
|
+
# name<String>
|
10
|
+
# options<Hash>
|
11
|
+
#
|
12
|
+
def package_name(name, _ = {})
|
13
|
+
@package_name = name.nil? || name == "" ? nil : name
|
14
|
+
end
|
15
|
+
|
16
|
+
# Sets the default command when thor is executed without an explicit command to be called.
|
17
|
+
#
|
18
|
+
# ==== Parameters
|
19
|
+
# meth<Symbol>:: name of the default command
|
20
|
+
#
|
21
|
+
def default_command(meth = nil)
|
22
|
+
if meth
|
23
|
+
@default_command = meth == :none ? "help" : meth.to_s
|
24
|
+
else
|
25
|
+
@default_command ||= from_superclass(:default_command, "help")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
alias_method :default_task, :default_command
|
29
|
+
|
30
|
+
# Registers another Foreman::Thor subclass as a command.
|
31
|
+
#
|
32
|
+
# ==== Parameters
|
33
|
+
# klass<Class>:: Foreman::Thor subclass to register
|
34
|
+
# command<String>:: Subcommand name to use
|
35
|
+
# usage<String>:: Short usage for the subcommand
|
36
|
+
# description<String>:: Description for the subcommand
|
37
|
+
def register(klass, subcommand_name, usage, description, options = {})
|
38
|
+
if klass <= Foreman::Thor::Group
|
39
|
+
desc usage, description, options
|
40
|
+
define_method(subcommand_name) { |*args| invoke(klass, args) }
|
41
|
+
else
|
42
|
+
desc usage, description, options
|
43
|
+
subcommand subcommand_name, klass
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Defines the usage and the description of the next command.
|
48
|
+
#
|
49
|
+
# ==== Parameters
|
50
|
+
# usage<String>
|
51
|
+
# description<String>
|
52
|
+
# options<String>
|
53
|
+
#
|
54
|
+
def desc(usage, description, options = {})
|
55
|
+
if options[:for]
|
56
|
+
command = find_and_refresh_command(options[:for])
|
57
|
+
command.usage = usage if usage
|
58
|
+
command.description = description if description
|
59
|
+
else
|
60
|
+
@usage = usage
|
61
|
+
@desc = description
|
62
|
+
@hide = options[:hide] || false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Defines the long description of the next command.
|
67
|
+
#
|
68
|
+
# ==== Parameters
|
69
|
+
# long description<String>
|
70
|
+
#
|
71
|
+
def long_desc(long_description, options = {})
|
72
|
+
if options[:for]
|
73
|
+
command = find_and_refresh_command(options[:for])
|
74
|
+
command.long_description = long_description if long_description
|
75
|
+
else
|
76
|
+
@long_desc = long_description
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Maps an input to a command. If you define:
|
81
|
+
#
|
82
|
+
# map "-T" => "list"
|
83
|
+
#
|
84
|
+
# Running:
|
85
|
+
#
|
86
|
+
# thor -T
|
87
|
+
#
|
88
|
+
# Will invoke the list command.
|
89
|
+
#
|
90
|
+
# ==== Parameters
|
91
|
+
# Hash[String|Array => Symbol]:: Maps the string or the strings in the array to the given command.
|
92
|
+
#
|
93
|
+
def map(mappings = nil)
|
94
|
+
@map ||= from_superclass(:map, {})
|
95
|
+
|
96
|
+
if mappings
|
97
|
+
mappings.each do |key, value|
|
98
|
+
if key.respond_to?(:each)
|
99
|
+
key.each { |subkey| @map[subkey] = value }
|
100
|
+
else
|
101
|
+
@map[key] = value
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
@map
|
107
|
+
end
|
108
|
+
|
109
|
+
# Declares the options for the next command to be declared.
|
110
|
+
#
|
111
|
+
# ==== Parameters
|
112
|
+
# Hash[Symbol => Object]:: The hash key is the name of the option and the value
|
113
|
+
# is the type of the option. Can be :string, :array, :hash, :boolean, :numeric
|
114
|
+
# or :required (string). If you give a value, the type of the value is used.
|
115
|
+
#
|
116
|
+
def method_options(options = nil)
|
117
|
+
@method_options ||= {}
|
118
|
+
build_options(options, @method_options) if options
|
119
|
+
@method_options
|
120
|
+
end
|
121
|
+
|
122
|
+
alias_method :options, :method_options
|
123
|
+
|
124
|
+
# Adds an option to the set of method options. If :for is given as option,
|
125
|
+
# it allows you to change the options from a previous defined command.
|
126
|
+
#
|
127
|
+
# def previous_command
|
128
|
+
# # magic
|
129
|
+
# end
|
130
|
+
#
|
131
|
+
# method_option :foo => :bar, :for => :previous_command
|
132
|
+
#
|
133
|
+
# def next_command
|
134
|
+
# # magic
|
135
|
+
# end
|
136
|
+
#
|
137
|
+
# ==== Parameters
|
138
|
+
# name<Symbol>:: The name of the argument.
|
139
|
+
# options<Hash>:: Described below.
|
140
|
+
#
|
141
|
+
# ==== Options
|
142
|
+
# :desc - Description for the argument.
|
143
|
+
# :required - If the argument is required or not.
|
144
|
+
# :default - Default value for this argument. It cannot be required and have default values.
|
145
|
+
# :aliases - Aliases for this option.
|
146
|
+
# :type - The type of the argument, can be :string, :hash, :array, :numeric or :boolean.
|
147
|
+
# :banner - String to show on usage notes.
|
148
|
+
# :hide - If you want to hide this option from the help.
|
149
|
+
#
|
150
|
+
def method_option(name, options = {})
|
151
|
+
scope = if options[:for]
|
152
|
+
find_and_refresh_command(options[:for]).options
|
153
|
+
else
|
154
|
+
method_options
|
155
|
+
end
|
156
|
+
|
157
|
+
build_option(name, options, scope)
|
158
|
+
end
|
159
|
+
alias_method :option, :method_option
|
160
|
+
|
161
|
+
def disable_class_options
|
162
|
+
@disable_class_options = true
|
163
|
+
end
|
164
|
+
|
165
|
+
# Prints help information for the given command.
|
166
|
+
#
|
167
|
+
# ==== Parameters
|
168
|
+
# shell<Foreman::Thor::Shell>
|
169
|
+
# command_name<String>
|
170
|
+
#
|
171
|
+
def command_help(shell, command_name)
|
172
|
+
meth = normalize_command_name(command_name)
|
173
|
+
command = all_commands[meth]
|
174
|
+
handle_no_command_error(meth) unless command
|
175
|
+
|
176
|
+
shell.say "Usage:"
|
177
|
+
shell.say " #{banner(command)}"
|
178
|
+
shell.say
|
179
|
+
class_options_help(shell, nil => command.options.values)
|
180
|
+
if command.long_description
|
181
|
+
shell.say "Description:"
|
182
|
+
shell.print_wrapped(command.long_description, :indent => 2)
|
183
|
+
else
|
184
|
+
shell.say command.description
|
185
|
+
end
|
186
|
+
end
|
187
|
+
alias_method :task_help, :command_help
|
188
|
+
|
189
|
+
# Prints help information for this class.
|
190
|
+
#
|
191
|
+
# ==== Parameters
|
192
|
+
# shell<Foreman::Thor::Shell>
|
193
|
+
#
|
194
|
+
def help(shell, subcommand = false)
|
195
|
+
list = printable_commands(true, subcommand)
|
196
|
+
Foreman::Thor::Util.thor_classes_in(self).each do |klass|
|
197
|
+
list += klass.printable_commands(false)
|
198
|
+
end
|
199
|
+
list.sort! { |a, b| a[0] <=> b[0] }
|
200
|
+
|
201
|
+
if defined?(@package_name) && @package_name
|
202
|
+
shell.say "#{@package_name} commands:"
|
203
|
+
else
|
204
|
+
shell.say "Commands:"
|
205
|
+
end
|
206
|
+
|
207
|
+
shell.print_table(list, :indent => 2, :truncate => true)
|
208
|
+
shell.say
|
209
|
+
class_options_help(shell)
|
210
|
+
end
|
211
|
+
|
212
|
+
# Returns commands ready to be printed.
|
213
|
+
def printable_commands(all = true, subcommand = false)
|
214
|
+
(all ? all_commands : commands).map do |_, command|
|
215
|
+
next if command.hidden?
|
216
|
+
item = []
|
217
|
+
item << banner(command, false, subcommand)
|
218
|
+
item << (command.description ? "# #{command.description.gsub(/\s+/m, ' ')}" : "")
|
219
|
+
item
|
220
|
+
end.compact
|
221
|
+
end
|
222
|
+
alias_method :printable_tasks, :printable_commands
|
223
|
+
|
224
|
+
def subcommands
|
225
|
+
@subcommands ||= from_superclass(:subcommands, [])
|
226
|
+
end
|
227
|
+
alias_method :subtasks, :subcommands
|
228
|
+
|
229
|
+
def subcommand_classes
|
230
|
+
@subcommand_classes ||= {}
|
231
|
+
end
|
232
|
+
|
233
|
+
def subcommand(subcommand, subcommand_class)
|
234
|
+
subcommands << subcommand.to_s
|
235
|
+
subcommand_class.subcommand_help subcommand
|
236
|
+
subcommand_classes[subcommand.to_s] = subcommand_class
|
237
|
+
|
238
|
+
define_method(subcommand) do |*args|
|
239
|
+
args, opts = Foreman::Thor::Arguments.split(args)
|
240
|
+
invoke_args = [args, opts, {:invoked_via_subcommand => true, :class_options => options}]
|
241
|
+
invoke_args.unshift "help" if opts.delete("--help") || opts.delete("-h")
|
242
|
+
invoke subcommand_class, *invoke_args
|
243
|
+
end
|
244
|
+
end
|
245
|
+
alias_method :subtask, :subcommand
|
246
|
+
|
247
|
+
# Extend check unknown options to accept a hash of conditions.
|
248
|
+
#
|
249
|
+
# === Parameters
|
250
|
+
# options<Hash>: A hash containing :only and/or :except keys
|
251
|
+
def check_unknown_options!(options = {})
|
252
|
+
@check_unknown_options ||= {}
|
253
|
+
options.each do |key, value|
|
254
|
+
if value
|
255
|
+
@check_unknown_options[key] = Array(value)
|
256
|
+
else
|
257
|
+
@check_unknown_options.delete(key)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
@check_unknown_options
|
261
|
+
end
|
262
|
+
|
263
|
+
# Overwrite check_unknown_options? to take subcommands and options into account.
|
264
|
+
def check_unknown_options?(config) #:nodoc:
|
265
|
+
options = check_unknown_options
|
266
|
+
return false unless options
|
267
|
+
|
268
|
+
command = config[:current_command]
|
269
|
+
return true unless command
|
270
|
+
|
271
|
+
name = command.name
|
272
|
+
|
273
|
+
if subcommands.include?(name)
|
274
|
+
false
|
275
|
+
elsif options[:except]
|
276
|
+
!options[:except].include?(name.to_sym)
|
277
|
+
elsif options[:only]
|
278
|
+
options[:only].include?(name.to_sym)
|
279
|
+
else
|
280
|
+
true
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
# Stop parsing of options as soon as an unknown option or a regular
|
285
|
+
# argument is encountered. All remaining arguments are passed to the command.
|
286
|
+
# This is useful if you have a command that can receive arbitrary additional
|
287
|
+
# options, and where those additional options should not be handled by
|
288
|
+
# Foreman::Thor.
|
289
|
+
#
|
290
|
+
# ==== Example
|
291
|
+
#
|
292
|
+
# To better understand how this is useful, let's consider a command that calls
|
293
|
+
# an external command. A user may want to pass arbitrary options and
|
294
|
+
# arguments to that command. The command itself also accepts some options,
|
295
|
+
# which should be handled by Foreman::Thor.
|
296
|
+
#
|
297
|
+
# class_option "verbose", :type => :boolean
|
298
|
+
# stop_on_unknown_option! :exec
|
299
|
+
# check_unknown_options! :except => :exec
|
300
|
+
#
|
301
|
+
# desc "exec", "Run a shell command"
|
302
|
+
# def exec(*args)
|
303
|
+
# puts "diagnostic output" if options[:verbose]
|
304
|
+
# Kernel.exec(*args)
|
305
|
+
# end
|
306
|
+
#
|
307
|
+
# Here +exec+ can be called with +--verbose+ to get diagnostic output,
|
308
|
+
# e.g.:
|
309
|
+
#
|
310
|
+
# $ thor exec --verbose echo foo
|
311
|
+
# diagnostic output
|
312
|
+
# foo
|
313
|
+
#
|
314
|
+
# But if +--verbose+ is given after +echo+, it is passed to +echo+ instead:
|
315
|
+
#
|
316
|
+
# $ thor exec echo --verbose foo
|
317
|
+
# --verbose foo
|
318
|
+
#
|
319
|
+
# ==== Parameters
|
320
|
+
# Symbol ...:: A list of commands that should be affected.
|
321
|
+
def stop_on_unknown_option!(*command_names)
|
322
|
+
stop_on_unknown_option.merge(command_names)
|
323
|
+
end
|
324
|
+
|
325
|
+
def stop_on_unknown_option?(command) #:nodoc:
|
326
|
+
command && stop_on_unknown_option.include?(command.name.to_sym)
|
327
|
+
end
|
328
|
+
|
329
|
+
protected
|
330
|
+
|
331
|
+
def stop_on_unknown_option #:nodoc:
|
332
|
+
@stop_on_unknown_option ||= Set.new
|
333
|
+
end
|
334
|
+
|
335
|
+
# The method responsible for dispatching given the args.
|
336
|
+
def dispatch(meth, given_args, given_opts, config) #:nodoc: # rubocop:disable MethodLength
|
337
|
+
meth ||= retrieve_command_name(given_args)
|
338
|
+
command = all_commands[normalize_command_name(meth)]
|
339
|
+
|
340
|
+
if !command && config[:invoked_via_subcommand]
|
341
|
+
# We're a subcommand and our first argument didn't match any of our
|
342
|
+
# commands. So we put it back and call our default command.
|
343
|
+
given_args.unshift(meth)
|
344
|
+
command = all_commands[normalize_command_name(default_command)]
|
345
|
+
end
|
346
|
+
|
347
|
+
if command
|
348
|
+
args, opts = Foreman::Thor::Options.split(given_args)
|
349
|
+
if stop_on_unknown_option?(command) && !args.empty?
|
350
|
+
# given_args starts with a non-option, so we treat everything as
|
351
|
+
# ordinary arguments
|
352
|
+
args.concat opts
|
353
|
+
opts.clear
|
354
|
+
end
|
355
|
+
else
|
356
|
+
args = given_args
|
357
|
+
opts = nil
|
358
|
+
command = dynamic_command_class.new(meth)
|
359
|
+
end
|
360
|
+
|
361
|
+
opts = given_opts || opts || []
|
362
|
+
config[:current_command] = command
|
363
|
+
config[:command_options] = command.options
|
364
|
+
|
365
|
+
instance = new(args, opts, config)
|
366
|
+
yield instance if block_given?
|
367
|
+
args = instance.args
|
368
|
+
trailing = args[Range.new(arguments.size, -1)]
|
369
|
+
instance.invoke_command(command, trailing || [])
|
370
|
+
end
|
371
|
+
|
372
|
+
# The banner for this class. You can customize it if you are invoking the
|
373
|
+
# thor class by another ways which is not the Foreman::Thor::Runner. It receives
|
374
|
+
# the command that is going to be invoked and a boolean which indicates if
|
375
|
+
# the namespace should be displayed as arguments.
|
376
|
+
#
|
377
|
+
def banner(command, namespace = nil, subcommand = false)
|
378
|
+
"#{basename} #{command.formatted_usage(self, $thor_runner, subcommand)}"
|
379
|
+
end
|
380
|
+
|
381
|
+
def baseclass #:nodoc:
|
382
|
+
Foreman::Thor
|
383
|
+
end
|
384
|
+
|
385
|
+
def dynamic_command_class #:nodoc:
|
386
|
+
Foreman::Thor::DynamicCommand
|
387
|
+
end
|
388
|
+
|
389
|
+
def create_command(meth) #:nodoc:
|
390
|
+
@usage ||= nil
|
391
|
+
@desc ||= nil
|
392
|
+
@long_desc ||= nil
|
393
|
+
@disable_class_options ||= nil
|
394
|
+
|
395
|
+
if @usage && @desc
|
396
|
+
base_class = @hide ? Foreman::Thor::HiddenCommand : Foreman::Thor::Command
|
397
|
+
commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options, @disable_class_options)
|
398
|
+
@usage, @desc, @long_desc, @method_options, @hide, @disable_class_options = nil
|
399
|
+
true
|
400
|
+
elsif all_commands[meth] || meth == "method_missing"
|
401
|
+
true
|
402
|
+
else
|
403
|
+
puts "[WARNING] Attempted to create command #{meth.inspect} without usage or description. " \
|
404
|
+
"Call desc if you want this method to be available as command or declare it inside a " \
|
405
|
+
"no_commands{} block. Invoked from #{caller[1].inspect}."
|
406
|
+
false
|
407
|
+
end
|
408
|
+
end
|
409
|
+
alias_method :create_task, :create_command
|
410
|
+
|
411
|
+
def initialize_added #:nodoc:
|
412
|
+
class_options.merge!(method_options)
|
413
|
+
@method_options = nil
|
414
|
+
end
|
415
|
+
|
416
|
+
# Retrieve the command name from given args.
|
417
|
+
def retrieve_command_name(args) #:nodoc:
|
418
|
+
meth = args.first.to_s unless args.empty?
|
419
|
+
args.shift if meth && (map[meth] || meth !~ /^\-/)
|
420
|
+
end
|
421
|
+
alias_method :retrieve_task_name, :retrieve_command_name
|
422
|
+
|
423
|
+
# receives a (possibly nil) command name and returns a name that is in
|
424
|
+
# the commands hash. In addition to normalizing aliases, this logic
|
425
|
+
# will determine if a shortened command is an unambiguous substring of
|
426
|
+
# a command or alias.
|
427
|
+
#
|
428
|
+
# +normalize_command_name+ also converts names like +animal-prison+
|
429
|
+
# into +animal_prison+.
|
430
|
+
def normalize_command_name(meth) #:nodoc:
|
431
|
+
return default_command.to_s.tr("-", "_") unless meth
|
432
|
+
|
433
|
+
possibilities = find_command_possibilities(meth)
|
434
|
+
raise AmbiguousTaskError, "Ambiguous command #{meth} matches [#{possibilities.join(', ')}]" if possibilities.size > 1
|
435
|
+
|
436
|
+
if possibilities.empty?
|
437
|
+
meth ||= default_command
|
438
|
+
elsif map[meth]
|
439
|
+
meth = map[meth]
|
440
|
+
else
|
441
|
+
meth = possibilities.first
|
442
|
+
end
|
443
|
+
|
444
|
+
meth.to_s.tr("-", "_") # treat foo-bar as foo_bar
|
445
|
+
end
|
446
|
+
alias_method :normalize_task_name, :normalize_command_name
|
447
|
+
|
448
|
+
# this is the logic that takes the command name passed in by the user
|
449
|
+
# and determines whether it is an unambiguous substrings of a command or
|
450
|
+
# alias name.
|
451
|
+
def find_command_possibilities(meth)
|
452
|
+
len = meth.to_s.length
|
453
|
+
possibilities = all_commands.merge(map).keys.select { |n| meth == n[0, len] }.sort
|
454
|
+
unique_possibilities = possibilities.map { |k| map[k] || k }.uniq
|
455
|
+
|
456
|
+
if possibilities.include?(meth)
|
457
|
+
[meth]
|
458
|
+
elsif unique_possibilities.size == 1
|
459
|
+
unique_possibilities
|
460
|
+
else
|
461
|
+
possibilities
|
462
|
+
end
|
463
|
+
end
|
464
|
+
alias_method :find_task_possibilities, :find_command_possibilities
|
465
|
+
|
466
|
+
def subcommand_help(cmd)
|
467
|
+
desc "help [COMMAND]", "Describe subcommands or one specific subcommand"
|
468
|
+
class_eval "
|
469
|
+
def help(command = nil, subcommand = true); super; end
|
470
|
+
"
|
471
|
+
end
|
472
|
+
alias_method :subtask_help, :subcommand_help
|
473
|
+
end
|
474
|
+
|
475
|
+
include Foreman::Thor::Base
|
476
|
+
|
477
|
+
map HELP_MAPPINGS => :help
|
478
|
+
|
479
|
+
desc "help [COMMAND]", "Describe available commands or one specific command"
|
480
|
+
disable_class_options
|
481
|
+
def help(command = nil, subcommand = false)
|
482
|
+
if command
|
483
|
+
if self.class.subcommands.include? command
|
484
|
+
self.class.subcommand_classes[command].help(shell, true)
|
485
|
+
else
|
486
|
+
self.class.command_help(shell, command)
|
487
|
+
end
|
488
|
+
else
|
489
|
+
self.class.help(shell, subcommand)
|
490
|
+
end
|
491
|
+
end
|
492
|
+
end
|
data/lib/foreman.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "foreman/version"
|
2
|
+
|
3
|
+
module Foreman
|
4
|
+
|
5
|
+
def self.runner
|
6
|
+
File.expand_path("../../bin/foreman-runner", __FILE__)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.ruby_18?
|
10
|
+
defined?(RUBY_VERSION) and RUBY_VERSION =~ /^1\.8\.\d+/
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.windows?
|
14
|
+
defined?(RUBY_PLATFORM) and RUBY_PLATFORM =~ /(win|w)32$/
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/man/overman.1
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
.\" generated with Ronn-NG/v0.10.1
|
2
|
+
.\" http://github.com/apjanke/ronn-ng/tree/0.10.1
|
3
|
+
.TH "FOREMAN" "1" "April 2024" "Foreman 0.88.1" "Foreman Manual"
|
4
|
+
.SH "NAME"
|
5
|
+
\fBforeman\fR \- manage Procfile\-based applications
|
6
|
+
.SH "SYNOPSIS"
|
7
|
+
\fBforeman start [process]\fR
|
8
|
+
.br
|
9
|
+
\fBforeman run <command>\fR
|
10
|
+
.br
|
11
|
+
\fBforeman export <format> [location]\fR
|
12
|
+
.SH "DESCRIPTION"
|
13
|
+
Foreman is a manager for Procfile\-based applications\. Its aim is to abstract away the details of the Procfile format, and allow you to either run your application directly or export it to some other process management format\.
|
14
|
+
.SH "RUNNING"
|
15
|
+
\fBforeman start\fR is used to run your application directly from the command line\.
|
16
|
+
.P
|
17
|
+
If no additional parameters are passed, foreman will run one instance of each type of process defined in your Procfile\.
|
18
|
+
.P
|
19
|
+
If a parameter is passed, foreman will run one instance of the specified application type\.
|
20
|
+
.P
|
21
|
+
The following options control how the application is run:
|
22
|
+
.TP
|
23
|
+
\fB\-m\fR, \fB\-\-formation\fR
|
24
|
+
Specify the number of each process type to run\. The value passed in should be in the format \fBprocess=num,process=num\fR
|
25
|
+
.TP
|
26
|
+
\fB\-e\fR, \fB\-\-env\fR
|
27
|
+
Specify one or more \.env files to load
|
28
|
+
.TP
|
29
|
+
\fB\-f\fR, \fB\-\-procfile\fR
|
30
|
+
Specify an alternate Procfile to load, implies \fB\-d\fR at the Procfile root\.
|
31
|
+
.TP
|
32
|
+
\fB\-p\fR, \fB\-\-port\fR
|
33
|
+
Specify which port to use as the base for this application\. Should be a multiple of 1000\.
|
34
|
+
.TP
|
35
|
+
\fB\-t\fR, \fB\-\-timeout\fR
|
36
|
+
Specify the amount of time (in seconds) processes have to shutdown gracefully before receiving a SIGKILL, defaults to 5\.
|
37
|
+
.P
|
38
|
+
\fBforeman run\fR is used to run one\-off commands using the same environment as your defined processes\.
|
39
|
+
.SH "EXPORTING"
|
40
|
+
\fBforeman export\fR is used to export your application to another process management format\.
|
41
|
+
.P
|
42
|
+
A location to export can be passed as an argument\. This argument may be either required or optional depending on the export format\.
|
43
|
+
.P
|
44
|
+
The following options control how the application is run:
|
45
|
+
.TP
|
46
|
+
\fB\-a\fR, \fB\-\-app\fR
|
47
|
+
Use this name rather than the application's root directory name as the name of the application when exporting\.
|
48
|
+
.TP
|
49
|
+
\fB\-m\fR, \fB\-\-formation\fR
|
50
|
+
Specify the number of each process type to run\. The value passed in should be in the format \fBprocess=num,process=num\fR
|
51
|
+
.TP
|
52
|
+
\fB\-l\fR, \fB\-\-log\fR
|
53
|
+
Specify the directory to place process logs in\.
|
54
|
+
.TP
|
55
|
+
\fB\-p\fR, \fB\-\-port\fR
|
56
|
+
Specify which port to use as the base for this application\. Should be a multiple of 1000\.
|
57
|
+
.TP
|
58
|
+
\fB\-t\fR, \fB\-\-template\fR
|
59
|
+
Specify an alternate template to use for creating export files\. See \fIhttps://github\.com/ddollar/foreman/tree/master/data/export\fR for examples\.
|
60
|
+
.TP
|
61
|
+
\fB\-u\fR, \fB\-\-user\fR
|
62
|
+
Specify the user the application should be run as\. Defaults to the app name
|
63
|
+
.SH "GLOBAL OPTIONS"
|
64
|
+
These options control all modes of foreman's operation\.
|
65
|
+
.TP
|
66
|
+
\fB\-d\fR, \fB\-\-root\fR
|
67
|
+
Specify an alternate application root\. This defaults to the directory containing the Procfile\.
|
68
|
+
.TP
|
69
|
+
\fB\-e\fR, \fB\-\-env\fR
|
70
|
+
Specify an alternate environment file\. You can specify more than one file by using: \fB\-\-env file1,file2\fR\.
|
71
|
+
.TP
|
72
|
+
\fB\-f\fR, \fB\-\-procfile\fR
|
73
|
+
Specify an alternate location for the application's Procfile\. This file's containing directory will be assumed to be the root directory of the application\.
|
74
|
+
.SH "EXPORT FORMATS"
|
75
|
+
foreman currently supports the following output formats:
|
76
|
+
.IP "\(bu" 4
|
77
|
+
bluepill
|
78
|
+
.IP "\(bu" 4
|
79
|
+
inittab
|
80
|
+
.IP "\(bu" 4
|
81
|
+
launchd
|
82
|
+
.IP "\(bu" 4
|
83
|
+
runit
|
84
|
+
.IP "\(bu" 4
|
85
|
+
supervisord
|
86
|
+
.IP "\(bu" 4
|
87
|
+
systemd
|
88
|
+
.IP "\(bu" 4
|
89
|
+
upstart
|
90
|
+
.IP "" 0
|
91
|
+
.SH "INITTAB EXPORT"
|
92
|
+
Will export a chunk of inittab\-compatible configuration:
|
93
|
+
.IP "" 4
|
94
|
+
.nf
|
95
|
+
# \-\-\-\-\- foreman example processes \-\-\-\-\-
|
96
|
+
EX01:4:respawn:/bin/su \- example \-c 'PORT=5000 bundle exec thin start >> /var/log/web\-1\.log 2>&1'
|
97
|
+
EX02:4:respawn:/bin/su \- example \-c 'PORT=5100 bundle exec rake jobs:work >> /var/log/job\-1\.log 2>&1'
|
98
|
+
# \-\-\-\-\- end foreman example processes \-\-\-\-\-
|
99
|
+
.fi
|
100
|
+
.IP "" 0
|
101
|
+
.SH "SYSTEMD EXPORT"
|
102
|
+
Will create a series of systemd scripts in the location you specify\. Scripts will be structured to make the following commands valid:
|
103
|
+
.P
|
104
|
+
\fBsystemctl start appname\.target\fR
|
105
|
+
.P
|
106
|
+
\fBsystemctl stop appname\-processname\.target\fR
|
107
|
+
.P
|
108
|
+
\fBsystemctl restart appname\-processname\-3\.service\fR
|
109
|
+
.SH "UPSTART EXPORT"
|
110
|
+
Will create a series of upstart scripts in the location you specify\. Scripts will be structured to make the following commands valid:
|
111
|
+
.P
|
112
|
+
\fBstart appname\fR
|
113
|
+
.P
|
114
|
+
\fBstop appname\-processname\fR
|
115
|
+
.P
|
116
|
+
\fBrestart appname\-processname\-3\fR
|
117
|
+
.SH "PROCFILE"
|
118
|
+
A Procfile should contain both a name for the process and the command used to run it\.
|
119
|
+
.IP "" 4
|
120
|
+
.nf
|
121
|
+
web: bundle exec thin start
|
122
|
+
job: bundle exec rake jobs:work
|
123
|
+
.fi
|
124
|
+
.IP "" 0
|
125
|
+
.P
|
126
|
+
A process name may contain letters, numbers and the underscore character\. You can validate your Procfile format using the \fBcheck\fR command:
|
127
|
+
.IP "" 4
|
128
|
+
.nf
|
129
|
+
$ foreman check
|
130
|
+
.fi
|
131
|
+
.IP "" 0
|
132
|
+
.P
|
133
|
+
The special environment variables \fB$PORT\fR and \fB$PS\fR are available within the Procfile\. \fB$PORT\fR is the port selected for that process\. \fB$PS\fR is the name of the process for the line\.
|
134
|
+
.P
|
135
|
+
The \fB$PORT\fR value starts as the base port as specified by \fB\-p\fR, then increments by 100 for each new process line\. Multiple instances of the same process are assigned \fB$PORT\fR values that increment by 1\.
|
136
|
+
.SH "ENVIRONMENT"
|
137
|
+
If a \fB\.env\fR file exists in the current directory, the default environment will be read from it\. This file should contain key/value pairs, separated by \fB=\fR, with one key/value pair per line\.
|
138
|
+
.IP "" 4
|
139
|
+
.nf
|
140
|
+
FOO=bar
|
141
|
+
BAZ=qux
|
142
|
+
.fi
|
143
|
+
.IP "" 0
|
144
|
+
.SH "DEFAULT OPTIONS"
|
145
|
+
If a \fB\.foreman\fR file exists in the current directory, default options will be read from it\. This file should be in YAML format with the long option name as keys\. Example:
|
146
|
+
.IP "" 4
|
147
|
+
.nf
|
148
|
+
formation: alpha=0,bravo=1
|
149
|
+
port: 15000
|
150
|
+
.fi
|
151
|
+
.IP "" 0
|
152
|
+
.SH "EXAMPLES"
|
153
|
+
Start one instance of each process type, interleave the output on stdout:
|
154
|
+
.IP "" 4
|
155
|
+
.nf
|
156
|
+
$ foreman start
|
157
|
+
.fi
|
158
|
+
.IP "" 0
|
159
|
+
.P
|
160
|
+
Export the application in upstart format:
|
161
|
+
.IP "" 4
|
162
|
+
.nf
|
163
|
+
$ foreman export upstart /etc/init
|
164
|
+
.fi
|
165
|
+
.IP "" 0
|
166
|
+
.P
|
167
|
+
Run one process type from the application defined in a specific Procfile:
|
168
|
+
.IP "" 4
|
169
|
+
.nf
|
170
|
+
$ foreman start alpha \-f ~/myapp/Procfile
|
171
|
+
.fi
|
172
|
+
.IP "" 0
|
173
|
+
.P
|
174
|
+
Start all processes except the one named worker:
|
175
|
+
.IP "" 4
|
176
|
+
.nf
|
177
|
+
$ foreman start \-m all=1,worker=0
|
178
|
+
.fi
|
179
|
+
.IP "" 0
|
180
|
+
.SH "COPYRIGHT"
|
181
|
+
Foreman is Copyright (C) 2010 David Dollar \fIhttp://daviddollar\.org\fR
|