foreman 0.85.0 → 0.87.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/data/export/systemd/master.target.erb +1 -1
  4. data/data/export/systemd/process.service.erb +6 -3
  5. data/lib/foreman/cli.rb +3 -3
  6. data/lib/foreman/export/systemd.rb +7 -13
  7. data/lib/foreman/vendor/thor/lib/thor/actions/create_file.rb +103 -0
  8. data/lib/foreman/vendor/thor/lib/thor/actions/create_link.rb +59 -0
  9. data/lib/foreman/vendor/thor/lib/thor/actions/directory.rb +118 -0
  10. data/lib/foreman/vendor/thor/lib/thor/actions/empty_directory.rb +135 -0
  11. data/lib/foreman/vendor/thor/lib/thor/actions/file_manipulation.rb +327 -0
  12. data/lib/foreman/vendor/thor/lib/thor/actions/inject_into_file.rb +103 -0
  13. data/lib/foreman/vendor/thor/lib/thor/actions.rb +318 -0
  14. data/lib/foreman/vendor/thor/lib/thor/base.rb +656 -0
  15. data/lib/foreman/vendor/thor/lib/thor/command.rb +133 -0
  16. data/lib/foreman/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +85 -0
  17. data/lib/foreman/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
  18. data/lib/foreman/vendor/thor/lib/thor/core_ext/ordered_hash.rb +129 -0
  19. data/lib/foreman/vendor/thor/lib/thor/error.rb +32 -0
  20. data/lib/foreman/vendor/thor/lib/thor/group.rb +281 -0
  21. data/lib/foreman/vendor/thor/lib/thor/invocation.rb +177 -0
  22. data/lib/foreman/vendor/thor/lib/thor/line_editor/basic.rb +35 -0
  23. data/lib/foreman/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
  24. data/lib/foreman/vendor/thor/lib/thor/line_editor.rb +17 -0
  25. data/lib/foreman/vendor/thor/lib/thor/parser/argument.rb +70 -0
  26. data/lib/foreman/vendor/thor/lib/thor/parser/arguments.rb +175 -0
  27. data/lib/foreman/vendor/thor/lib/thor/parser/option.rb +146 -0
  28. data/lib/foreman/vendor/thor/lib/thor/parser/options.rb +220 -0
  29. data/lib/foreman/vendor/thor/lib/thor/parser.rb +4 -0
  30. data/lib/foreman/vendor/thor/lib/thor/rake_compat.rb +71 -0
  31. data/lib/foreman/vendor/thor/lib/thor/runner.rb +322 -0
  32. data/lib/foreman/vendor/thor/lib/thor/shell/basic.rb +436 -0
  33. data/lib/foreman/vendor/thor/lib/thor/shell/color.rb +149 -0
  34. data/lib/foreman/vendor/thor/lib/thor/shell/html.rb +126 -0
  35. data/lib/foreman/vendor/thor/lib/thor/shell.rb +81 -0
  36. data/lib/foreman/vendor/thor/lib/thor/util.rb +268 -0
  37. data/lib/foreman/vendor/thor/lib/thor/version.rb +3 -0
  38. data/lib/foreman/vendor/thor/lib/thor.rb +492 -0
  39. data/lib/foreman/version.rb +1 -1
  40. data/man/foreman.1 +1 -1
  41. data/spec/foreman/export/systemd_spec.rb +88 -46
  42. data/spec/resources/export/systemd/{app-alpha@.service → app-alpha.1.service} +6 -3
  43. data/spec/resources/export/systemd/{app-bravo@.service → app-alpha.2.service} +6 -3
  44. data/spec/resources/export/systemd/app-bravo.1.service +18 -0
  45. data/spec/resources/export/systemd/app.target +1 -1
  46. data/spec/spec_helper.rb +1 -1
  47. metadata +39 -22
  48. data/data/export/systemd/process_master.target.erb +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e43a0881882bfbd5a312184407cf297c245774fd31dd194bc7921f88de02187
4
- data.tar.gz: e836814f151cd348c8744a158c2c5e0aaa35edc567d5482fef75b0b7943c8063
3
+ metadata.gz: b4561719e71efe2d57cb77e271499273d03dd6e3ce1566c2ea448b9924f3986b
4
+ data.tar.gz: 317cb62ea6013742326098d8e4942aafaed4f3c8ba1eee63bf52c269c514d3b8
5
5
  SHA512:
6
- metadata.gz: 9ddc414ab8833e61463cc686cbffe9cb0cb3f6c745963854d57a048f044308d84f6a026378f1b1c90ae1e78a3988f327b86187ffd3871065582bef1623e0c6d6
7
- data.tar.gz: 25ea476d1f02817f63040855c45c07f9e2e05753c18b190a715be3f0ff0f61b7dcca82ef2c8a3dc05522a7089a89c8e614e923b2019d0c891104bbab61318b3c
6
+ metadata.gz: 5af45a820751188c14a474634687b8a088aa436c0de20cf828e1ced1f3c4cdec51da0f6e1566dc78a0f04faa1f14c8a5e516005d96a0abc3c5833e689dd2d217
7
+ data.tar.gz: a35df2258df75633fdeb5835e5f6d82290be0c7c573fac3b2da482c9d61565db7acea6e80c6d1b0663b11924b825139502c0553d231f941a2fa0033cf7cee85a
data/README.md CHANGED
@@ -10,7 +10,7 @@ Manage Procfile-based applications
10
10
 
11
11
  $ gem install foreman
12
12
 
13
- Ruby users should take care *not* to install foreman in their project's `Gemfile`.
13
+ Ruby users should take care *not* to install foreman in their project's `Gemfile`. See this [wiki article](https://github.com/ddollar/foreman/wiki/Don't-Bundle-Foreman) for more details.
14
14
 
15
15
  ## Getting Started
16
16
 
@@ -1,5 +1,5 @@
1
1
  [Unit]
2
- Wants=<%= process_master_names.join(' ') %>
2
+ Wants=<%= service_names.join(' ') %>
3
3
 
4
4
  [Install]
5
5
  WantedBy=multi-user.target
@@ -1,15 +1,18 @@
1
1
  [Unit]
2
- PartOf=<%= app %>-<%= name %>.target
2
+ PartOf=<%= app %>.target
3
+ StopWhenUnneeded=yes
3
4
 
4
5
  [Service]
5
6
  User=<%= user %>
6
7
  WorkingDirectory=<%= engine.root %>
7
- Environment=PORT=%i
8
+ Environment=PORT=<%= port %>
9
+ Environment=PS=<%= process_name %>
8
10
  <% engine.env.each_pair do |var,env| -%>
9
11
  Environment="<%= var %>=<%= env %>"
10
12
  <% end -%>
11
- ExecStart=/bin/bash -lc 'exec <%= process.command %>'
13
+ ExecStart=/bin/bash -lc 'exec -a "<%= app %>-<%= process_name %>" <%= process.command %>'
12
14
  Restart=always
15
+ RestartSec=14s
13
16
  StandardInput=null
14
17
  StandardOutput=syslog
15
18
  StandardError=syslog
data/lib/foreman/cli.rb CHANGED
@@ -6,9 +6,9 @@ require "foreman/export"
6
6
  require "foreman/version"
7
7
  require "shellwords"
8
8
  require "yaml"
9
- require "thor"
9
+ require "foreman/vendor/thor/lib/thor"
10
10
 
11
- class Foreman::CLI < Thor
11
+ class Foreman::CLI < Foreman::Thor
12
12
 
13
13
  include Foreman::Helpers
14
14
 
@@ -157,6 +157,6 @@ private ######################################################################
157
157
  original_options = super
158
158
  return original_options unless File.file?(".foreman")
159
159
  defaults = ::YAML::load_file(".foreman") || {}
160
- Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
160
+ Foreman::Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
161
161
  end
162
162
  end
@@ -17,22 +17,16 @@ class Foreman::Export::Systemd < Foreman::Export::Base
17
17
  clean_dir file
18
18
  end
19
19
 
20
- process_master_names = []
20
+ service_names = []
21
21
 
22
22
  engine.each_process do |name, process|
23
- service_fn = "#{app}-#{name}@.service"
24
- write_template "systemd/process.service.erb", service_fn, binding
25
-
26
- create_directory("#{app}-#{name}.target.wants")
27
- 1.upto(engine.formation[name])
28
- .collect { |num| engine.port_for(process, num) }
29
- .collect { |port| "#{app}-#{name}@#{port}.service" }
30
- .each do |process_name|
31
- create_symlink("#{app}-#{name}.target.wants/#{process_name}", "../#{service_fn}") rescue Errno::EEXIST # This is needed because rr-mocks do not call the origial cleanup
23
+ 1.upto(engine.formation[name]) do |num|
24
+ port = engine.port_for(process, num)
25
+ process_name = "#{name}.#{num}"
26
+ service_filename = "#{app}-#{process_name}.service"
27
+ write_template "systemd/process.service.erb", service_filename, binding
28
+ service_names << service_filename
32
29
  end
33
-
34
- write_template "systemd/process_master.target.erb", "#{app}-#{name}.target", binding
35
- process_master_names << "#{app}-#{name}.target"
36
30
  end
37
31
 
38
32
  write_template "systemd/master.target.erb", "#{app}.target", binding
@@ -0,0 +1,103 @@
1
+ require "foreman/vendor/thor/lib/thor/actions/empty_directory"
2
+
3
+ class Foreman::Thor
4
+ module Actions
5
+ # Create a new file relative to the destination root with the given data,
6
+ # which is the return value of a block or a data string.
7
+ #
8
+ # ==== Parameters
9
+ # destination<String>:: the relative path to the destination root.
10
+ # data<String|NilClass>:: the data to append to the file.
11
+ # config<Hash>:: give :verbose => false to not log the status.
12
+ #
13
+ # ==== Examples
14
+ #
15
+ # create_file "lib/fun_party.rb" do
16
+ # hostname = ask("What is the virtual hostname I should use?")
17
+ # "vhost.name = #{hostname}"
18
+ # end
19
+ #
20
+ # create_file "config/apache.conf", "your apache config"
21
+ #
22
+ def create_file(destination, *args, &block)
23
+ config = args.last.is_a?(Hash) ? args.pop : {}
24
+ data = args.first
25
+ action CreateFile.new(self, destination, block || data.to_s, config)
26
+ end
27
+ alias_method :add_file, :create_file
28
+
29
+ # CreateFile is a subset of Template, which instead of rendering a file with
30
+ # ERB, it gets the content from the user.
31
+ #
32
+ class CreateFile < EmptyDirectory #:nodoc:
33
+ attr_reader :data
34
+
35
+ def initialize(base, destination, data, config = {})
36
+ @data = data
37
+ super(base, destination, config)
38
+ end
39
+
40
+ # Checks if the content of the file at the destination is identical to the rendered result.
41
+ #
42
+ # ==== Returns
43
+ # Boolean:: true if it is identical, false otherwise.
44
+ #
45
+ def identical?
46
+ exists? && File.binread(destination) == render
47
+ end
48
+
49
+ # Holds the content to be added to the file.
50
+ #
51
+ def render
52
+ @render ||= if data.is_a?(Proc)
53
+ data.call
54
+ else
55
+ data
56
+ end
57
+ end
58
+
59
+ def invoke!
60
+ invoke_with_conflict_check do
61
+ FileUtils.mkdir_p(File.dirname(destination))
62
+ File.open(destination, "wb") { |f| f.write render }
63
+ end
64
+ given_destination
65
+ end
66
+
67
+ protected
68
+
69
+ # Now on conflict we check if the file is identical or not.
70
+ #
71
+ def on_conflict_behavior(&block)
72
+ if identical?
73
+ say_status :identical, :blue
74
+ else
75
+ options = base.options.merge(config)
76
+ force_or_skip_or_conflict(options[:force], options[:skip], &block)
77
+ end
78
+ end
79
+
80
+ # If force is true, run the action, otherwise check if it's not being
81
+ # skipped. If both are false, show the file_collision menu, if the menu
82
+ # returns true, force it, otherwise skip.
83
+ #
84
+ def force_or_skip_or_conflict(force, skip, &block)
85
+ if force
86
+ say_status :force, :yellow
87
+ yield unless pretend?
88
+ elsif skip
89
+ say_status :skip, :yellow
90
+ else
91
+ say_status :conflict, :red
92
+ force_or_skip_or_conflict(force_on_collision?, true, &block)
93
+ end
94
+ end
95
+
96
+ # Shows the file collision menu to the user and gets the result.
97
+ #
98
+ def force_on_collision?
99
+ base.shell.file_collision(destination) { render }
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,59 @@
1
+ require "foreman/vendor/thor/lib/thor/actions/create_file"
2
+
3
+ class Foreman::Thor
4
+ module Actions
5
+ # Create a new file relative to the destination root from the given source.
6
+ #
7
+ # ==== Parameters
8
+ # destination<String>:: the relative path to the destination root.
9
+ # source<String|NilClass>:: the relative path to the source root.
10
+ # config<Hash>:: give :verbose => false to not log the status.
11
+ # :: give :symbolic => false for hard link.
12
+ #
13
+ # ==== Examples
14
+ #
15
+ # create_link "config/apache.conf", "/etc/apache.conf"
16
+ #
17
+ def create_link(destination, *args)
18
+ config = args.last.is_a?(Hash) ? args.pop : {}
19
+ source = args.first
20
+ action CreateLink.new(self, destination, source, config)
21
+ end
22
+ alias_method :add_link, :create_link
23
+
24
+ # CreateLink is a subset of CreateFile, which instead of taking a block of
25
+ # data, just takes a source string from the user.
26
+ #
27
+ class CreateLink < CreateFile #:nodoc:
28
+ attr_reader :data
29
+
30
+ # Checks if the content of the file at the destination is identical to the rendered result.
31
+ #
32
+ # ==== Returns
33
+ # Boolean:: true if it is identical, false otherwise.
34
+ #
35
+ def identical?
36
+ exists? && File.identical?(render, destination)
37
+ end
38
+
39
+ def invoke!
40
+ invoke_with_conflict_check do
41
+ FileUtils.mkdir_p(File.dirname(destination))
42
+ # Create a symlink by default
43
+ config[:symbolic] = true if config[:symbolic].nil?
44
+ File.unlink(destination) if exists?
45
+ if config[:symbolic]
46
+ File.symlink(render, destination)
47
+ else
48
+ File.link(render, destination)
49
+ end
50
+ end
51
+ given_destination
52
+ end
53
+
54
+ def exists?
55
+ super || File.symlink?(destination)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,118 @@
1
+ require "foreman/vendor/thor/lib/thor/actions/empty_directory"
2
+
3
+ class Foreman::Thor
4
+ module Actions
5
+ # Copies recursively the files from source directory to root directory.
6
+ # If any of the files finishes with .tt, it's considered to be a template
7
+ # and is placed in the destination without the extension .tt. If any
8
+ # empty directory is found, it's copied and all .empty_directory files are
9
+ # ignored. If any file name is wrapped within % signs, the text within
10
+ # the % signs will be executed as a method and replaced with the returned
11
+ # value. Let's suppose a doc directory with the following files:
12
+ #
13
+ # doc/
14
+ # components/.empty_directory
15
+ # README
16
+ # rdoc.rb.tt
17
+ # %app_name%.rb
18
+ #
19
+ # When invoked as:
20
+ #
21
+ # directory "doc"
22
+ #
23
+ # It will create a doc directory in the destination with the following
24
+ # files (assuming that the `app_name` method returns the value "blog"):
25
+ #
26
+ # doc/
27
+ # components/
28
+ # README
29
+ # rdoc.rb
30
+ # blog.rb
31
+ #
32
+ # <b>Encoded path note:</b> Since Foreman::Thor internals use Object#respond_to? to check if it can
33
+ # expand %something%, this `something` should be a public method in the class calling
34
+ # #directory. If a method is private, Foreman::Thor stack raises PrivateMethodEncodedError.
35
+ #
36
+ # ==== Parameters
37
+ # source<String>:: the relative path to the source root.
38
+ # destination<String>:: the relative path to the destination root.
39
+ # config<Hash>:: give :verbose => false to not log the status.
40
+ # If :recursive => false, does not look for paths recursively.
41
+ # If :mode => :preserve, preserve the file mode from the source.
42
+ # If :exclude_pattern => /regexp/, prevents copying files that match that regexp.
43
+ #
44
+ # ==== Examples
45
+ #
46
+ # directory "doc"
47
+ # directory "doc", "docs", :recursive => false
48
+ #
49
+ def directory(source, *args, &block)
50
+ config = args.last.is_a?(Hash) ? args.pop : {}
51
+ destination = args.first || source
52
+ action Directory.new(self, source, destination || source, config, &block)
53
+ end
54
+
55
+ class Directory < EmptyDirectory #:nodoc:
56
+ attr_reader :source
57
+
58
+ def initialize(base, source, destination = nil, config = {}, &block)
59
+ @source = File.expand_path(base.find_in_source_paths(source.to_s))
60
+ @block = block
61
+ super(base, destination, {:recursive => true}.merge(config))
62
+ end
63
+
64
+ def invoke!
65
+ base.empty_directory given_destination, config
66
+ execute!
67
+ end
68
+
69
+ def revoke!
70
+ execute!
71
+ end
72
+
73
+ protected
74
+
75
+ def execute!
76
+ lookup = Util.escape_globs(source)
77
+ lookup = config[:recursive] ? File.join(lookup, "**") : lookup
78
+ lookup = file_level_lookup(lookup)
79
+
80
+ files(lookup).sort.each do |file_source|
81
+ next if File.directory?(file_source)
82
+ next if config[:exclude_pattern] && file_source.match(config[:exclude_pattern])
83
+ file_destination = File.join(given_destination, file_source.gsub(source, "."))
84
+ file_destination.gsub!("/./", "/")
85
+
86
+ case file_source
87
+ when /\.empty_directory$/
88
+ dirname = File.dirname(file_destination).gsub(%r{/\.$}, "")
89
+ next if dirname == given_destination
90
+ base.empty_directory(dirname, config)
91
+ when /#{TEMPLATE_EXTNAME}$/
92
+ base.template(file_source, file_destination[0..-4], config, &@block)
93
+ else
94
+ base.copy_file(file_source, file_destination, config, &@block)
95
+ end
96
+ end
97
+ end
98
+
99
+ if RUBY_VERSION < "2.0"
100
+ def file_level_lookup(previous_lookup)
101
+ File.join(previous_lookup, "{*,.[a-z]*}")
102
+ end
103
+
104
+ def files(lookup)
105
+ Dir[lookup]
106
+ end
107
+ else
108
+ def file_level_lookup(previous_lookup)
109
+ File.join(previous_lookup, "*")
110
+ end
111
+
112
+ def files(lookup)
113
+ Dir.glob(lookup, File::FNM_DOTMATCH)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,135 @@
1
+ class Foreman::Thor
2
+ module Actions
3
+ # Creates an empty directory.
4
+ #
5
+ # ==== Parameters
6
+ # destination<String>:: the relative path to the destination root.
7
+ # config<Hash>:: give :verbose => false to not log the status.
8
+ #
9
+ # ==== Examples
10
+ #
11
+ # empty_directory "doc"
12
+ #
13
+ def empty_directory(destination, config = {})
14
+ action EmptyDirectory.new(self, destination, config)
15
+ end
16
+
17
+ # Class which holds create directory logic. This is the base class for
18
+ # other actions like create_file and directory.
19
+ #
20
+ # This implementation is based in Templater actions, created by Jonas Nicklas
21
+ # and Michael S. Klishin under MIT LICENSE.
22
+ #
23
+ class EmptyDirectory #:nodoc:
24
+ attr_reader :base, :destination, :given_destination, :relative_destination, :config
25
+
26
+ # Initializes given the source and destination.
27
+ #
28
+ # ==== Parameters
29
+ # base<Foreman::Thor::Base>:: A Foreman::Thor::Base instance
30
+ # source<String>:: Relative path to the source of this file
31
+ # destination<String>:: Relative path to the destination of this file
32
+ # config<Hash>:: give :verbose => false to not log the status.
33
+ #
34
+ def initialize(base, destination, config = {})
35
+ @base = base
36
+ @config = {:verbose => true}.merge(config)
37
+ self.destination = destination
38
+ end
39
+
40
+ # Checks if the destination file already exists.
41
+ #
42
+ # ==== Returns
43
+ # Boolean:: true if the file exists, false otherwise.
44
+ #
45
+ def exists?
46
+ ::File.exist?(destination)
47
+ end
48
+
49
+ def invoke!
50
+ invoke_with_conflict_check do
51
+ ::FileUtils.mkdir_p(destination)
52
+ end
53
+ end
54
+
55
+ def revoke!
56
+ say_status :remove, :red
57
+ ::FileUtils.rm_rf(destination) if !pretend? && exists?
58
+ given_destination
59
+ end
60
+
61
+ protected
62
+
63
+ # Shortcut for pretend.
64
+ #
65
+ def pretend?
66
+ base.options[:pretend]
67
+ end
68
+
69
+ # Sets the absolute destination value from a relative destination value.
70
+ # It also stores the given and relative destination. Let's suppose our
71
+ # script is being executed on "dest", it sets the destination root to
72
+ # "dest". The destination, given_destination and relative_destination
73
+ # are related in the following way:
74
+ #
75
+ # inside "bar" do
76
+ # empty_directory "baz"
77
+ # end
78
+ #
79
+ # destination #=> dest/bar/baz
80
+ # relative_destination #=> bar/baz
81
+ # given_destination #=> baz
82
+ #
83
+ def destination=(destination)
84
+ return unless destination
85
+ @given_destination = convert_encoded_instructions(destination.to_s)
86
+ @destination = ::File.expand_path(@given_destination, base.destination_root)
87
+ @relative_destination = base.relative_to_original_destination_root(@destination)
88
+ end
89
+
90
+ # Filenames in the encoded form are converted. If you have a file:
91
+ #
92
+ # %file_name%.rb
93
+ #
94
+ # It calls #file_name from the base and replaces %-string with the
95
+ # return value (should be String) of #file_name:
96
+ #
97
+ # user.rb
98
+ #
99
+ # The method referenced can be either public or private.
100
+ #
101
+ def convert_encoded_instructions(filename)
102
+ filename.gsub(/%(.*?)%/) do |initial_string|
103
+ method = $1.strip
104
+ base.respond_to?(method, true) ? base.send(method) : initial_string
105
+ end
106
+ end
107
+
108
+ # Receives a hash of options and just execute the block if some
109
+ # conditions are met.
110
+ #
111
+ def invoke_with_conflict_check(&block)
112
+ if exists?
113
+ on_conflict_behavior(&block)
114
+ else
115
+ say_status :create, :green
116
+ yield unless pretend?
117
+ end
118
+
119
+ destination
120
+ end
121
+
122
+ # What to do when the destination file already exists.
123
+ #
124
+ def on_conflict_behavior
125
+ say_status :exist, :blue
126
+ end
127
+
128
+ # Shortcut to say_status shell method.
129
+ #
130
+ def say_status(status, color)
131
+ base.shell.say_status status, relative_destination, color if config[:verbose]
132
+ end
133
+ end
134
+ end
135
+ end