From bdf4c92b72f8ffbd3db6ff1ed161bbe4650f863f Mon Sep 17 00:00:00 2001 From: Emile Cantin Date: Tue, 11 Sep 2012 11:12:40 -0400 Subject: [PATCH] Test new interface --- data/export/initscript/master.erb | 6 +++--- lib/foreman/export/initscript.rb | 15 +++------------ spec/foreman/export/initscript_spec.rb | 5 +++-- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/data/export/initscript/master.erb b/data/export/initscript/master.erb index f9cc6a8..ede26f6 100644 --- a/data/export/initscript/master.erb +++ b/data/export/initscript/master.erb @@ -39,8 +39,8 @@ USERNAME=<%= user %> do_start() { mkdir -p $PIDDIR - mkdir -p <%= log_root %> - chown $USERNAME: <%= log_root %> + mkdir -p <%= log %> + chown $USERNAME: <%= log %> # START APPLICATION: <%= app %> <% engine.procfile.entries.each do |process| %> # START PROCESS: <%= process.name %> @@ -48,7 +48,7 @@ do_start() # 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_root %>/<%=process.name%>-<%=num%>.log 2>&1 & echo $!' > $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 <% end %> <% end %> diff --git a/lib/foreman/export/initscript.rb b/lib/foreman/export/initscript.rb index 231489b..ee300f0 100644 --- a/lib/foreman/export/initscript.rb +++ b/lib/foreman/export/initscript.rb @@ -4,24 +4,15 @@ require "foreman/export" class Foreman::Export::Initscript < Foreman::Export::Base def export - error("Must specify a location") unless location - FileUtils.mkdir_p location - - app = self.app || File.basename(engine.directory) - user = self.user || app - log_root = self.log || "/var/log/#{app}" - template_root = Pathname.new(File.dirname(__FILE__)).join('..', '..', '..', 'data', 'export', 'initscript').expand_path + super Dir["#{location}/#{app}"].each do |file| say "cleaning up: #{file}" - FileUtils.rm(file) + clean file end - master_template = export_template("initscript", "master.erb", template_root) - master_config = ERB.new(master_template).result(binding) - write_file "#{location}/#{app}", master_config - + 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 a299da0..664df39 100644 --- a/spec/foreman/export/initscript_spec.rb +++ b/spec/foreman/export/initscript_spec.rb @@ -5,8 +5,9 @@ require "tmpdir" describe Foreman::Export::Initscript, :fakefs do let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") } - let(:engine) { Foreman::Engine.new(procfile) } - let(:options) { Hash.new } + 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) } before(:each) { load_export_templates_into_fakefs("initscript") }