Compare commits

...
17 Commits
Author SHA1 Message Date
David Dollar 7fdade277c 0.48.0 2012-07-10 15:06:22 -04:00
David Dollar 1a0943c495 allow old exporter format to work, but with deprecation warning 2012-07-10 15:06:22 -04:00
David Dollar 4a732abd77 remove debugging code 2012-07-10 15:06:22 -04:00
David Dollar 3e71fea777 Merge pull request #219 from MarkDBlackwell/patch-1
Avoid crash by verifying the existence of SIGHUP before accessing it.
2012-07-09 06:30:14 -07:00
Mark D. Blackwell ae7aeabb63 Avoid crash by verifying the existence of SIGHUP before accessing it. 2012-07-08 16:21:27 -03:00
David Dollar 9901b9f924 0.48.0.pre3 2012-06-18 00:11:43 -04:00
David Dollar 4c2d569810 0.48.0.pre2 2012-06-18 00:11:23 -04:00
David Dollar 26f9c8186d allow color to be forced on 2012-06-18 00:11:23 -04:00
David Dollar 24ed8946f3 terminate gracefully if stdout goes away 2012-06-18 00:11:23 -04:00
David Dollar 83b2a9cc50 always flush output 2012-06-18 00:11:22 -04:00
David Dollar a0228b9fa0 Merge pull request #212 from morgoth/added-version-command
added command for displaying foreman version
2012-06-12 09:37:07 -07:00
Wojciech Wnętrzak b1a2a4a0cd added command for displaying foreman version 2012-06-12 17:16:35 +02:00
David Dollar 7774b7f150 Merge pull request #211 from morgoth/fixed-yaml-usage
fixed using YAML
2012-06-11 12:57:24 -07:00
Wojciech Wnętrzak b01355a093 fixed using YAML 2012-06-11 21:42:59 +02:00
David Dollar 8b18143281 test on more things, but don't fail 2012-06-11 13:34:08 -04:00
David Dollar e06886ed57 changelog 2012-06-11 12:34:16 -04:00
David Dollar d6a00d7262 0.48.0.pre1 2012-06-11 12:27:20 -04:00
12 changed files with 154 additions and 35 deletions
+14 -3
View File
@@ -1,8 +1,11 @@
script: bundle exec rake spec script: bundle exec rake spec
rvm: matrix:
- 1.9.2 allow_failures:
- 1.9.3 - rvm: 1.8.7
- rvm: jruby
- rvm: rbx
- rvm: ree
notifications: notifications:
email: false email: false
@@ -11,3 +14,11 @@ notifications:
on_failure: always on_failure: always
urls: urls:
- http://dx-helper.herokuapp.com/travis - http://dx-helper.herokuapp.com/travis
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- jruby
- rbx
- ree
+17
View File
@@ -1,3 +1,20 @@
## 0.48.0.pre1 (2012-06-11)
* Massive refactoring for programmatic control and stability [David Dollar]
* Procfile commands with shell interpolations now work again [David Dollar]
* Stop trying to test on Ruby 1.8 [David Dollar]
## 0.47.0 (2012-06-07)
* Fix multi-word argument handling in `foreman run`. [Daniel Brockman]
* Make 'PORT=5000 foreman start' work [Koen Van der Auwera]
* Terminate gracefully upon SIGHUP [Stefan Schüßler]
* Set port from .env if specified [Koen Van der Auwera]
* Updated bluepill exporter to use environment variables from .env [Aneeth]
* Added launchd exporter [Maxwell Swadling]
* Quote and escape environment variables in upstart templates [Matt Griffin]
* Added list of ports to other languages to README [elf Pavlik]
## 0.46.0 (2012-05-02) ## 0.46.0 (2012-05-02)
* Add Profile load/write/append API [Michael Granger] * Add Profile load/write/append API [Michael Granger]
+2 -2
View File
@@ -1,7 +1,7 @@
PATH PATH
remote: . remote: .
specs: specs:
foreman (0.47.0) foreman (0.48.0)
thor (>= 0.13.6) thor (>= 0.13.6)
GEM GEM
@@ -39,7 +39,7 @@ GEM
multi_json (~> 1.0.3) multi_json (~> 1.0.3)
simplecov-html (~> 0.5.3) simplecov-html (~> 0.5.3)
simplecov-html (0.5.3) simplecov-html (0.5.3)
thor (0.14.6) thor (0.15.3)
timecop (0.3.5) timecop (0.3.5)
win32console (1.3.0-x86-mingw32) win32console (1.3.0-x86-mingw32)
xml-simple (1.0.15) xml-simple (1.0.15)
+13 -6
View File
@@ -3,18 +3,23 @@ require "foreman/helpers"
require "foreman/engine" require "foreman/engine"
require "foreman/engine/cli" require "foreman/engine/cli"
require "foreman/export" require "foreman/export"
require "foreman/version"
require "shellwords" require "shellwords"
require "yaml"
require "thor" require "thor"
class Foreman::CLI < Thor class Foreman::CLI < Thor
include Foreman::Helpers include Foreman::Helpers
map ["-v", "--version"] => :version
class_option :procfile, :type => :string, :aliases => "-f", :desc => "Default: Procfile" class_option :procfile, :type => :string, :aliases => "-f", :desc => "Default: Procfile"
class_option :root, :type => :string, :aliases => "-d", :desc => "Default: Procfile directory" class_option :root, :type => :string, :aliases => "-d", :desc => "Default: Procfile directory"
desc "start [PROCESS]", "Start the application (or a specific PROCESS)" desc "start [PROCESS]", "Start the application (or a specific PROCESS)"
method_option :color, :type => :boolean, :aliases => "-c", :desc => "Force color to be enabled"
method_option :env, :type => :string, :aliases => "-e", :desc => "Specify an environment file to load, defaults to .env" method_option :env, :type => :string, :aliases => "-e", :desc => "Specify an environment file to load, defaults to .env"
method_option :formation, :type => :string, :aliases => "-m", :banner => '"alpha=5,bar=3"' method_option :formation, :type => :string, :aliases => "-m", :banner => '"alpha=5,bar=3"'
method_option :port, :type => :numeric, :aliases => "-p" method_option :port, :type => :numeric, :aliases => "-p"
@@ -79,15 +84,17 @@ class Foreman::CLI < Thor
end end
end end
desc "version", "Display Foreman gem version"
def version
puts Foreman::VERSION
end
no_tasks do no_tasks do
def engine def engine
@engine ||= begin @engine ||= begin
engine_class = Foreman::Engine::CLI engine_class = Foreman::Engine::CLI
engine = engine_class.new( engine = engine_class.new(options)
:formation => options[:formation],
:port => options[:port],
:root => options[:root]
)
engine engine
end end
end end
@@ -126,7 +133,7 @@ private ######################################################################
def options def options
original_options = super original_options = super
return original_options unless File.exists?(".foreman") return original_options unless File.exists?(".foreman")
defaults = YAML::load_file(".foreman") || {} defaults = ::YAML::load_file(".foreman") || {}
Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options)) Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
end end
+23 -10
View File
@@ -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
@@ -39,7 +39,7 @@ class Foreman::Engine
def start def start
trap("TERM") { puts "SIGTERM received"; terminate_gracefully } trap("TERM") { puts "SIGTERM received"; terminate_gracefully }
trap("INT") { puts "SIGINT received"; terminate_gracefully } trap("INT") { puts "SIGINT received"; terminate_gracefully }
trap("HUP") { puts "SIGHUP received"; terminate_gracefully } trap("HUP") { puts "SIGHUP received"; terminate_gracefully } if ::Signal.list.keys.include? 'HUP'
startup startup
spawn_processes spawn_processes
@@ -154,11 +154,28 @@ class Foreman::Engine
# #
# @param [Foreman::Process] process A +Process+ associated with this engine # @param [Foreman::Process] process A +Process+ associated with this engine
# @param [Fixnum] instance The instance of the process # @param [Fixnum] instance The instance of the process
# #
# @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("=")
+7 -2
View File
@@ -24,11 +24,13 @@ class Foreman::Engine::CLI < Foreman::Engine
:bright_white => 37, :bright_white => 37,
} }
def self.enable(io) def self.enable(io, force=false)
io.extend(self) io.extend(self)
@@color_force = force
end end
def color? def color?
return true if @@color_force
return false unless self.respond_to?(:isatty) return false unless self.respond_to?(:isatty)
self.isatty && ENV["TERM"] self.isatty && ENV["TERM"]
end end
@@ -51,14 +53,17 @@ class Foreman::Engine::CLI < Foreman::Engine
def output(name, data) def output(name, data)
data.to_s.chomp.split("\n").each do |message| data.to_s.chomp.split("\n").each do |message|
Color.enable($stdout) unless $stdout.respond_to?(:color?) Color.enable($stdout, options[:color]) unless $stdout.respond_to?(:color?)
output = "" output = ""
output += $stdout.color(@colors[name.split(".").first].to_sym) output += $stdout.color(@colors[name.split(".").first].to_sym)
output += "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(name)} | " output += "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(name)} | "
output += $stdout.color(:reset) output += $stdout.color(:reset)
output += message output += message
$stdout.puts output $stdout.puts output
$stdout.flush
end end
rescue Errno::EPIPE
terminate_gracefully
end end
def shutdown def shutdown
+1 -1
View File
@@ -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"
+65 -8
View File
@@ -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
+1 -1
View File
@@ -1,5 +1,5 @@
module Foreman module Foreman
VERSION = "0.47.0" VERSION = "0.48.0"
end end
+10
View File
@@ -74,4 +74,14 @@ describe "Foreman::CLI", :fakefs do
end end
end end
describe "version" do
it "displays gem version" do
foreman("version").chomp.should == Foreman::VERSION
end
it "displays gem version on shortcut command" do
foreman("-v").chomp.should == Foreman::VERSION
end
end
end end
-1
View File
@@ -54,7 +54,6 @@ def fork_and_capture(&blk)
Process.wait pid Process.wait pid
buffer = "" buffer = ""
until rd.eof? until rd.eof?
p [:foo]
buffer += rd.gets buffer += rd.gets
end end
end end
+1 -1
View File
@@ -35,7 +35,7 @@ def newer_release
tags = %x{ git tag --contains v#{latest_release} }.split("\n").sort_by do |tag| tags = %x{ git tag --contains v#{latest_release} }.split("\n").sort_by do |tag|
Gem::Version.new(tag[1..-1]) Gem::Version.new(tag[1..-1])
end end
tags.reject { |tag| Gem::Version.new(tag[1..-1]).prerelease? }[1] tags[1]
end end
desc "Generate a Changelog" desc "Generate a Changelog"