diff --git a/data/export/initscript/master.erb b/data/export/initscript/master.erb index ede26f6..bde3963 100644 --- a/data/export/initscript/master.erb +++ b/data/export/initscript/master.erb @@ -42,13 +42,13 @@ do_start() mkdir -p <%= log %> chown $USERNAME: <%= log %> # START APPLICATION: <%= app %> - <% engine.procfile.entries.each do |process| %> - # START PROCESS: <%= process.name %> - <% 1.upto(concurrency[process.name]) do |num| %> + <% engine.each_process do |name, process| %> + # START PROCESS: <%= name %> + <% 1.upto(engine.formation[name]) do |num| %> # START CONCURRENT: <%= num %> - # Start: <%= app %>.<%= process.name %>.<%= num %> - # Create $PIDDIR/<%= process.name %>.<%= num %>.pid - su - $USERNAME -c 'cd <%= engine.directory %>; export PORT=<%= engine.port_for(process, num, self.port) %>;<% engine.environment.each_pair do |var,env| %> export <%= var.upcase %>=<%= env %>; <% end %> <%= process.command %> >> <%= log %>/<%=process.name%>-<%=num%>.log 2>&1 & echo $!' > $PIDDIR/<%= process.name %>.<%= num %>.pid + # Start: <%= app %>.<%= name %>.<%= num %> + # Create $PIDDIR/<%= name %>.<%= num %>.pid + su - $USERNAME -c 'cd <%= engine.root %>; export PORT=<%= engine.port_for(process, num) %>;<% engine.environment.each_pair do |var,env| %> export <%= var.upcase %>=<%= env %>; <% end %> <%= process.command %> >> <%= log %>/<%=name%>-<%=num%>.log 2>&1 & echo $!' > $PIDDIR/<%= name %>.<%= num %>.pid <% end %> <% end %> @@ -60,13 +60,13 @@ do_start() do_stop() { # STOP APPLICATION: <%= app %> - <% engine.procfile.entries.each do |process| %> - # STOP PROCESS: <%= process.name %> - <% 1.upto(concurrency[process.name]) do |num| %> + <% engine.each_process do |name, process| %> + # STOP PROCESS: <%= name %> + <% 1.upto(engine.formation[name]) do |num| %> # STOP CONCURRENT: <%= num %> - # Stop: <%= app %>.<%= process.name %>.<%= num %> - kill `cat $PIDDIR/<%= process.name %>.<%= num %>.pid` - rm $PIDDIR/<%= process.name %>.<%= num %>.pid + # Stop: <%= app %>.<%= name %>.<%= num %> + kill `cat $PIDDIR/<%= name %>.<%= num %>.pid` + rm $PIDDIR/<%= name %>.<%= num %>.pid <% end %> <% end %> rmdir $PIDDIR diff --git a/lib/foreman/export/initscript.rb b/lib/foreman/export/initscript.rb index ee300f0..0ab681b 100644 --- a/lib/foreman/export/initscript.rb +++ b/lib/foreman/export/initscript.rb @@ -5,14 +5,27 @@ class Foreman::Export::Initscript < Foreman::Export::Base def export - super + #super + error("Must specify a location") unless location + FileUtils.mkdir_p(location) rescue error("Could not create: #{location}") + FileUtils.mkdir_p(log) rescue error("Could not create: #{log}") +# begin +# FileUtils.chown(user, nil, log) +# rescue Exception => e +# error("Could not chown #{log} to #{user} - #{e.message}") +# end - Dir["#{location}/#{app}"].each do |file| - say "cleaning up: #{file}" - clean file - end - - write_template "initscript/master.erb", "#{app}", binding + name = "initscript/master.erb" + name_without_first = name.split("/")[1..-1].join("/") + matchers = [] + matchers << File.join(options[:template], name_without_first) if options[:template] + matchers << File.expand_path("~/.foreman/templates/#{name}") + matchers << File.expand_path("../../../../data/export/#{name}", __FILE__) + path = File.read(matchers.detect { |m| File.exists?(m) }) + compiled = ERB.new(path).result(binding) + write_file "#{app}", compiled +# path = export_template name +# write_template "initscript/master.erb", "#{app}", binding end end diff --git a/spec/foreman/export/initscript_spec.rb b/spec/foreman/export/initscript_spec.rb index 664df39..e93c619 100644 --- a/spec/foreman/export/initscript_spec.rb +++ b/spec/foreman/export/initscript_spec.rb @@ -8,7 +8,7 @@ describe Foreman::Export::Initscript, :fakefs do let(:formation) { nil } let(:engine) { Foreman::Engine.new(:formation => formation).load_procfile(procfile) } let(:options) { Hash.new } - let(:initscript) { Foreman::Export::Initscript.new("/tmp/init", engine, options) } + let(:initscript) { FileUtils.mkdir_p("/tmp/init"); Foreman::Export::Initscript.new("/tmp/init", engine, options) } before(:each) { load_export_templates_into_fakefs("initscript") } before(:each) { stub(initscript).say } @@ -18,14 +18,6 @@ describe Foreman::Export::Initscript, :fakefs do normalize_space(File.read("/tmp/init/app")).should == normalize_space(example_export_file("initscript/app")) end -# it "cleans up if exporting into an existing dir" do -# mock(FileUtils).rm("/tmp/init/app") -# -# initscript.export -# #require 'debug' -# initscript.export -# end - context "with concurrency" do let(:options) { Hash[:concurrency => "alpha=2"] }