Test new interface

This commit is contained in:
Emile Cantin 2012-09-11 11:12:40 -04:00
parent 63ef82c621
commit bdf4c92b72
3 changed files with 9 additions and 17 deletions

View File

@ -39,8 +39,8 @@ USERNAME=<%= user %>
do_start() do_start()
{ {
mkdir -p $PIDDIR mkdir -p $PIDDIR
mkdir -p <%= log_root %> mkdir -p <%= log %>
chown $USERNAME: <%= log_root %> chown $USERNAME: <%= log %>
# START APPLICATION: <%= app %> # START APPLICATION: <%= app %>
<% engine.procfile.entries.each do |process| %> <% engine.procfile.entries.each do |process| %>
# START PROCESS: <%= process.name %> # START PROCESS: <%= process.name %>
@ -48,7 +48,7 @@ do_start()
# START CONCURRENT: <%= num %> # START CONCURRENT: <%= num %>
# Start: <%= app %>.<%= process.name %>.<%= num %> # Start: <%= app %>.<%= process.name %>.<%= num %>
# Create $PIDDIR/<%= process.name %>.<%= num %>.pid # 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 %>
<% end %> <% end %>

View File

@ -4,24 +4,15 @@ require "foreman/export"
class Foreman::Export::Initscript < Foreman::Export::Base class Foreman::Export::Initscript < Foreman::Export::Base
def export def export
error("Must specify a location") unless location
FileUtils.mkdir_p location super
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
Dir["#{location}/#{app}"].each do |file| Dir["#{location}/#{app}"].each do |file|
say "cleaning up: #{file}" say "cleaning up: #{file}"
FileUtils.rm(file) clean file
end end
master_template = export_template("initscript", "master.erb", template_root) write_template "initscript/master.erb", "#{app}", binding
master_config = ERB.new(master_template).result(binding)
write_file "#{location}/#{app}", master_config
end end
end end

View File

@ -5,7 +5,8 @@ require "tmpdir"
describe Foreman::Export::Initscript, :fakefs do describe Foreman::Export::Initscript, :fakefs do
let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") } let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
let(:engine) { Foreman::Engine.new(procfile) } let(:formation) { nil }
let(:engine) { Foreman::Engine.new(:formation => formation).load_procfile(procfile) }
let(:options) { Hash.new } let(:options) { Hash.new }
let(:initscript) { Foreman::Export::Initscript.new("/tmp/init", engine, options) } let(:initscript) { Foreman::Export::Initscript.new("/tmp/init", engine, options) }