add -p flag to specify the base port for apps

This commit is contained in:
David Dollar
2010-06-30 21:32:26 -04:00
parent 98486513b6
commit 3151663f37
6 changed files with 32 additions and 17 deletions

View File

@@ -3,4 +3,4 @@ stop on stopping <%= app %>-<%= process.name %>
respawn
chdir <%= engine.directory %>
exec su <%= user %> -c "<%= process.command %> >> <%= log_root %>/<%=process.name%>-<%=num%>.log 2>&1"
exec su <%= user %> -c "PORT=<%= port %> <%= process.command %> >> <%= log_root %>/<%=process.name%>-<%=num%>.log 2>&1"

View File

@@ -25,10 +25,11 @@ class Foreman::CLI < Thor
desc "export FORMAT LOCATION", "Export the application to another process management format"
method_option :app, :type => :string, :aliases => "-a"
method_option :log, :type => :string, :aliases => "-l"
method_option :user, :type => :string, :aliases => "-u"
method_option :concurrency, :type => :string, :aliases => "-c",
method_option :app, :type => :string, :aliases => "-a"
method_option :log, :type => :string, :aliases => "-l"
method_option :port, :type => :numeric, :aliases => "-p"
method_option :user, :type => :string, :aliases => "-u"
method_option :concurrency, :type => :string, :aliases => "-c",
:banner => '"alpha=5,bar=3"'
def export(format, location=nil)
@@ -40,12 +41,8 @@ class Foreman::CLI < Thor
else error "Unknown export format: #{format}."
end
formatter.new(engine).export(location,
:name => options[:app],
:user => options[:user],
:log => options[:log],
:concurrency => options[:concurrency]
)
formatter.new(engine).export(location, options)
rescue Foreman::Export::Exception => ex
error ex.message
end

View File

@@ -36,6 +36,12 @@ private ######################################################################
end
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}"

View File

@@ -11,10 +11,17 @@ class Foreman::Export::Inittab < Foreman::Export::Base
inittab = []
inittab << "# ----- foreman #{app} processes -----"
engine.processes.values.each_with_index do |process, num|
id = app.slice(0, 2).upcase + sprintf("%02d", num+1)
inittab << "#{id}:4:respawn:/bin/su - #{user} -c '#{process.command} >> #{log_root}/#{process.name}-#{num+1}.log 2>&1'"
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)
inittab << "#{id}:4:respawn:/bin/su - #{user} -c 'PORT=#{port} #{process.command} >> #{log_root}/#{process.name}-#{num}.log 2>&1'"
index += 1
end
index
end
inittab << "# ----- end foreman #{app} processes -----"
inittab = inittab.join("\n") + "\n"

View File

@@ -31,6 +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)
process_config = ERB.new(process_template).result(binding)
write_file "#{location}/#{app}-#{process.name}-#{num}.conf", process_config
end

View File

@@ -43,13 +43,17 @@ The following options control how the application is run:
Use this name rather than the application's root directory name as the
name of the application when exporting.
* `-l`, `--log`:
Specify the directory to place process logs in.
* `-c`, `--concurrency`:
Specify the number of each process type to run. The value passed in
should be in the format `process=num,process=num`
* `-l`, `--log`:
Specify the directory to place process logs in.
* `-p`, `--port`:
Specify which port to use as the base for this application. Should be
a multiple of 1000.
* `-u`, `--user`:
Specify the user the application should be run as. Defaults to the
app name