foreman 0.48.0.pre3 → 0.48.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,7 +24,7 @@ class Foreman::Engine
24
24
  def initialize(options={})
25
25
  @options = options.dup
26
26
 
27
- @options[:formation] ||= "all=1"
27
+ @options[:formation] ||= (options[:concurrency] || "all=1")
28
28
 
29
29
  @env = {}
30
30
  @mutex = Mutex.new
@@ -39,7 +39,7 @@ class Foreman::Engine
39
39
  def start
40
40
  trap("TERM") { puts "SIGTERM received"; terminate_gracefully }
41
41
  trap("INT") { puts "SIGINT received"; terminate_gracefully }
42
- trap("HUP") { puts "SIGHUP received"; terminate_gracefully }
42
+ trap("HUP") { puts "SIGHUP received"; terminate_gracefully } if ::Signal.list.keys.include? 'HUP'
43
43
 
44
44
  startup
45
45
  spawn_processes
@@ -154,11 +154,28 @@ class Foreman::Engine
154
154
  #
155
155
  # @param [Foreman::Process] process A +Process+ associated with this engine
156
156
  # @param [Fixnum] instance The instance of the process
157
- #
157
+ #
158
158
  # @returns [Fixnum] port The port to use for this instance of this process
159
159
  #
160
- def port_for(process, instance)
161
- base_port + (@processes.index(process) * 100) + (instance - 1)
160
+ def port_for(process, instance, base=nil)
161
+ if base
162
+ base + (@processes.index(process.process) * 100) + (instance - 1)
163
+ else
164
+ base_port + (@processes.index(process) * 100) + (instance - 1)
165
+ end
166
+ end
167
+
168
+ # Get the base port for this foreman instance
169
+ #
170
+ # @returns [Fixnum] port The base port
171
+ #
172
+ def base_port
173
+ (options[:port] || env["PORT"] || ENV["PORT"] || 5000).to_i
174
+ end
175
+
176
+ # deprecated
177
+ def environment
178
+ env
162
179
  end
163
180
 
164
181
  private
@@ -179,10 +196,6 @@ private
179
196
 
180
197
  ## Helpers ##########################################################
181
198
 
182
- def base_port
183
- (options[:port] || env["PORT"] || ENV["PORT"] || 5000).to_i
184
- end
185
-
186
199
  def create_pipe
187
200
  IO.method(:pipe).arity.zero? ? IO.pipe : IO.pipe("BINARY")
188
201
  end
@@ -193,7 +206,7 @@ private
193
206
  end
194
207
 
195
208
  def parse_formation(formation)
196
- pairs = @options[:formation].to_s.gsub(/\s/, "").split(",")
209
+ pairs = formation.to_s.gsub(/\s/, "").split(",")
197
210
 
198
211
  pairs.inject(Hash.new(0)) do |ax, pair|
199
212
  process, amount = pair.split("=")
@@ -1,5 +1,6 @@
1
1
  require "foreman"
2
2
  require "foreman/helpers"
3
+ require "pathname"
3
4
 
4
5
  module Foreman::Export
5
6
  extend Foreman::Helpers
@@ -31,4 +32,3 @@ require "foreman/export/bluepill"
31
32
  require "foreman/export/runit"
32
33
  require "foreman/export/supervisord"
33
34
  require "foreman/export/launchd"
34
-
@@ -1,4 +1,6 @@
1
1
  require "foreman/export"
2
+ require "ostruct"
3
+ require "pathname"
2
4
  require "shellwords"
3
5
 
4
6
  class Foreman::Export::Base
@@ -8,11 +10,37 @@ class Foreman::Export::Base
8
10
  attr_reader :options
9
11
  attr_reader :formation
10
12
 
13
+ # deprecated
14
+ attr_reader :port
15
+
11
16
  def initialize(location, engine, options={})
12
17
  @location = location
13
18
  @engine = engine
14
19
  @options = options.dup
15
20
  @formation = engine.formation
21
+
22
+ # deprecated
23
+ def port
24
+ Foreman::Export::Base.warn_deprecation!
25
+ engine.base_port
26
+ end
27
+
28
+ # deprecated
29
+ def template
30
+ Foreman::Export::Base.warn_deprecation!
31
+ options[:template]
32
+ end
33
+
34
+ # deprecated
35
+ def @engine.procfile
36
+ Foreman::Export::Base.warn_deprecation!
37
+ @processes.map do |process|
38
+ OpenStruct.new(
39
+ :name => @names[process],
40
+ :process => process
41
+ )
42
+ end
43
+ end
16
44
  end
17
45
 
18
46
  def export
@@ -36,6 +64,18 @@ class Foreman::Export::Base
36
64
 
37
65
  private ######################################################################
38
66
 
67
+ def self.warn_deprecation!
68
+ @@deprecation_warned ||= false
69
+ return if @@deprecation_warned
70
+ puts "WARNING: Using deprecated exporter interface. Please update your exporter"
71
+ puts "the interface shown in the upstart exporter:"
72
+ puts
73
+ puts "https://github.com/ddollar/foreman/blob/master/lib/foreman/export/upstart.rb"
74
+ puts "https://github.com/ddollar/foreman/blob/master/data/export/upstart/process.conf.erb"
75
+ puts
76
+ @@deprecation_warned = true
77
+ end
78
+
39
79
  def error(message)
40
80
  raise Foreman::Export::Exception.new(message)
41
81
  end
@@ -54,13 +94,28 @@ private ######################################################################
54
94
  '"' + Shellwords.escape(value) + '"'
55
95
  end
56
96
 
57
- def export_template(name)
58
- name_without_first = name.split("/")[1..-1].join("/")
59
- matchers = []
60
- matchers << File.join(options[:template], name_without_first) if options[:template]
61
- matchers << File.expand_path("~/.foreman/templates/#{name}")
62
- matchers << File.expand_path("../../../../data/export/#{name}", __FILE__)
63
- File.read(matchers.detect { |m| File.exists?(m) })
97
+ # deprecated
98
+ def old_export_template(exporter, file, template_root)
99
+ if template_root && File.exist?(file_path = File.join(template_root, file))
100
+ File.read(file_path)
101
+ elsif File.exist?(file_path = File.expand_path(File.join("~/.foreman/templates", file)))
102
+ File.read(file_path)
103
+ else
104
+ File.read(File.expand_path("../../../../data/export/#{exporter}/#{file}", __FILE__))
105
+ end
106
+ end
107
+
108
+ def export_template(name, file=nil, template_root=nil)
109
+ if file && template_root
110
+ old_export_template name, file, template_root
111
+ else
112
+ name_without_first = name.split("/")[1..-1].join("/")
113
+ matchers = []
114
+ matchers << File.join(options[:template], name_without_first) if options[:template]
115
+ matchers << File.expand_path("~/.foreman/templates/#{name}")
116
+ matchers << File.expand_path("../../../../data/export/#{name}", __FILE__)
117
+ File.read(matchers.detect { |m| File.exists?(m) })
118
+ end
64
119
  end
65
120
 
66
121
  def write_template(name, target, binding)
@@ -81,7 +136,9 @@ private ######################################################################
81
136
  def write_file(filename, contents)
82
137
  say "writing: #{filename}"
83
138
 
84
- File.open(File.join(location, filename), "w") do |file|
139
+ filename = File.join(location, filename) unless Pathname.new(filename).absolute?
140
+
141
+ File.open(filename, "w") do |file|
85
142
  file.puts contents
86
143
  end
87
144
  end
@@ -1,5 +1,5 @@
1
1
  module Foreman
2
2
 
3
- VERSION = "0.48.0.pre3"
3
+ VERSION = "0.48.0"
4
4
 
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -54,7 +54,6 @@ def fork_and_capture(&blk)
54
54
  Process.wait pid
55
55
  buffer = ""
56
56
  until rd.eof?
57
- p [:foo]
58
57
  buffer += rd.gets
59
58
  end
60
59
  end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.48.0.pre3
5
- prerelease: 7
4
+ version: 0.48.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Dollar
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-18 00:00:00.000000000 Z
12
+ date: 2012-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &70226092135660 !ruby/object:Gem::Requirement
16
+ requirement: &70302671508760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.13.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70226092135660
24
+ version_requirements: *70302671508760
25
25
  description: Process manager for applications with multiple components
26
26
  email: ddollar@gmail.com
27
27
  executables:
@@ -124,9 +124,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  none: false
126
126
  requirements:
127
- - - ! '>'
127
+ - - ! '>='
128
128
  - !ruby/object:Gem::Version
129
- version: 1.3.1
129
+ version: '0'
130
130
  requirements: []
131
131
  rubyforge_project:
132
132
  rubygems_version: 1.8.11