From e5a8c38da6f0533f431531a98705ac5cd11a76d9 Mon Sep 17 00:00:00 2001 From: David Dollar Date: Tue, 20 Jul 2010 16:19:40 -0700 Subject: [PATCH] clean up exports --- lib/foreman/engine.rb | 6 ++++++ lib/foreman/export/base.rb | 6 ------ lib/foreman/export/inittab.rb | 4 ++-- lib/foreman/export/upstart.rb | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/foreman/engine.rb b/lib/foreman/engine.rb index f09c939..2e1ae18 100644 --- a/lib/foreman/engine.rb +++ b/lib/foreman/engine.rb @@ -71,6 +71,12 @@ class Foreman::Engine watch_for_termination end + def port_for(process, num, base_port=nil) + base_port ||= 5000 + offset = processes.keys.sort.index(process.name) * 100 + base_port.to_i + offset + num - 1 + end + private ###################################################################### def fork(process) diff --git a/lib/foreman/export/base.rb b/lib/foreman/export/base.rb index 4854587..bb70511 100644 --- a/lib/foreman/export/base.rb +++ b/lib/foreman/export/base.rb @@ -27,12 +27,6 @@ private ###################################################################### File.read(File.expand_path("../../../../export/#{name}", __FILE__)) end - def port_for(base_port, app, num) - base_port ||= 5000 - offset = engine.processes.keys.sort.index(app) * 100 - base_port.to_i + offset + num - 1 - end - def write_file(filename, contents) say "writing: #{filename}" diff --git a/lib/foreman/export/inittab.rb b/lib/foreman/export/inittab.rb index 98a6e49..446d009 100644 --- a/lib/foreman/export/inittab.rb +++ b/lib/foreman/export/inittab.rb @@ -7,7 +7,7 @@ class Foreman::Export::Inittab < Foreman::Export::Base user = options[:user] || app log_root = options[:log] || "/var/log/#{app}" - concurrency = parse_concurrency(options[:concurrency]) + concurrency = Foreman::Utils.parse_concurrency(options[:concurrency]) inittab = [] inittab << "# ----- foreman #{app} processes -----" @@ -15,7 +15,7 @@ class Foreman::Export::Inittab < Foreman::Export::Base engine.processes.values.inject(1) do |index, process| 1.upto(concurrency[process.name]) do |num| id = app.slice(0, 2).upcase + sprintf("%02d", index) - port = port_for(options[:port], process.name, num) + port = engine.port_for(process, num, options[:port]) inittab << "#{id}:4:respawn:/bin/su - #{user} -c 'PORT=#{port} #{process.command} >> #{log_root}/#{process.name}-#{num}.log 2>&1'" index += 1 end diff --git a/lib/foreman/export/upstart.rb b/lib/foreman/export/upstart.rb index 3a693ad..109369b 100644 --- a/lib/foreman/export/upstart.rb +++ b/lib/foreman/export/upstart.rb @@ -17,7 +17,7 @@ class Foreman::Export::Upstart < Foreman::Export::Base FileUtils.rm(file) end - concurrency = parse_concurrency(options[:concurrency]) + concurrency = Foreman::Utils.parse_concurrency(options[:concurrency]) master_template = export_template("upstart/master.conf.erb") master_config = ERB.new(master_template).result(binding) @@ -31,7 +31,7 @@ class Foreman::Export::Upstart < Foreman::Export::Base write_file "#{location}/#{app}-#{process.name}.conf", process_master_config 1.upto(concurrency[process.name]) do |num| - port = port_for(options[:port], process.name, num) + port = engine.port_for(process, num, options[:port]) process_config = ERB.new(process_template).result(binding) write_file "#{location}/#{app}-#{process.name}-#{num}.conf", process_config end