overman 0.0.1 → 0.87.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +52 -0
  3. data/bin/foreman-runner +41 -0
  4. data/bin/overman +7 -0
  5. data/data/example/Procfile +4 -0
  6. data/data/example/Procfile.without_colon +2 -0
  7. data/data/example/error +7 -0
  8. data/data/example/log/neverdie.log +4 -0
  9. data/data/example/spawnee +14 -0
  10. data/data/example/spawner +7 -0
  11. data/data/example/ticker +14 -0
  12. data/data/example/utf8 +11 -0
  13. data/data/export/bluepill/master.pill.erb +28 -0
  14. data/data/export/daemon/master.conf.erb +14 -0
  15. data/data/export/daemon/process.conf.erb +8 -0
  16. data/data/export/daemon/process_master.conf.erb +2 -0
  17. data/data/export/launchd/launchd.plist.erb +33 -0
  18. data/data/export/runit/log/run.erb +7 -0
  19. data/data/export/runit/run.erb +4 -0
  20. data/data/export/supervisord/app.conf.erb +31 -0
  21. data/data/export/systemd/master.target.erb +5 -0
  22. data/data/export/systemd/process.service.erb +21 -0
  23. data/data/export/upstart/master.conf.erb +2 -0
  24. data/data/export/upstart/process.conf.erb +15 -0
  25. data/data/export/upstart/process_master.conf.erb +2 -0
  26. data/lib/foreman/cli.rb +162 -0
  27. data/lib/foreman/distribution.rb +9 -0
  28. data/lib/foreman/engine/cli.rb +105 -0
  29. data/lib/foreman/engine.rb +494 -0
  30. data/lib/foreman/env.rb +29 -0
  31. data/lib/foreman/export/base.rb +171 -0
  32. data/lib/foreman/export/bluepill.rb +12 -0
  33. data/lib/foreman/export/daemon.rb +28 -0
  34. data/lib/foreman/export/inittab.rb +42 -0
  35. data/lib/foreman/export/launchd.rb +22 -0
  36. data/lib/foreman/export/runit.rb +34 -0
  37. data/lib/foreman/export/supervisord.rb +16 -0
  38. data/lib/foreman/export/systemd.rb +34 -0
  39. data/lib/foreman/export/upstart.rb +46 -0
  40. data/lib/foreman/export.rb +36 -0
  41. data/lib/foreman/helpers.rb +45 -0
  42. data/lib/foreman/process.rb +81 -0
  43. data/lib/foreman/procfile.rb +94 -0
  44. data/lib/foreman/vendor/thor/lib/thor/actions/create_file.rb +103 -0
  45. data/lib/foreman/vendor/thor/lib/thor/actions/create_link.rb +59 -0
  46. data/lib/foreman/vendor/thor/lib/thor/actions/directory.rb +118 -0
  47. data/lib/foreman/vendor/thor/lib/thor/actions/empty_directory.rb +135 -0
  48. data/lib/foreman/vendor/thor/lib/thor/actions/file_manipulation.rb +327 -0
  49. data/lib/foreman/vendor/thor/lib/thor/actions/inject_into_file.rb +103 -0
  50. data/lib/foreman/vendor/thor/lib/thor/actions.rb +318 -0
  51. data/lib/foreman/vendor/thor/lib/thor/base.rb +656 -0
  52. data/lib/foreman/vendor/thor/lib/thor/command.rb +133 -0
  53. data/lib/foreman/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +85 -0
  54. data/lib/foreman/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
  55. data/lib/foreman/vendor/thor/lib/thor/core_ext/ordered_hash.rb +129 -0
  56. data/lib/foreman/vendor/thor/lib/thor/error.rb +32 -0
  57. data/lib/foreman/vendor/thor/lib/thor/group.rb +281 -0
  58. data/lib/foreman/vendor/thor/lib/thor/invocation.rb +177 -0
  59. data/lib/foreman/vendor/thor/lib/thor/line_editor/basic.rb +35 -0
  60. data/lib/foreman/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
  61. data/lib/foreman/vendor/thor/lib/thor/line_editor.rb +17 -0
  62. data/lib/foreman/vendor/thor/lib/thor/parser/argument.rb +70 -0
  63. data/lib/foreman/vendor/thor/lib/thor/parser/arguments.rb +175 -0
  64. data/lib/foreman/vendor/thor/lib/thor/parser/option.rb +146 -0
  65. data/lib/foreman/vendor/thor/lib/thor/parser/options.rb +220 -0
  66. data/lib/foreman/vendor/thor/lib/thor/parser.rb +4 -0
  67. data/lib/foreman/vendor/thor/lib/thor/rake_compat.rb +71 -0
  68. data/lib/foreman/vendor/thor/lib/thor/runner.rb +322 -0
  69. data/lib/foreman/vendor/thor/lib/thor/shell/basic.rb +436 -0
  70. data/lib/foreman/vendor/thor/lib/thor/shell/color.rb +149 -0
  71. data/lib/foreman/vendor/thor/lib/thor/shell/html.rb +126 -0
  72. data/lib/foreman/vendor/thor/lib/thor/shell.rb +81 -0
  73. data/lib/foreman/vendor/thor/lib/thor/util.rb +268 -0
  74. data/lib/foreman/vendor/thor/lib/thor/version.rb +3 -0
  75. data/lib/foreman/vendor/thor/lib/thor.rb +492 -0
  76. data/lib/foreman/version.rb +5 -0
  77. data/lib/foreman.rb +17 -0
  78. data/man/overman.1 +284 -0
  79. data/spec/foreman/cli_spec.rb +111 -0
  80. data/spec/foreman/engine_spec.rb +114 -0
  81. data/spec/foreman/export/base_spec.rb +19 -0
  82. data/spec/foreman/export/bluepill_spec.rb +37 -0
  83. data/spec/foreman/export/daemon_spec.rb +97 -0
  84. data/spec/foreman/export/inittab_spec.rb +40 -0
  85. data/spec/foreman/export/launchd_spec.rb +31 -0
  86. data/spec/foreman/export/runit_spec.rb +36 -0
  87. data/spec/foreman/export/supervisord_spec.rb +38 -0
  88. data/spec/foreman/export/systemd_spec.rb +155 -0
  89. data/spec/foreman/export/upstart_spec.rb +118 -0
  90. data/spec/foreman/export_spec.rb +24 -0
  91. data/spec/foreman/helpers_spec.rb +26 -0
  92. data/spec/foreman/process_spec.rb +71 -0
  93. data/spec/foreman/procfile_spec.rb +57 -0
  94. data/spec/foreman_spec.rb +16 -0
  95. data/spec/helper_spec.rb +19 -0
  96. data/spec/resources/Procfile +5 -0
  97. data/spec/resources/Procfile.bad +2 -0
  98. data/spec/resources/bin/echo +2 -0
  99. data/spec/resources/bin/env +2 -0
  100. data/spec/resources/bin/test +2 -0
  101. data/spec/resources/bin/utf8 +2 -0
  102. data/spec/resources/export/bluepill/app-concurrency.pill +49 -0
  103. data/spec/resources/export/bluepill/app.pill +81 -0
  104. data/spec/resources/export/daemon/app-alpha-1.conf +7 -0
  105. data/spec/resources/export/daemon/app-alpha-2.conf +7 -0
  106. data/spec/resources/export/daemon/app-alpha.conf +2 -0
  107. data/spec/resources/export/daemon/app-bravo-1.conf +7 -0
  108. data/spec/resources/export/daemon/app-bravo.conf +2 -0
  109. data/spec/resources/export/daemon/app.conf +14 -0
  110. data/spec/resources/export/inittab/inittab.concurrency +4 -0
  111. data/spec/resources/export/inittab/inittab.default +6 -0
  112. data/spec/resources/export/launchd/launchd-a.default +29 -0
  113. data/spec/resources/export/launchd/launchd-b.default +29 -0
  114. data/spec/resources/export/launchd/launchd-c.default +30 -0
  115. data/spec/resources/export/runit/app-alpha-1/log/run +7 -0
  116. data/spec/resources/export/runit/app-alpha-1/run +4 -0
  117. data/spec/resources/export/runit/app-alpha-2/log/run +7 -0
  118. data/spec/resources/export/runit/app-alpha-2/run +4 -0
  119. data/spec/resources/export/runit/app-bravo-1/log/run +7 -0
  120. data/spec/resources/export/runit/app-bravo-1/run +4 -0
  121. data/spec/resources/export/supervisord/app-alpha-1.conf +42 -0
  122. data/spec/resources/export/supervisord/app-alpha-2.conf +22 -0
  123. data/spec/resources/export/systemd/app-alpha.1.service +18 -0
  124. data/spec/resources/export/systemd/app-alpha.2.service +18 -0
  125. data/spec/resources/export/systemd/app-alpha.target +2 -0
  126. data/spec/resources/export/systemd/app-bravo.1.service +18 -0
  127. data/spec/resources/export/systemd/app-bravo.target +2 -0
  128. data/spec/resources/export/systemd/app.target +5 -0
  129. data/spec/resources/export/upstart/app-alpha-1.conf +11 -0
  130. data/spec/resources/export/upstart/app-alpha-2.conf +11 -0
  131. data/spec/resources/export/upstart/app-alpha.conf +2 -0
  132. data/spec/resources/export/upstart/app-bravo-1.conf +11 -0
  133. data/spec/resources/export/upstart/app-bravo.conf +2 -0
  134. data/spec/resources/export/upstart/app.conf +2 -0
  135. data/spec/spec_helper.rb +177 -0
  136. metadata +147 -16
  137. data/lib/overman/version.rb +0 -5
  138. data/lib/overman.rb +0 -1
@@ -0,0 +1,318 @@
1
+ require "fileutils"
2
+ require "uri"
3
+ require "foreman/vendor/thor/lib/thor/core_ext/io_binary_read"
4
+ require "foreman/vendor/thor/lib/thor/actions/create_file"
5
+ require "foreman/vendor/thor/lib/thor/actions/create_link"
6
+ require "foreman/vendor/thor/lib/thor/actions/directory"
7
+ require "foreman/vendor/thor/lib/thor/actions/empty_directory"
8
+ require "foreman/vendor/thor/lib/thor/actions/file_manipulation"
9
+ require "foreman/vendor/thor/lib/thor/actions/inject_into_file"
10
+
11
+ class Foreman::Thor
12
+ module Actions
13
+ attr_accessor :behavior
14
+
15
+ def self.included(base) #:nodoc:
16
+ base.extend ClassMethods
17
+ end
18
+
19
+ module ClassMethods
20
+ # Hold source paths for one Foreman::Thor instance. source_paths_for_search is the
21
+ # method responsible to gather source_paths from this current class,
22
+ # inherited paths and the source root.
23
+ #
24
+ def source_paths
25
+ @_source_paths ||= []
26
+ end
27
+
28
+ # Stores and return the source root for this class
29
+ def source_root(path = nil)
30
+ @_source_root = path if path
31
+ @_source_root ||= nil
32
+ end
33
+
34
+ # Returns the source paths in the following order:
35
+ #
36
+ # 1) This class source paths
37
+ # 2) Source root
38
+ # 3) Parents source paths
39
+ #
40
+ def source_paths_for_search
41
+ paths = []
42
+ paths += source_paths
43
+ paths << source_root if source_root
44
+ paths += from_superclass(:source_paths, [])
45
+ paths
46
+ end
47
+
48
+ # Add runtime options that help actions execution.
49
+ #
50
+ def add_runtime_options!
51
+ class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime,
52
+ :desc => "Overwrite files that already exist"
53
+
54
+ class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime,
55
+ :desc => "Run but do not make any changes"
56
+
57
+ class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime,
58
+ :desc => "Suppress status output"
59
+
60
+ class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime,
61
+ :desc => "Skip files that already exist"
62
+ end
63
+ end
64
+
65
+ # Extends initializer to add more configuration options.
66
+ #
67
+ # ==== Configuration
68
+ # behavior<Symbol>:: The actions default behavior. Can be :invoke or :revoke.
69
+ # It also accepts :force, :skip and :pretend to set the behavior
70
+ # and the respective option.
71
+ #
72
+ # destination_root<String>:: The root directory needed for some actions.
73
+ #
74
+ def initialize(args = [], options = {}, config = {})
75
+ self.behavior = case config[:behavior].to_s
76
+ when "force", "skip"
77
+ _cleanup_options_and_set(options, config[:behavior])
78
+ :invoke
79
+ when "revoke"
80
+ :revoke
81
+ else
82
+ :invoke
83
+ end
84
+
85
+ super
86
+ self.destination_root = config[:destination_root]
87
+ end
88
+
89
+ # Wraps an action object and call it accordingly to the thor class behavior.
90
+ #
91
+ def action(instance) #:nodoc:
92
+ if behavior == :revoke
93
+ instance.revoke!
94
+ else
95
+ instance.invoke!
96
+ end
97
+ end
98
+
99
+ # Returns the root for this thor class (also aliased as destination root).
100
+ #
101
+ def destination_root
102
+ @destination_stack.last
103
+ end
104
+
105
+ # Sets the root for this thor class. Relatives path are added to the
106
+ # directory where the script was invoked and expanded.
107
+ #
108
+ def destination_root=(root)
109
+ @destination_stack ||= []
110
+ @destination_stack[0] = File.expand_path(root || "")
111
+ end
112
+
113
+ # Returns the given path relative to the absolute root (ie, root where
114
+ # the script started).
115
+ #
116
+ def relative_to_original_destination_root(path, remove_dot = true)
117
+ path = path.dup
118
+ if path.gsub!(@destination_stack[0], ".")
119
+ remove_dot ? (path[2..-1] || "") : path
120
+ else
121
+ path
122
+ end
123
+ end
124
+
125
+ # Holds source paths in instance so they can be manipulated.
126
+ #
127
+ def source_paths
128
+ @source_paths ||= self.class.source_paths_for_search
129
+ end
130
+
131
+ # Receives a file or directory and search for it in the source paths.
132
+ #
133
+ def find_in_source_paths(file)
134
+ possible_files = [file, file + TEMPLATE_EXTNAME]
135
+ relative_root = relative_to_original_destination_root(destination_root, false)
136
+
137
+ source_paths.each do |source|
138
+ possible_files.each do |f|
139
+ source_file = File.expand_path(f, File.join(source, relative_root))
140
+ return source_file if File.exist?(source_file)
141
+ end
142
+ end
143
+
144
+ message = "Could not find #{file.inspect} in any of your source paths. "
145
+
146
+ unless self.class.source_root
147
+ message << "Please invoke #{self.class.name}.source_root(PATH) with the PATH containing your templates. "
148
+ end
149
+
150
+ message << if source_paths.empty?
151
+ "Currently you have no source paths."
152
+ else
153
+ "Your current source paths are: \n#{source_paths.join("\n")}"
154
+ end
155
+
156
+ raise Error, message
157
+ end
158
+
159
+ # Do something in the root or on a provided subfolder. If a relative path
160
+ # is given it's referenced from the current root. The full path is yielded
161
+ # to the block you provide. The path is set back to the previous path when
162
+ # the method exits.
163
+ #
164
+ # ==== Parameters
165
+ # dir<String>:: the directory to move to.
166
+ # config<Hash>:: give :verbose => true to log and use padding.
167
+ #
168
+ def inside(dir = "", config = {}, &block)
169
+ verbose = config.fetch(:verbose, false)
170
+ pretend = options[:pretend]
171
+
172
+ say_status :inside, dir, verbose
173
+ shell.padding += 1 if verbose
174
+ @destination_stack.push File.expand_path(dir, destination_root)
175
+
176
+ # If the directory doesnt exist and we're not pretending
177
+ if !File.exist?(destination_root) && !pretend
178
+ FileUtils.mkdir_p(destination_root)
179
+ end
180
+
181
+ if pretend
182
+ # In pretend mode, just yield down to the block
183
+ block.arity == 1 ? yield(destination_root) : yield
184
+ else
185
+ FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }
186
+ end
187
+
188
+ @destination_stack.pop
189
+ shell.padding -= 1 if verbose
190
+ end
191
+
192
+ # Goes to the root and execute the given block.
193
+ #
194
+ def in_root
195
+ inside(@destination_stack.first) { yield }
196
+ end
197
+
198
+ # Loads an external file and execute it in the instance binding.
199
+ #
200
+ # ==== Parameters
201
+ # path<String>:: The path to the file to execute. Can be a web address or
202
+ # a relative path from the source root.
203
+ #
204
+ # ==== Examples
205
+ #
206
+ # apply "http://gist.github.com/103208"
207
+ #
208
+ # apply "recipes/jquery.rb"
209
+ #
210
+ def apply(path, config = {})
211
+ verbose = config.fetch(:verbose, true)
212
+ is_uri = path =~ %r{^https?\://}
213
+ path = find_in_source_paths(path) unless is_uri
214
+
215
+ say_status :apply, path, verbose
216
+ shell.padding += 1 if verbose
217
+
218
+ contents = if is_uri
219
+ open(path, "Accept" => "application/x-thor-template", &:read)
220
+ else
221
+ open(path, &:read)
222
+ end
223
+
224
+ instance_eval(contents, path)
225
+ shell.padding -= 1 if verbose
226
+ end
227
+
228
+ # Executes a command returning the contents of the command.
229
+ #
230
+ # ==== Parameters
231
+ # command<String>:: the command to be executed.
232
+ # config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output. Specify :with
233
+ # to append an executable to command execution.
234
+ #
235
+ # ==== Example
236
+ #
237
+ # inside('vendor') do
238
+ # run('ln -s ~/edge rails')
239
+ # end
240
+ #
241
+ def run(command, config = {})
242
+ return unless behavior == :invoke
243
+
244
+ destination = relative_to_original_destination_root(destination_root, false)
245
+ desc = "#{command} from #{destination.inspect}"
246
+
247
+ if config[:with]
248
+ desc = "#{File.basename(config[:with].to_s)} #{desc}"
249
+ command = "#{config[:with]} #{command}"
250
+ end
251
+
252
+ say_status :run, desc, config.fetch(:verbose, true)
253
+
254
+ !options[:pretend] && config[:capture] ? `#{command}` : system(command.to_s)
255
+ end
256
+
257
+ # Executes a ruby script (taking into account WIN32 platform quirks).
258
+ #
259
+ # ==== Parameters
260
+ # command<String>:: the command to be executed.
261
+ # config<Hash>:: give :verbose => false to not log the status.
262
+ #
263
+ def run_ruby_script(command, config = {})
264
+ return unless behavior == :invoke
265
+ run command, config.merge(:with => Foreman::Thor::Util.ruby_command)
266
+ end
267
+
268
+ # Run a thor command. A hash of options can be given and it's converted to
269
+ # switches.
270
+ #
271
+ # ==== Parameters
272
+ # command<String>:: the command to be invoked
273
+ # args<Array>:: arguments to the command
274
+ # config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output.
275
+ # Other options are given as parameter to Foreman::Thor.
276
+ #
277
+ #
278
+ # ==== Examples
279
+ #
280
+ # thor :install, "http://gist.github.com/103208"
281
+ # #=> thor install http://gist.github.com/103208
282
+ #
283
+ # thor :list, :all => true, :substring => 'rails'
284
+ # #=> thor list --all --substring=rails
285
+ #
286
+ def thor(command, *args)
287
+ config = args.last.is_a?(Hash) ? args.pop : {}
288
+ verbose = config.key?(:verbose) ? config.delete(:verbose) : true
289
+ pretend = config.key?(:pretend) ? config.delete(:pretend) : false
290
+ capture = config.key?(:capture) ? config.delete(:capture) : false
291
+
292
+ args.unshift(command)
293
+ args.push Foreman::Thor::Options.to_switches(config)
294
+ command = args.join(" ").strip
295
+
296
+ run command, :with => :thor, :verbose => verbose, :pretend => pretend, :capture => capture
297
+ end
298
+
299
+ protected
300
+
301
+ # Allow current root to be shared between invocations.
302
+ #
303
+ def _shared_configuration #:nodoc:
304
+ super.merge!(:destination_root => destination_root)
305
+ end
306
+
307
+ def _cleanup_options_and_set(options, key) #:nodoc:
308
+ case options
309
+ when Array
310
+ %w(--force -f --skip -s).each { |i| options.delete(i) }
311
+ options << "--#{key}"
312
+ when Hash
313
+ [:force, :skip, "force", "skip"].each { |i| options.delete(i) }
314
+ options.merge!(key => true)
315
+ end
316
+ end
317
+ end
318
+ end