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
+1 -1
View File
@@ -3,4 +3,4 @@ stop on stopping <%= app %>-<%= process.name %>
respawn respawn
chdir <%= engine.directory %> 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"
+7 -10
View File
@@ -25,10 +25,11 @@ class Foreman::CLI < Thor
desc "export FORMAT LOCATION", "Export the application to another process management format" desc "export FORMAT LOCATION", "Export the application to another process management format"
method_option :app, :type => :string, :aliases => "-a" method_option :app, :type => :string, :aliases => "-a"
method_option :log, :type => :string, :aliases => "-l" method_option :log, :type => :string, :aliases => "-l"
method_option :user, :type => :string, :aliases => "-u" method_option :port, :type => :numeric, :aliases => "-p"
method_option :concurrency, :type => :string, :aliases => "-c", method_option :user, :type => :string, :aliases => "-u"
method_option :concurrency, :type => :string, :aliases => "-c",
:banner => '"alpha=5,bar=3"' :banner => '"alpha=5,bar=3"'
def export(format, location=nil) def export(format, location=nil)
@@ -40,12 +41,8 @@ class Foreman::CLI < Thor
else error "Unknown export format: #{format}." else error "Unknown export format: #{format}."
end end
formatter.new(engine).export(location, formatter.new(engine).export(location, options)
:name => options[:app],
:user => options[:user],
:log => options[:log],
:concurrency => options[:concurrency]
)
rescue Foreman::Export::Exception => ex rescue Foreman::Export::Exception => ex
error ex.message error ex.message
end end
+6
View File
@@ -36,6 +36,12 @@ private ######################################################################
end end
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) def write_file(filename, contents)
say "writing: #{filename}" say "writing: #{filename}"
+10 -3
View File
@@ -11,10 +11,17 @@ class Foreman::Export::Inittab < Foreman::Export::Base
inittab = [] inittab = []
inittab << "# ----- foreman #{app} processes -----" inittab << "# ----- foreman #{app} processes -----"
engine.processes.values.each_with_index do |process, num|
id = app.slice(0, 2).upcase + sprintf("%02d", num+1) engine.processes.values.inject(1) do |index, process|
inittab << "#{id}:4:respawn:/bin/su - #{user} -c '#{process.command} >> #{log_root}/#{process.name}-#{num+1}.log 2>&1'" 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 end
inittab << "# ----- end foreman #{app} processes -----" inittab << "# ----- end foreman #{app} processes -----"
inittab = inittab.join("\n") + "\n" inittab = inittab.join("\n") + "\n"
+1
View File
@@ -31,6 +31,7 @@ class Foreman::Export::Upstart < Foreman::Export::Base
write_file "#{location}/#{app}-#{process.name}.conf", process_master_config write_file "#{location}/#{app}-#{process.name}.conf", process_master_config
1.upto(concurrency[process.name]) do |num| 1.upto(concurrency[process.name]) do |num|
port = port_for(options[:port], process.name, num)
process_config = ERB.new(process_template).result(binding) process_config = ERB.new(process_template).result(binding)
write_file "#{location}/#{app}-#{process.name}-#{num}.conf", process_config write_file "#{location}/#{app}-#{process.name}-#{num}.conf", process_config
end end
+7 -3
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 Use this name rather than the application's root directory name as the
name of the application when exporting. name of the application when exporting.
* `-l`, `--log`:
Specify the directory to place process logs in.
* `-c`, `--concurrency`: * `-c`, `--concurrency`:
Specify the number of each process type to run. The value passed in Specify the number of each process type to run. The value passed in
should be in the format `process=num,process=num` 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`: * `-u`, `--user`:
Specify the user the application should be run as. Defaults to the Specify the user the application should be run as. Defaults to the
app name app name