Compare commits

...

9 Commits

Author SHA1 Message Date
David Dollar
26599f630f Regenerated gemspec for version 0.5.0 2010-06-30 21:32:44 -04:00
David Dollar
cfe6a49900 update readme 2010-06-30 21:32:44 -04:00
David Dollar
ddccab4c63 0.5.0 2010-06-30 21:32:38 -04:00
David Dollar
3151663f37 add -p flag to specify the base port for apps 2010-06-30 21:32:26 -04:00
David Dollar
98486513b6 switch procfile option to -f 2010-06-30 21:18:30 -04:00
David Dollar
b969e03086 pedantry 2010-06-29 20:42:06 -04:00
David Dollar
be593846e2 Regenerated gemspec for version 0.4.7 2010-06-29 17:08:49 -04:00
David Dollar
2458c4e75f 0.4.7 2010-06-29 17:08:46 -04:00
David Dollar
314e2f5530 fix -l, dont append app name 2010-06-29 17:08:30 -04:00
10 changed files with 52 additions and 34 deletions

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
@@ -58,7 +62,7 @@ The following options control how the application is run:
These options control all modes of foreman's operation.
* `-p`, `--procfile`
* `-f`, `--procfile`
Specify an alternate location for the application's Procfile. This file's
containing directory will be assumed to be the root directory of the
application.

View File

@@ -1,8 +1,8 @@
pre-start script
bash << "EOF"
mkdir -p <%= log_root %>/<%= app %>
chown -R <%= user %> <%= log_root %>/<%= app %>
mkdir -p <%= log_root %>
chown -R <%= user %> <%= log_root %>
EOF
end script

View File

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

View File

@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{foreman}
s.version = "0.4.6"
s.version = "0.5.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["David Dollar"]
s.date = %q{2010-06-29}
s.date = %q{2010-06-30}
s.default_executable = %q{foreman}
s.description = %q{Process manager for applications with multiple components}
s.email = %q{ddollar@gmail.com}

View File

@@ -1,6 +1,6 @@
module Foreman
VERSION = "0.4.6"
VERSION = "0.5.0"
class AppDoesNotExist < Exception; end

View File

@@ -5,7 +5,7 @@ require "thor"
class Foreman::CLI < Thor
class_option :procfile, :type => :string, :aliases => "-p", :desc => "Default: ./Procfile"
class_option :procfile, :type => :string, :aliases => "-f", :desc => "Default: ./Procfile"
desc "start [PROCESS]", "Start the application, or a specific process"
@@ -13,7 +13,7 @@ class Foreman::CLI < Thor
def start(process=nil)
check_procfile!
if process
engine.execute(process)
elsif options[:screen]
@@ -25,11 +25,13 @@ 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)
check_procfile!
@@ -39,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

@@ -7,23 +7,28 @@ class Foreman::Export::Inittab < Foreman::Export::Base
user = options[:user] || app
log_root = options[:log] || "/var/log"
log_dir = "#{log_root}/#{app}"
concurrency = parse_concurrency(options[:concurrency])
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_dir}/#{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"
if fname
FileUtils.mkdir_p(log_dir)
FileUtils.chown(user, nil, log_dir)
FileUtils.mkdir_p(log_root)
FileUtils.chown(user, nil, log_root)
write_file(fname, inittab)
else
puts inittab

View File

@@ -10,7 +10,7 @@ class Foreman::Export::Upstart < Foreman::Export::Base
app = options[:app] || File.basename(engine.directory)
user = options[:user] || app
log_root = options[:log] || "/var/log"
log_root = options[:log] || "/var/log/#{app}"
Dir["#{location}/#{app}*.conf"].each do |file|
say "cleaning up: #{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
@@ -58,7 +62,7 @@ The following options control how the application is run:
These options control all modes of foreman's operation.
* `-p`, `--procfile`
* `-f`, `--procfile`
Specify an alternate location for the application's Procfile. This file's
containing directory will be assumed to be the root directory of the
application.