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:
1 parent
927a57f738
commit
e8d2552caa
3 files changed
+12
-5
No files matched your search
@@ -30,6 +30,7 @@ class Foreman::CLI < Thor
|
|||||||
method_option :log, :type => :string, :aliases => "-l"
|
method_option :log, :type => :string, :aliases => "-l"
|
||||||
method_option :port, :type => :numeric, :aliases => "-p"
|
method_option :port, :type => :numeric, :aliases => "-p"
|
||||||
method_option :user, :type => :string, :aliases => "-u"
|
method_option :user, :type => :string, :aliases => "-u"
|
||||||
|
method_option :template, :type => :string, :aliases => "-t"
|
||||||
method_option :concurrency, :type => :string, :aliases => "-c",
|
method_option :concurrency, :type => :string, :aliases => "-c",
|
||||||
:banner => '"alpha=5,bar=3"'
|
:banner => '"alpha=5,bar=3"'
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ require "foreman/utils"
|
|||||||
class Foreman::Export::Base
|
class Foreman::Export::Base
|
||||||
|
|
||||||
attr_reader :engine
|
attr_reader :engine
|
||||||
|
attr_accessor :template
|
||||||
|
|
||||||
def initialize(engine)
|
def initialize(engine)
|
||||||
@engine = engine
|
@engine = engine
|
||||||
@@ -23,8 +24,12 @@ private ######################################################################
|
|||||||
puts "[foreman export] %s" % message
|
puts "[foreman export] %s" % message
|
||||||
end
|
end
|
||||||
|
|
||||||
def export_template(name)
|
def export_template(path, file)
|
||||||
File.read(File.expand_path("../../../../data/export/#{name}", __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
|
end
|
||||||
|
|
||||||
def write_file(filename, contents)
|
def write_file(filename, contents)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class Foreman::Export::Upstart < Foreman::Export::Base
|
|||||||
app = options[:app] || File.basename(engine.directory)
|
app = options[:app] || File.basename(engine.directory)
|
||||||
user = options[:user] || app
|
user = options[:user] || app
|
||||||
log_root = options[:log] || "/var/log/#{app}"
|
log_root = options[:log] || "/var/log/#{app}"
|
||||||
|
self.template = options[:template]
|
||||||
|
|
||||||
Dir["#{location}/#{app}*.conf"].each do |file|
|
Dir["#{location}/#{app}*.conf"].each do |file|
|
||||||
say "cleaning up: #{file}"
|
say "cleaning up: #{file}"
|
||||||
@@ -19,14 +20,14 @@ class Foreman::Export::Upstart < Foreman::Export::Base
|
|||||||
|
|
||||||
concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])
|
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)
|
master_config = ERB.new(master_template).result(binding)
|
||||||
write_file "#{location}/#{app}.conf", master_config
|
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|
|
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)
|
process_master_config = ERB.new(process_master_template).result(binding)
|
||||||
write_file "#{location}/#{app}-#{process.name}.conf", process_master_config
|
write_file "#{location}/#{app}-#{process.name}.conf", process_master_config
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user