lib/foreman/engine.rb in foreman-0.48.0.pre3 vs lib/foreman/engine.rb in foreman-0.48.0
- old
+ new
@@ -22,11 +22,11 @@
# @option options [String] :root (Dir.pwd) The root directory from which to run processes
#
def initialize(options={})
@options = options.dup
- @options[:formation] ||= "all=1"
+ @options[:formation] ||= (options[:concurrency] || "all=1")
@env = {}
@mutex = Mutex.new
@names = {}
@processes = []
@@ -37,11 +37,11 @@
# Start the processes registered to this +Engine+
#
def start
trap("TERM") { puts "SIGTERM received"; terminate_gracefully }
trap("INT") { puts "SIGINT received"; terminate_gracefully }
- trap("HUP") { puts "SIGHUP received"; terminate_gracefully }
+ trap("HUP") { puts "SIGHUP received"; terminate_gracefully } if ::Signal.list.keys.include? 'HUP'
startup
spawn_processes
watch_for_output
sleep 0.1
@@ -152,17 +152,34 @@
# Get the port for a given process and offset
#
# @param [Foreman::Process] process A +Process+ associated with this engine
# @param [Fixnum] instance The instance of the process
- #
+ #
# @returns [Fixnum] port The port to use for this instance of this process
#
- def port_for(process, instance)
- base_port + (@processes.index(process) * 100) + (instance - 1)
+ def port_for(process, instance, base=nil)
+ if base
+ base + (@processes.index(process.process) * 100) + (instance - 1)
+ else
+ base_port + (@processes.index(process) * 100) + (instance - 1)
+ end
end
+ # Get the base port for this foreman instance
+ #
+ # @returns [Fixnum] port The base port
+ #
+ def base_port
+ (options[:port] || env["PORT"] || ENV["PORT"] || 5000).to_i
+ end
+
+ # deprecated
+ def environment
+ env
+ end
+
private
### Engine API ######################################################
def startup
@@ -177,24 +194,20 @@
raise TypeError, "must use a subclass of Foreman::Engine"
end
## Helpers ##########################################################
- def base_port
- (options[:port] || env["PORT"] || ENV["PORT"] || 5000).to_i
- end
-
def create_pipe
IO.method(:pipe).arity.zero? ? IO.pipe : IO.pipe("BINARY")
end
def name_for(pid)
process, index = @running[pid]
[ @names[process], index.to_s ].compact.join(".")
end
def parse_formation(formation)
- pairs = @options[:formation].to_s.gsub(/\s/, "").split(",")
+ pairs = formation.to_s.gsub(/\s/, "").split(",")
pairs.inject(Hash.new(0)) do |ax, pair|
process, amount = pair.split("=")
process == "all" ? ax.default = amount.to_i : ax[process] = amount.to_i
ax