diff --git a/export/upstart/master.conf.erb b/export/upstart/master.conf.erb index dd1a739..130f2d0 100644 --- a/export/upstart/master.conf.erb +++ b/export/upstart/master.conf.erb @@ -2,12 +2,6 @@ pre-start script bash << "EOF" mkdir -p /var/log/<%= app %> - - <% engine.processes.keys.sort.each do |process| %> - <% 1.upto(concurrency[process]).each do |num| %> - start <%=app%>-<%=process%>-<%=num%> - <% end %> - <% end %> EOF end script diff --git a/export/upstart/process.conf.erb b/export/upstart/process.conf.erb index 692c71a..3dbe96b 100644 --- a/export/upstart/process.conf.erb +++ b/export/upstart/process.conf.erb @@ -1,5 +1,6 @@ -stop on stopping <%= app %> +start on starting <%= app %>-<%= process.name %> +stop on stopping <%= app %>-<%= process.name %> respawn chdir <%= engine.directory %> -exec <%= process.command %> >> /var/log/<%=app%>/<%=process.name%>-<%=num%>.log 2>&1 +exec sudo -u <%= user %> <%= process.command %> >> /var/log/<%=app%>/<%=process.name%>-<%=num%>.log 2>&1 diff --git a/export/upstart/process_master.conf.erb b/export/upstart/process_master.conf.erb new file mode 100644 index 0000000..c9cc851 --- /dev/null +++ b/export/upstart/process_master.conf.erb @@ -0,0 +1,2 @@ +start on starting <%= app %> +stop on stopping <%= app %> diff --git a/lib/foreman/cli.rb b/lib/foreman/cli.rb index 6a2a9d3..c1b7dc3 100644 --- a/lib/foreman/cli.rb +++ b/lib/foreman/cli.rb @@ -26,9 +26,9 @@ 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 :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,6 +39,7 @@ class Foreman::CLI < Thor formatter.new(engine).export(location, :name => options[:app], + :user => options[:user], :concurrency => options[:concurrency] ) rescue Foreman::Export::Exception => ex diff --git a/lib/foreman/export/upstart.rb b/lib/foreman/export/upstart.rb index 7888ca9..810ab17 100644 --- a/lib/foreman/export/upstart.rb +++ b/lib/foreman/export/upstart.rb @@ -9,6 +9,7 @@ class Foreman::Export::Upstart < Foreman::Export::Base FileUtils.mkdir_p location app = options[:app] || File.basename(engine.directory) + user = options[:user] || app Dir["#{location}/#{app}*.conf"].each do |file| say "cleaning up: #{file}" @@ -24,6 +25,10 @@ class Foreman::Export::Upstart < Foreman::Export::Base process_template = export_template("upstart/process.conf.erb") engine.processes.values.each do |process| + process_master_template = export_template("upstart/process_master.conf.erb") + process_master_config = ERB.new(process_master_template).result(binding) + write_file "#{location}/#{app}-#{process.name}.conf", process_master_config + 1.upto(concurrency[process.name]) do |num| process_config = ERB.new(process_template).result(binding) write_file "#{location}/#{app}-#{process.name}-#{num}.conf", process_config diff --git a/man/foreman.1.ronn b/man/foreman.1.ronn index 6036427..8c80e0f 100644 --- a/man/foreman.1.ronn +++ b/man/foreman.1.ronn @@ -47,6 +47,10 @@ The following options control how the application is run: Specify the number of each process type to run. The value passed in should be in the format `process=num,process=num` + * `-u`, `--user`: + Specify the user the application should be run as. Defaults to the + app name + ## OPTIONS These options control all modes of foreman's operation.