Added the ability to use template configuration files using the '--template [-t]' command line option. This allows you to create a directory on the file system containing your configuration files which Foreman will read from instead of the default templates.

This commit is contained in:
Michael van Rooijen
2011-06-26 19:02:51 +02:00
parent 927a57f738
commit e8d2552caa
3 changed files with 12 additions and 5 deletions
+1
View File
@@ -30,6 +30,7 @@ class Foreman::CLI < Thor
method_option :log, :type => :string, :aliases => "-l"
method_option :port, :type => :numeric, :aliases => "-p"
method_option :user, :type => :string, :aliases => "-u"
method_option :template, :type => :string, :aliases => "-t"
method_option :concurrency, :type => :string, :aliases => "-c",
:banner => '"alpha=5,bar=3"'
+7 -2
View File
@@ -4,6 +4,7 @@ require "foreman/utils"
class Foreman::Export::Base
attr_reader :engine
attr_accessor :template
def initialize(engine)
@engine = engine
@@ -23,8 +24,12 @@ private ######################################################################
puts "[foreman export] %s" % message
end
def export_template(name)
File.read(File.expand_path("../../../../data/export/#{name}", __FILE__))
def export_template(path, file)
if template and File.exist?(file_path = File.join(template, file))
File.read(file_path)
else
File.read(File.expand_path("../../../../data/export/#{path}/#{file}", __FILE__))
end
end
def write_file(filename, contents)
+4 -3
View File
@@ -11,6 +11,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/#{app}"
self.template = options[:template]
Dir["#{location}/#{app}*.conf"].each do |file|
say "cleaning up: #{file}"
@@ -19,14 +20,14 @@ class Foreman::Export::Upstart < Foreman::Export::Base
concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])
master_template = export_template("upstart/master.conf.erb")
master_template = export_template("upstart", "master.conf.erb")
master_config = ERB.new(master_template).result(binding)
write_file "#{location}/#{app}.conf", master_config
process_template = export_template("upstart/process.conf.erb")
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_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