allow old exporter format to work, but with deprecation warning
This commit is contained in:
1 parent
4a732abd77
commit
1a0943c495
3 files changed
+87
-17
No files matched your search
+21
-8
@@ -24,7 +24,7 @@ class Foreman::Engine
|
|||||||
def initialize(options={})
|
def initialize(options={})
|
||||||
@options = options.dup
|
@options = options.dup
|
||||||
|
|
||||||
@options[:formation] ||= "all=1"
|
@options[:formation] ||= (options[:concurrency] || "all=1")
|
||||||
|
|
||||||
@env = {}
|
@env = {}
|
||||||
@mutex = Mutex.new
|
@mutex = Mutex.new
|
||||||
@@ -157,8 +157,25 @@ class Foreman::Engine
|
|||||||
#
|
#
|
||||||
# @returns [Fixnum] port The port to use for this instance of this process
|
# @returns [Fixnum] port The port to use for this instance of this process
|
||||||
#
|
#
|
||||||
def port_for(process, instance)
|
def port_for(process, instance, base=nil)
|
||||||
base_port + (@processes.index(process) * 100) + (instance - 1)
|
if base
|
||||||
|
base + (@processes.index(process.process) * 100) + (instance - 1)
|
||||||
|
else
|
||||||
|
base_port + (@processes.index(process) * 100) + (instance - 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get the base port for this foreman instance
|
||||||
|
#
|
||||||
|
# @returns [Fixnum] port The base port
|
||||||
|
#
|
||||||
|
def base_port
|
||||||
|
(options[:port] || env["PORT"] || ENV["PORT"] || 5000).to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
# deprecated
|
||||||
|
def environment
|
||||||
|
env
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -179,10 +196,6 @@ private
|
|||||||
|
|
||||||
## Helpers ##########################################################
|
## Helpers ##########################################################
|
||||||
|
|
||||||
def base_port
|
|
||||||
(options[:port] || env["PORT"] || ENV["PORT"] || 5000).to_i
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_pipe
|
def create_pipe
|
||||||
IO.method(:pipe).arity.zero? ? IO.pipe : IO.pipe("BINARY")
|
IO.method(:pipe).arity.zero? ? IO.pipe : IO.pipe("BINARY")
|
||||||
end
|
end
|
||||||
@@ -193,7 +206,7 @@ private
|
|||||||
end
|
end
|
||||||
|
|
||||||
def parse_formation(formation)
|
def parse_formation(formation)
|
||||||
pairs = @options[:formation].to_s.gsub(/\s/, "").split(",")
|
pairs = formation.to_s.gsub(/\s/, "").split(",")
|
||||||
|
|
||||||
pairs.inject(Hash.new(0)) do |ax, pair|
|
pairs.inject(Hash.new(0)) do |ax, pair|
|
||||||
process, amount = pair.split("=")
|
process, amount = pair.split("=")
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
require "foreman"
|
require "foreman"
|
||||||
require "foreman/helpers"
|
require "foreman/helpers"
|
||||||
|
require "pathname"
|
||||||
|
|
||||||
module Foreman::Export
|
module Foreman::Export
|
||||||
extend Foreman::Helpers
|
extend Foreman::Helpers
|
||||||
@@ -31,4 +32,3 @@ require "foreman/export/bluepill"
|
|||||||
require "foreman/export/runit"
|
require "foreman/export/runit"
|
||||||
require "foreman/export/supervisord"
|
require "foreman/export/supervisord"
|
||||||
require "foreman/export/launchd"
|
require "foreman/export/launchd"
|
||||||
|
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
require "foreman/export"
|
require "foreman/export"
|
||||||
|
require "ostruct"
|
||||||
|
require "pathname"
|
||||||
require "shellwords"
|
require "shellwords"
|
||||||
|
|
||||||
class Foreman::Export::Base
|
class Foreman::Export::Base
|
||||||
@@ -8,11 +10,37 @@ class Foreman::Export::Base
|
|||||||
attr_reader :options
|
attr_reader :options
|
||||||
attr_reader :formation
|
attr_reader :formation
|
||||||
|
|
||||||
|
# deprecated
|
||||||
|
attr_reader :port
|
||||||
|
|
||||||
def initialize(location, engine, options={})
|
def initialize(location, engine, options={})
|
||||||
@location = location
|
@location = location
|
||||||
@engine = engine
|
@engine = engine
|
||||||
@options = options.dup
|
@options = options.dup
|
||||||
@formation = engine.formation
|
@formation = engine.formation
|
||||||
|
|
||||||
|
# deprecated
|
||||||
|
def port
|
||||||
|
Foreman::Export::Base.warn_deprecation!
|
||||||
|
engine.base_port
|
||||||
|
end
|
||||||
|
|
||||||
|
# deprecated
|
||||||
|
def template
|
||||||
|
Foreman::Export::Base.warn_deprecation!
|
||||||
|
options[:template]
|
||||||
|
end
|
||||||
|
|
||||||
|
# deprecated
|
||||||
|
def @engine.procfile
|
||||||
|
Foreman::Export::Base.warn_deprecation!
|
||||||
|
@processes.map do |process|
|
||||||
|
OpenStruct.new(
|
||||||
|
:name => @names[process],
|
||||||
|
:process => process
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def export
|
def export
|
||||||
@@ -36,6 +64,18 @@ class Foreman::Export::Base
|
|||||||
|
|
||||||
private ######################################################################
|
private ######################################################################
|
||||||
|
|
||||||
|
def self.warn_deprecation!
|
||||||
|
@@deprecation_warned ||= false
|
||||||
|
return if @@deprecation_warned
|
||||||
|
puts "WARNING: Using deprecated exporter interface. Please update your exporter"
|
||||||
|
puts "the interface shown in the upstart exporter:"
|
||||||
|
puts
|
||||||
|
puts "https://github.com/ddollar/foreman/blob/master/lib/foreman/export/upstart.rb"
|
||||||
|
puts "https://github.com/ddollar/foreman/blob/master/data/export/upstart/process.conf.erb"
|
||||||
|
puts
|
||||||
|
@@deprecation_warned = true
|
||||||
|
end
|
||||||
|
|
||||||
def error(message)
|
def error(message)
|
||||||
raise Foreman::Export::Exception.new(message)
|
raise Foreman::Export::Exception.new(message)
|
||||||
end
|
end
|
||||||
@@ -54,13 +94,28 @@ private ######################################################################
|
|||||||
'"' + Shellwords.escape(value) + '"'
|
'"' + Shellwords.escape(value) + '"'
|
||||||
end
|
end
|
||||||
|
|
||||||
def export_template(name)
|
# deprecated
|
||||||
name_without_first = name.split("/")[1..-1].join("/")
|
def old_export_template(exporter, file, template_root)
|
||||||
matchers = []
|
if template_root && File.exist?(file_path = File.join(template_root, file))
|
||||||
matchers << File.join(options[:template], name_without_first) if options[:template]
|
File.read(file_path)
|
||||||
matchers << File.expand_path("~/.foreman/templates/#{name}")
|
elsif File.exist?(file_path = File.expand_path(File.join("~/.foreman/templates", file)))
|
||||||
matchers << File.expand_path("../../../../data/export/#{name}", __FILE__)
|
File.read(file_path)
|
||||||
File.read(matchers.detect { |m| File.exists?(m) })
|
else
|
||||||
|
File.read(File.expand_path("../../../../data/export/#{exporter}/#{file}", __FILE__))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def export_template(name, file=nil, template_root=nil)
|
||||||
|
if file && template_root
|
||||||
|
old_export_template name, file, template_root
|
||||||
|
else
|
||||||
|
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__)
|
||||||
|
File.read(matchers.detect { |m| File.exists?(m) })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_template(name, target, binding)
|
def write_template(name, target, binding)
|
||||||
@@ -81,7 +136,9 @@ private ######################################################################
|
|||||||
def write_file(filename, contents)
|
def write_file(filename, contents)
|
||||||
say "writing: #{filename}"
|
say "writing: #{filename}"
|
||||||
|
|
||||||
File.open(File.join(location, filename), "w") do |file|
|
filename = File.join(location, filename) unless Pathname.new(filename).absolute?
|
||||||
|
|
||||||
|
File.open(filename, "w") do |file|
|
||||||
file.puts contents
|
file.puts contents
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in new issue
Block a user