Compare commits
27 Commits
v0.48.0.pr
...
v0.51.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03e5342067 | ||
|
|
b1d57426fb | ||
|
|
06e5c52f35 | ||
|
|
64ca839c0b | ||
|
|
80aebda023 | ||
|
|
5dee2281a2 | ||
|
|
efb6d2f11d | ||
|
|
ac528d3b50 | ||
|
|
cefd4e351e | ||
|
|
9849f4558a | ||
|
|
4b53b42be1 | ||
|
|
219acaf690 | ||
|
|
f8118d7b40 | ||
|
|
7fdade277c | ||
|
|
1a0943c495 | ||
|
|
4a732abd77 | ||
|
|
3e71fea777 | ||
|
|
ae7aeabb63 | ||
|
|
9901b9f924 | ||
|
|
4c2d569810 | ||
|
|
26f9c8186d | ||
|
|
24ed8946f3 | ||
|
|
83b2a9cc50 | ||
|
|
a0228b9fa0 | ||
|
|
b1a2a4a0cd | ||
|
|
7774b7f150 | ||
|
|
b01355a093 |
36
Changelog.md
36
Changelog.md
@@ -1,8 +1,36 @@
|
||||
## 0.48.0.pre1 (2012-06-11)
|
||||
## 0.50.0 (2012-07-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]
|
||||
* handle windows [David Dollar]
|
||||
|
||||
## 0.49.0 (2012-07-11)
|
||||
|
||||
* 1.8 compatibility [David Dollar]
|
||||
* use one pgroup for all of foreman and kill that since ruby 1.8 sucks at pgroups [David Dollar]
|
||||
* better debugging [David Dollar]
|
||||
|
||||
## 0.48.0 (2012-07-10)
|
||||
|
||||
* allow old exporter format to work, but with deprecation warning [David Dollar]
|
||||
* remove debugging code [David Dollar]
|
||||
* Merge pull request #219 from MarkDBlackwell/patch-1 [David Dollar]
|
||||
* Avoid crash by verifying the existence of SIGHUP before accessing it. [Mark D. Blackwell]
|
||||
* allow color to be forced on [David Dollar]
|
||||
* terminate gracefully if stdout goes away [David Dollar]
|
||||
* always flush output [David Dollar]
|
||||
* Merge pull request #212 from morgoth/added-version-command [David Dollar]
|
||||
* added command for displaying foreman version [Wojciech Wnętrzak]
|
||||
* Merge pull request #211 from morgoth/fixed-yaml-usage [David Dollar]
|
||||
* fixed using YAML [Wojciech Wnętrzak]
|
||||
* test on more things, but don't fail [David Dollar]
|
||||
* changelog [David Dollar]
|
||||
* 0.48.0.pre1 [David Dollar]
|
||||
* foreman doesn't work on ruby 1.8, may try to fix later [David Dollar]
|
||||
* use bash [David Dollar]
|
||||
* massive refactoring for programmatic control and stability [David Dollar]
|
||||
* Merge pull request #164 from hsume2/master [David Dollar]
|
||||
* Only run tmux specs if tmux is installed [Henry Hsu]
|
||||
* Do not assume BUNDLE_GEMFILE [Henry Hsu]
|
||||
* Add support for starting procfile in tmux session [Henry Hsu]
|
||||
|
||||
## 0.47.0 (2012-06-07)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
foreman (0.48.0.pre2)
|
||||
foreman (0.51.0)
|
||||
thor (>= 0.13.6)
|
||||
|
||||
GEM
|
||||
@@ -39,7 +39,7 @@ GEM
|
||||
multi_json (~> 1.0.3)
|
||||
simplecov-html (~> 0.5.3)
|
||||
simplecov-html (0.5.3)
|
||||
thor (0.15.2)
|
||||
thor (0.15.4)
|
||||
timecop (0.3.5)
|
||||
win32console (1.3.0-x86-mingw32)
|
||||
xml-simple (1.0.15)
|
||||
|
||||
@@ -9,6 +9,6 @@ sigterm() {
|
||||
#trap sigterm SIGTERM
|
||||
|
||||
while true; do
|
||||
echo "$NAME: ping"
|
||||
echo "$NAME: ping $$"
|
||||
sleep 1
|
||||
done
|
||||
|
||||
16
dist/mswin32.rake
vendored
Normal file
16
dist/mswin32.rake
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
file pkg("foreman-#{version}-x86-mswin32.gem") => distribution_files do |t|
|
||||
Bundler.with_clean_env do
|
||||
sh "env PLATFORM=mswin32 gem build foreman.gemspec"
|
||||
end
|
||||
sh "mv foreman-#{version}-x86-mswin32.gem #{t.name}"
|
||||
end
|
||||
|
||||
task "mswin32:build" => pkg("foreman-#{version}-x86-mswin32.gem")
|
||||
|
||||
task "mswin32:clean" do
|
||||
clean pkg("foreman-#{version}-x86-mswin32.gem")
|
||||
end
|
||||
|
||||
task "mswin32:release" => "mswin32:build" do |t|
|
||||
sh "gem push #{pkg("foreman-#{version}-x86-mswin32.gem")} || echo 'error'"
|
||||
end
|
||||
@@ -12,6 +12,10 @@ module Foreman
|
||||
defined?(RUBY_PLATFORM) and RUBY_PLATFORM == "java"
|
||||
end
|
||||
|
||||
def self.ruby_18?
|
||||
defined?(RUBY_VERSION) and RUBY_VERSION =~ /^1\.8\.\d+/
|
||||
end
|
||||
|
||||
def self.windows?
|
||||
defined?(RUBY_PLATFORM) and RUBY_PLATFORM =~ /(win|w)32$/
|
||||
end
|
||||
|
||||
@@ -3,13 +3,17 @@ require "foreman/helpers"
|
||||
require "foreman/engine"
|
||||
require "foreman/engine/cli"
|
||||
require "foreman/export"
|
||||
require "foreman/version"
|
||||
require "shellwords"
|
||||
require "yaml"
|
||||
require "thor"
|
||||
|
||||
class Foreman::CLI < Thor
|
||||
|
||||
include Foreman::Helpers
|
||||
|
||||
map ["-v", "--version"] => :version
|
||||
|
||||
class_option :procfile, :type => :string, :aliases => "-f", :desc => "Default: Procfile"
|
||||
class_option :root, :type => :string, :aliases => "-d", :desc => "Default: Procfile directory"
|
||||
|
||||
@@ -80,6 +84,12 @@ class Foreman::CLI < Thor
|
||||
end
|
||||
end
|
||||
|
||||
desc "version", "Display Foreman gem version"
|
||||
|
||||
def version
|
||||
puts Foreman::VERSION
|
||||
end
|
||||
|
||||
no_tasks do
|
||||
def engine
|
||||
@engine ||= begin
|
||||
@@ -123,7 +133,7 @@ private ######################################################################
|
||||
def options
|
||||
original_options = super
|
||||
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))
|
||||
end
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class Foreman::Engine
|
||||
def initialize(options={})
|
||||
@options = options.dup
|
||||
|
||||
@options[:formation] ||= "all=1"
|
||||
@options[:formation] ||= (options[:concurrency] || "all=1")
|
||||
|
||||
@env = {}
|
||||
@mutex = Mutex.new
|
||||
@@ -39,7 +39,7 @@ class Foreman::Engine
|
||||
def start
|
||||
trap("TERM") { puts "SIGTERM 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
|
||||
spawn_processes
|
||||
@@ -99,10 +99,17 @@ class Foreman::Engine
|
||||
# @param [String] signal The signal to send to each process
|
||||
#
|
||||
def killall(signal="SIGTERM")
|
||||
@running.each do |pid, (process, index)|
|
||||
system "sending #{signal} to #{name_for(pid)} at pid #{pid}"
|
||||
if Foreman.windows?
|
||||
@running.each do |pid, (process, index)|
|
||||
system "sending #{signal} to #{name_for(pid)} at pid #{pid}"
|
||||
begin
|
||||
Process.kill(signal, pid)
|
||||
rescue Errno::ESRCH, Errno::EPERM
|
||||
end
|
||||
end
|
||||
else
|
||||
begin
|
||||
Process.kill(signal, -1 * pid)
|
||||
Process.kill "-#{signal}", Process.pid
|
||||
rescue Errno::ESRCH, Errno::EPERM
|
||||
end
|
||||
end
|
||||
@@ -154,11 +161,28 @@ class Foreman::Engine
|
||||
#
|
||||
# @param [Foreman::Process] process A +Process+ associated with this engine
|
||||
# @param [Fixnum] instance The instance of the process
|
||||
#
|
||||
#
|
||||
# @returns [Fixnum] port The port to use for this instance of this process
|
||||
#
|
||||
def port_for(process, instance)
|
||||
base_port + (@processes.index(process) * 100) + (instance - 1)
|
||||
def port_for(process, instance, base=nil)
|
||||
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
|
||||
|
||||
private
|
||||
@@ -179,10 +203,6 @@ private
|
||||
|
||||
## Helpers ##########################################################
|
||||
|
||||
def base_port
|
||||
(options[:port] || env["PORT"] || ENV["PORT"] || 5000).to_i
|
||||
end
|
||||
|
||||
def create_pipe
|
||||
IO.method(:pipe).arity.zero? ? IO.pipe : IO.pipe("BINARY")
|
||||
end
|
||||
@@ -193,7 +213,7 @@ private
|
||||
end
|
||||
|
||||
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|
|
||||
process, amount = pair.split("=")
|
||||
@@ -253,7 +273,7 @@ private
|
||||
loop do
|
||||
(IO.select(@readers.values).first || []).each do |reader|
|
||||
data = reader.gets
|
||||
output_with_mutex name_for(@readers.key(reader)), data
|
||||
output_with_mutex name_for(@readers.invert[reader]), data
|
||||
end
|
||||
end
|
||||
rescue Exception => ex
|
||||
@@ -275,8 +295,13 @@ private
|
||||
def terminate_gracefully
|
||||
return if @terminating
|
||||
@terminating = true
|
||||
system "sending SIGTERM to all processes"
|
||||
killall "SIGTERM"
|
||||
if Foreman.windows?
|
||||
system "sending SIGKILL to all processes"
|
||||
killall "SIGKILL"
|
||||
else
|
||||
system "sending SIGTERM to all processes"
|
||||
killall "SIGTERM"
|
||||
end
|
||||
Timeout.timeout(5) do
|
||||
watch_for_termination while @running.length > 0
|
||||
end
|
||||
|
||||
@@ -31,6 +31,7 @@ class Foreman::Engine::CLI < Foreman::Engine
|
||||
|
||||
def color?
|
||||
return true if @@color_force
|
||||
return false if Foreman.windows?
|
||||
return false unless self.respond_to?(:isatty)
|
||||
self.isatty && ENV["TERM"]
|
||||
end
|
||||
@@ -48,12 +49,12 @@ class Foreman::Engine::CLI < Foreman::Engine
|
||||
|
||||
def startup
|
||||
@colors = map_colors
|
||||
proctitle "foreman: master"
|
||||
proctitle "foreman: master" unless Foreman.windows?
|
||||
Color.enable($stdout, options[:color])
|
||||
end
|
||||
|
||||
def output(name, data)
|
||||
data.to_s.chomp.split("\n").each do |message|
|
||||
Color.enable($stdout, options[:color]) unless $stdout.respond_to?(:color?)
|
||||
output = ""
|
||||
output += $stdout.color(@colors[name.split(".").first].to_sym)
|
||||
output += "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(name)} | "
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
require "foreman"
|
||||
require "foreman/helpers"
|
||||
require "pathname"
|
||||
|
||||
module Foreman::Export
|
||||
extend Foreman::Helpers
|
||||
@@ -31,4 +32,3 @@ require "foreman/export/bluepill"
|
||||
require "foreman/export/runit"
|
||||
require "foreman/export/supervisord"
|
||||
require "foreman/export/launchd"
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
require "foreman/export"
|
||||
require "ostruct"
|
||||
require "pathname"
|
||||
require "shellwords"
|
||||
|
||||
class Foreman::Export::Base
|
||||
@@ -8,11 +10,37 @@ class Foreman::Export::Base
|
||||
attr_reader :options
|
||||
attr_reader :formation
|
||||
|
||||
# deprecated
|
||||
attr_reader :port
|
||||
|
||||
def initialize(location, engine, options={})
|
||||
@location = location
|
||||
@engine = engine
|
||||
@options = options.dup
|
||||
@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
|
||||
|
||||
def export
|
||||
@@ -36,6 +64,18 @@ class Foreman::Export::Base
|
||||
|
||||
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)
|
||||
raise Foreman::Export::Exception.new(message)
|
||||
end
|
||||
@@ -54,13 +94,28 @@ private ######################################################################
|
||||
'"' + Shellwords.escape(value) + '"'
|
||||
end
|
||||
|
||||
def export_template(name)
|
||||
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) })
|
||||
# deprecated
|
||||
def old_export_template(exporter, file, template_root)
|
||||
if template_root && File.exist?(file_path = File.join(template_root, file))
|
||||
File.read(file_path)
|
||||
elsif File.exist?(file_path = File.expand_path(File.join("~/.foreman/templates", file)))
|
||||
File.read(file_path)
|
||||
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
|
||||
|
||||
def write_template(name, target, binding)
|
||||
@@ -81,7 +136,9 @@ private ######################################################################
|
||||
def write_file(filename, contents)
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,16 +36,29 @@ class Foreman::Process
|
||||
|
||||
if Foreman.windows?
|
||||
Dir.chdir(cwd) do
|
||||
Process.spawn env, command, :out => output, :err => output, :new_pgroup => true
|
||||
expanded_command = command.dup
|
||||
env.each do |key, val|
|
||||
expanded_command.gsub!("$#{key}", val)
|
||||
end
|
||||
Process.spawn env, expanded_command, :out => output, :err => output
|
||||
end
|
||||
elsif Foreman.jruby?
|
||||
Dir.chdir(cwd) do
|
||||
require "posix/spawn"
|
||||
POSIX::Spawn.spawn env, command, :out => output, :err => output, :pgroup => 0
|
||||
POSIX::Spawn.spawn env, command, :out => output, :err => output
|
||||
end
|
||||
elsif Foreman.ruby_18?
|
||||
Dir.chdir(cwd) do
|
||||
fork do
|
||||
$stdout.reopen output
|
||||
$stderr.reopen output
|
||||
env.each { |k,v| ENV[k] = v }
|
||||
exec command
|
||||
end
|
||||
end
|
||||
else
|
||||
Dir.chdir(cwd) do
|
||||
Process.spawn env, command, :out => output, :err => output, :pgroup => 0
|
||||
Process.spawn env, command, :out => output, :err => output
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -55,7 +68,11 @@ class Foreman::Process
|
||||
# @param [String] signal The signal to send
|
||||
#
|
||||
def kill(signal)
|
||||
pid && Process.kill(signal, -1 * pid)
|
||||
if Foreman.windows?
|
||||
pid && Process.kill(signal, pid)
|
||||
else
|
||||
pid && Process.kill("-#{signal}", pid)
|
||||
end
|
||||
rescue Errno::ESRCH
|
||||
false
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module Foreman
|
||||
|
||||
VERSION = "0.48.0.pre2"
|
||||
VERSION = "0.51.0"
|
||||
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
.\" generated with Ronn/v0.7.3
|
||||
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
||||
.
|
||||
.TH "FOREMAN" "1" "April 2012" "Foreman 0.46.0" "Foreman Manual"
|
||||
.TH "FOREMAN" "1" "July 2012" "Foreman 0.50.0" "Foreman Manual"
|
||||
.
|
||||
.SH "NAME"
|
||||
\fBforeman\fR \- manage Procfile\-based applications
|
||||
|
||||
@@ -74,4 +74,14 @@ describe "Foreman::CLI", :fakefs do
|
||||
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
|
||||
|
||||
@@ -54,7 +54,6 @@ def fork_and_capture(&blk)
|
||||
Process.wait pid
|
||||
buffer = ""
|
||||
until rd.eof?
|
||||
p [:foo]
|
||||
buffer += rd.gets
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,7 +32,7 @@ def latest_release
|
||||
end
|
||||
|
||||
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} | grep -v pre }.split("\n").sort_by do |tag|
|
||||
Gem::Version.new(tag[1..-1])
|
||||
end
|
||||
tags[1]
|
||||
@@ -60,7 +60,6 @@ end
|
||||
|
||||
desc "Cut a release"
|
||||
task :release do
|
||||
Rake::Task["authors"].invoke
|
||||
Rake::Task["changelog"].invoke
|
||||
Rake::Task["pages"].invoke
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user