Compare commits
44 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26bb0ed54e | ||
|
|
44002953f6 | ||
|
|
bb2c3a2d04 | ||
|
|
88cdaacc67 | ||
|
|
faf7b3c40f | ||
|
|
21dd610eaf | ||
|
|
fe65c7510d | ||
|
|
cd2c255296 | ||
|
|
92c1909217 | ||
|
|
af57bf3d52 | ||
|
|
443994d3b5 | ||
|
|
2faa3fb6ff | ||
|
|
0d53f6bd6c | ||
|
|
1d2bcdbc56 | ||
|
|
aceea1472a | ||
|
|
44726e377e | ||
|
|
61eca5a1d8 | ||
|
|
553ac7f81f | ||
|
|
6790cf02a9 | ||
|
|
7ad41da592 | ||
|
|
8ee7b7afdf | ||
|
|
2620b90808 | ||
|
|
89bdc3ab8e | ||
|
|
60a11eb981 | ||
|
|
61c222deb8 | ||
|
|
8fe86e98c8 | ||
|
|
5c1ffdb7dc | ||
|
|
8b49256175 | ||
|
|
37d777f224 | ||
|
|
73fc059634 | ||
|
|
f7b7029cc0 | ||
|
|
3a101ec7dd | ||
|
|
6c931ea15e | ||
|
|
d173570d98 | ||
|
|
0cd41fee7f | ||
|
|
9da4e38209 | ||
|
|
5d9dfd294e | ||
|
|
8998e9a47c | ||
|
|
8238a86942 | ||
|
|
1153fb0f0c | ||
|
|
f69c755d9a | ||
|
|
8fbee31a2d | ||
|
|
7b4eabf0c5 | ||
|
|
e99f3173ef |
@@ -19,4 +19,3 @@ rvm:
|
||||
- 1.9.2
|
||||
- 1.9.3
|
||||
- jruby
|
||||
- ree
|
||||
|
||||
30
Changelog.md
30
Changelog.md
@@ -1,3 +1,33 @@
|
||||
## 0.60.2 (2012-10-08)
|
||||
|
||||
* Fix for nil value on io select loop, fixes #260 [Silvio Relli]
|
||||
|
||||
## 0.60.1 (2012-10-08)
|
||||
|
||||
* sleep on select() to avoid spinning the cpu [Silvio Relli]
|
||||
|
||||
## 0.60.0 (2012-09-25)
|
||||
|
||||
* foreman run can run things from the Procfile like heroku run. [Dan Peterson]
|
||||
|
||||
## 0.59.0 (2012-09-15)
|
||||
|
||||
* Use /bin/sh instead of bash for foreman-runner [Jeremy Evans]
|
||||
|
||||
## 0.58.0 (2012-09-14)
|
||||
|
||||
* dont set HOME [David Dollar]
|
||||
* Add StandardOutPath to launchd export [Aaron Kalin]
|
||||
* Add command argument string splitting [Aaron Kalin]
|
||||
* Cleanup launchd exporter [Aaron Kalin]
|
||||
* Enable trim_mode via '-' in ERB templates [Aaron Kalin]
|
||||
* Add support for setting environment variables [Aaron Kalin]
|
||||
* foreman run should exit with the same code as its command [Omar Khan]
|
||||
* Handle multiline strings in .env file [Szymon Nowak]
|
||||
* Use path and env variables in the inittab export [Indrek Juhkam]
|
||||
* fixed the directory option [Arnaud Lachaume]
|
||||
* Add capistrano export support [Daniel Farrell]
|
||||
|
||||
## 0.57.0 (2012-08-21)
|
||||
|
||||
* fix startup checks for upstart exporter [Aditya Sanghi]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
foreman (0.59.0)
|
||||
foreman (0.61.0)
|
||||
thor (>= 0.13.6)
|
||||
|
||||
GEM
|
||||
|
||||
@@ -3,6 +3,7 @@ require "foreman/version"
|
||||
|
||||
Gem::Specification.new do |gem|
|
||||
gem.name = "foreman"
|
||||
gem.license = "MIT"
|
||||
gem.version = Foreman::VERSION
|
||||
|
||||
gem.author = "David Dollar"
|
||||
|
||||
@@ -8,8 +8,8 @@ module Foreman
|
||||
File.expand_path("../../bin/foreman-runner", __FILE__)
|
||||
end
|
||||
|
||||
def self.jruby?
|
||||
defined?(RUBY_PLATFORM) and RUBY_PLATFORM == "java"
|
||||
def self.jruby_18?
|
||||
defined?(RUBY_PLATFORM) and RUBY_PLATFORM == "java" and ruby_18?
|
||||
end
|
||||
|
||||
def self.ruby_18?
|
||||
|
||||
@@ -12,7 +12,7 @@ if defined?(Capistrano)
|
||||
set :foreman_procfile, "Procfile"
|
||||
set :foreman_app, application
|
||||
set :foreman_user, user
|
||||
set :foreman_log, "#{shared_path}/log"
|
||||
set :foreman_log, 'shared_path/log'
|
||||
set :foreman_concurrency, false
|
||||
DESC
|
||||
task :export, :roles => :app do
|
||||
|
||||
@@ -23,6 +23,7 @@ class Foreman::CLI < Thor
|
||||
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 :port, :type => :numeric, :aliases => "-p"
|
||||
method_option :timeout, :type => :numeric, :aliases => "-t", :desc => "Specify the amount of time (in seconds) processes have to shudown gracefully before receiving a SIGKILL, defaults to 5."
|
||||
|
||||
class << self
|
||||
# Hackery. Take the run method away from Thor so that we can redefine it.
|
||||
@@ -75,10 +76,19 @@ class Foreman::CLI < Thor
|
||||
|
||||
def run(*args)
|
||||
load_environment!
|
||||
|
||||
if File.exist?(procfile)
|
||||
engine.load_procfile(procfile)
|
||||
end
|
||||
|
||||
pid = fork do
|
||||
begin
|
||||
engine.env.each { |k,v| ENV[k] = v }
|
||||
exec args.shelljoin
|
||||
if args.size == 1 && process = engine.process(args.first)
|
||||
process.exec(:env => engine.env)
|
||||
else
|
||||
exec args.shelljoin
|
||||
end
|
||||
rescue Errno::EACCES
|
||||
error "not executable: #{args.first}"
|
||||
rescue Errno::ENOENT
|
||||
|
||||
@@ -25,6 +25,7 @@ class Foreman::Engine
|
||||
@options = options.dup
|
||||
|
||||
@options[:formation] ||= (options[:concurrency] || "all=1")
|
||||
@options[:timeout] ||= 5
|
||||
|
||||
@env = {}
|
||||
@mutex = Mutex.new
|
||||
@@ -37,6 +38,9 @@ class Foreman::Engine
|
||||
# Start the processes registered to this +Engine+
|
||||
#
|
||||
def start
|
||||
# Make sure foreman is the process group leader.
|
||||
Process.setpgrp unless Foreman.windows?
|
||||
|
||||
trap("TERM") { puts "SIGTERM received"; terminate_gracefully }
|
||||
trap("INT") { puts "SIGINT received"; terminate_gracefully }
|
||||
trap("HUP") { puts "SIGHUP received"; terminate_gracefully } if ::Signal.list.keys.include? 'HUP'
|
||||
@@ -109,7 +113,7 @@ class Foreman::Engine
|
||||
end
|
||||
else
|
||||
begin
|
||||
Process.kill "-#{signal}", Process.pid
|
||||
Process.kill "-#{signal}", Process.getpgrp
|
||||
rescue Errno::ESRCH, Errno::EPERM
|
||||
end
|
||||
end
|
||||
@@ -273,9 +277,14 @@ private
|
||||
Thread.new do
|
||||
begin
|
||||
loop do
|
||||
(IO.select(@readers.values).first || []).each do |reader|
|
||||
data = reader.gets
|
||||
output_with_mutex name_for(@readers.invert[reader]), data
|
||||
io = IO.select(@readers.values, nil, nil, 30)
|
||||
(io.nil? ? [] : io.first).each do |reader|
|
||||
if reader.eof?
|
||||
@readers.delete_if { |key, value| value == reader }
|
||||
else
|
||||
data = reader.gets
|
||||
output_with_mutex name_for(@readers.invert[reader]), data
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue Exception => ex
|
||||
@@ -304,7 +313,7 @@ private
|
||||
system "sending SIGTERM to all processes"
|
||||
killall "SIGTERM"
|
||||
end
|
||||
Timeout.timeout(5) do
|
||||
Timeout.timeout(options[:timeout]) do
|
||||
watch_for_termination while @running.length > 0
|
||||
end
|
||||
rescue Timeout::Error
|
||||
|
||||
@@ -44,8 +44,8 @@ class Foreman::Engine::CLI < Foreman::Engine
|
||||
|
||||
end
|
||||
|
||||
FOREMAN_COLORS = %w( cyan yellow green magenta red blue intense_cyan intense_yellow
|
||||
intense_green intense_magenta intense_red, intense_blue )
|
||||
FOREMAN_COLORS = %w( cyan yellow green magenta red blue bright_cyan bright_yellow
|
||||
bright_green bright_magenta bright_red bright_blue )
|
||||
|
||||
def startup
|
||||
@colors = map_colors
|
||||
@@ -54,7 +54,7 @@ class Foreman::Engine::CLI < Foreman::Engine
|
||||
end
|
||||
|
||||
def output(name, data)
|
||||
data.to_s.chomp.split("\n").each do |message|
|
||||
data.to_s.lines.map(&:chomp).each do |message|
|
||||
output = ""
|
||||
output += $stdout.color(@colors[name.split(".").first].to_sym)
|
||||
output += "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(name)} | "
|
||||
@@ -89,7 +89,7 @@ private
|
||||
@names.values.each_with_index do |name, index|
|
||||
colors[name] = FOREMAN_COLORS[index % FOREMAN_COLORS.length]
|
||||
end
|
||||
colors["system"] = "intense_white"
|
||||
colors["system"] = "bright_white"
|
||||
colors
|
||||
end
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ class Foreman::Env
|
||||
attr_reader :entries
|
||||
|
||||
def initialize(filename)
|
||||
@entries = File.read(filename).split("\n").inject({}) do |ax, line|
|
||||
@entries = File.read(filename).gsub("\r\n","\n").split("\n").inject({}) do |ax, line|
|
||||
if line =~ /\A([A-Za-z_0-9]+)=(.*)\z/
|
||||
key = $1
|
||||
case val = $2
|
||||
|
||||
@@ -91,7 +91,7 @@ private ######################################################################
|
||||
end
|
||||
|
||||
def shell_quote(value)
|
||||
'"' + Shellwords.escape(value) + '"'
|
||||
Shellwords.escape(value)
|
||||
end
|
||||
|
||||
# deprecated
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
require "foreman"
|
||||
require "rubygems"
|
||||
|
||||
class Foreman::Process
|
||||
|
||||
@@ -21,6 +20,21 @@ class Foreman::Process
|
||||
@options[:env] ||= {}
|
||||
end
|
||||
|
||||
# Get environment-expanded command for a +Process+
|
||||
#
|
||||
# @param [Hash] custom_env ({}) Environment variables to merge with defaults
|
||||
#
|
||||
# @return [String] The expanded command
|
||||
#
|
||||
def expanded_command(custom_env={})
|
||||
env = @options[:env].merge(custom_env)
|
||||
expanded_command = command.dup
|
||||
env.each do |key, val|
|
||||
expanded_command.gsub!("$#{key}", val)
|
||||
end
|
||||
expanded_command
|
||||
end
|
||||
|
||||
# Run a +Process+
|
||||
#
|
||||
# @param [Hash] options
|
||||
@@ -31,18 +45,14 @@ class Foreman::Process
|
||||
# @returns [Fixnum] pid The +pid+ of the process
|
||||
#
|
||||
def run(options={})
|
||||
env = options[:env] ? @options[:env].merge(options[:env]) : @options[:env]
|
||||
env = @options[:env].merge(options[:env] || {})
|
||||
output = options[:output] || $stdout
|
||||
|
||||
if Foreman.windows?
|
||||
Dir.chdir(cwd) do
|
||||
expanded_command = command.dup
|
||||
env.each do |key, val|
|
||||
expanded_command.gsub!("$#{key}", val)
|
||||
end
|
||||
Process.spawn env, expanded_command, :out => output, :err => output
|
||||
Process.spawn env, expanded_command(env), :out => output, :err => output
|
||||
end
|
||||
elsif Foreman.jruby?
|
||||
elsif Foreman.jruby_18?
|
||||
require "posix/spawn"
|
||||
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
||||
POSIX::Spawn.spawn env, wrapped_command, :out => output, :err => output
|
||||
@@ -52,7 +62,7 @@ class Foreman::Process
|
||||
$stderr.reopen output
|
||||
env.each { |k,v| ENV[k] = v }
|
||||
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
||||
exec wrapped_command
|
||||
Kernel.exec wrapped_command
|
||||
end
|
||||
else
|
||||
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
||||
@@ -60,6 +70,20 @@ class Foreman::Process
|
||||
end
|
||||
end
|
||||
|
||||
# Exec a +Process+
|
||||
#
|
||||
# @param [Hash] options
|
||||
#
|
||||
# @option options :env ({}) Environment variables to set for this execution
|
||||
#
|
||||
# @return Does not return
|
||||
def exec(options={})
|
||||
env = @options[:env].merge(options[:env] || {})
|
||||
env.each { |k, v| ENV[k] = v }
|
||||
Dir.chdir(cwd)
|
||||
Kernel.exec expanded_command(env)
|
||||
end
|
||||
|
||||
# Send a signal to this +Process+
|
||||
#
|
||||
# @param [String] signal The signal to send
|
||||
|
||||
@@ -82,7 +82,7 @@ class Foreman::Procfile
|
||||
private
|
||||
|
||||
def parse(filename)
|
||||
File.read(filename).split("\n").map do |line|
|
||||
File.read(filename).gsub("\r\n","\n").split("\n").map do |line|
|
||||
if line =~ /^([A-Za-z0-9_]+):\s*(.+)$/
|
||||
[$1, $2]
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module Foreman
|
||||
|
||||
VERSION = "0.59.0"
|
||||
VERSION = "0.61.0"
|
||||
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
.\" generated with Ronn/v0.7.3
|
||||
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
||||
.
|
||||
.TH "FOREMAN" "1" "July 2012" "Foreman 0.57.0" "Foreman Manual"
|
||||
.TH "FOREMAN" "1" "October 2012" "" ""
|
||||
.
|
||||
.SH "NAME"
|
||||
\fBforeman\fR \- manage Procfile\-based applications
|
||||
@@ -90,7 +90,7 @@ Specify the user the application should be run as\. Defaults to the app name
|
||||
These options control all modes of foreman\'s operation\.
|
||||
.
|
||||
.TP
|
||||
\fB\-d\fR, \fB\-\-directory\fR
|
||||
\fB\-d\fR, \fB\-\-root\fR
|
||||
Specify an alternate application root\. This defaults to the directory containing the Procfile\.
|
||||
.
|
||||
.TP
|
||||
|
||||
@@ -84,7 +84,7 @@ The following options control how the application is run:
|
||||
|
||||
These options control all modes of foreman's operation.
|
||||
|
||||
* `-d`, `--directory`:
|
||||
* `-d`, `--root`:
|
||||
Specify an alternate application root. This defaults to the directory
|
||||
containing the Procfile.
|
||||
|
||||
|
||||
@@ -73,6 +73,10 @@ describe "Foreman::CLI", :fakefs do
|
||||
forked_foreman("run #{resource_path("bin/env FOO")} -e #{resource_path(".env")}").should == "bar\n"
|
||||
end
|
||||
|
||||
it "can run a command from the Procfile" do
|
||||
forked_foreman("run -f #{resource_path("Procfile")} test").should == "testing\n"
|
||||
end
|
||||
|
||||
it "exits with the same exit code as the command" do
|
||||
fork_and_get_exitstatus("run echo 1").should == 0
|
||||
fork_and_get_exitstatus("run date 'invalid_date'").should == 1
|
||||
|
||||
@@ -38,7 +38,7 @@ describe Foreman::Export::Upstart, :fakefs do
|
||||
engine.env['KEY'] = 'd"\|d'
|
||||
upstart.export
|
||||
"foobarfoo".should include "bar"
|
||||
File.read("/tmp/init/app-alpha-1.conf").should =~ /KEY="d\\"\\\\\\\|d/
|
||||
File.read("/tmp/init/app-alpha-1.conf").should =~ /KEY=d\\"\\\\\\\|d/
|
||||
end
|
||||
|
||||
context "with a formation" do
|
||||
|
||||
@@ -8,7 +8,7 @@ stdout_logfile=/var/log/app/alpha-1.log
|
||||
stderr_logfile=/var/log/app/alpha-1.error.log
|
||||
user=app
|
||||
directory=/tmp/app
|
||||
environment=PORT="5000"
|
||||
environment=PORT=5000
|
||||
[program:app-bravo-1]
|
||||
command=./bravo
|
||||
autostart=true
|
||||
@@ -18,7 +18,7 @@ stdout_logfile=/var/log/app/bravo-1.log
|
||||
stderr_logfile=/var/log/app/bravo-1.error.log
|
||||
user=app
|
||||
directory=/tmp/app
|
||||
environment=PORT="5100"
|
||||
environment=PORT=5100
|
||||
|
||||
[group:app]
|
||||
programs=app-alpha-1,app-bravo-1
|
||||
|
||||
@@ -8,7 +8,7 @@ stdout_logfile=/var/log/app/alpha-1.log
|
||||
stderr_logfile=/var/log/app/alpha-1.error.log
|
||||
user=app
|
||||
directory=/tmp/app
|
||||
environment=PORT="5000"
|
||||
environment=PORT=5000
|
||||
[program:app-alpha-2]
|
||||
command=./alpha
|
||||
autostart=true
|
||||
@@ -18,7 +18,7 @@ stdout_logfile=/var/log/app/alpha-2.log
|
||||
stderr_logfile=/var/log/app/alpha-2.error.log
|
||||
user=app
|
||||
directory=/tmp/app
|
||||
environment=PORT="5001"
|
||||
environment=PORT=5001
|
||||
|
||||
[group:app]
|
||||
programs=app-alpha-1,app-alpha-2
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
require "rubygems"
|
||||
|
||||
require "simplecov"
|
||||
SimpleCov.start do
|
||||
add_filter "/spec/"
|
||||
|
||||
Reference in New Issue
Block a user