Compare commits
101 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 | ||
|
|
64f0749d16 | ||
|
|
6b77ca1e46 | ||
|
|
8fbee31a2d | ||
|
|
7b4eabf0c5 | ||
|
|
6a44dd3fd3 | ||
|
|
e99f3173ef | ||
|
|
6c04dab649 | ||
|
|
96e26e7412 | ||
|
|
a2c03cc402 | ||
|
|
803115c0c4 | ||
|
|
a4343187ad | ||
|
|
98af1f0943 | ||
|
|
af2d4762a8 | ||
|
|
1d06124457 | ||
|
|
698e6ae092 | ||
|
|
c617ddb3b2 | ||
|
|
f6d4badcd2 | ||
|
|
f29bf49a35 | ||
|
|
e06d36b27c | ||
|
|
85e62dfbeb | ||
|
|
574e852710 | ||
|
|
68f098c1d2 | ||
|
|
e8bdafdfc1 | ||
|
|
4abd3ebedb | ||
|
|
f765436dde | ||
|
|
b5c513b4b5 | ||
|
|
ee761ff098 | ||
|
|
27c22deb6c | ||
|
|
681a9f7e61 | ||
|
|
8335a2b1ba | ||
|
|
407425ca78 | ||
|
|
6ca505b4cd | ||
|
|
612eae5e21 | ||
|
|
497b5ea1eb | ||
|
|
cd384e0d59 | ||
|
|
8921cac35b | ||
|
|
7d6de5b2a7 | ||
|
|
cc4306492e | ||
|
|
6042783e82 | ||
|
|
b7b3a9f898 | ||
|
|
8b204db2f0 | ||
|
|
15643dcb3f | ||
|
|
5f0f2f5378 | ||
|
|
c1b57b59cf | ||
|
|
21d53818f2 | ||
|
|
359d6f1c34 | ||
|
|
584f251e4a | ||
|
|
7d9c2b2ac4 | ||
|
|
fba4d9beff | ||
|
|
0bde5fdab5 | ||
|
|
ebe160d425 | ||
|
|
1beab80c1f | ||
|
|
7b270f9f4a | ||
|
|
03e5342067 | ||
|
|
b1d57426fb | ||
|
|
06e5c52f35 | ||
|
|
64ca839c0b | ||
|
|
80aebda023 | ||
|
|
5dee2281a2 | ||
|
|
0a61b1a62f |
@@ -16,9 +16,6 @@ notifications:
|
||||
- http://dx-helper.herokuapp.com/travis
|
||||
|
||||
rvm:
|
||||
- 1.8.7
|
||||
- 1.9.2
|
||||
- 1.9.3
|
||||
- jruby
|
||||
- rbx
|
||||
- ree
|
||||
|
||||
96
Changelog.md
96
Changelog.md
@@ -1,17 +1,97 @@
|
||||
## 0.48.0.pre2 (2012-06-17)
|
||||
## 0.60.2 (2012-10-08)
|
||||
|
||||
* 0.48.0.pre2 [David Dollar]
|
||||
* 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]
|
||||
|
||||
## 0.56.0 (2012-08-19)
|
||||
|
||||
* read .profile, not .profile.d [David Dollar]
|
||||
|
||||
## 0.55.0 (2012-08-14)
|
||||
|
||||
* use a forked process to exec a run with environment [David Dollar]
|
||||
|
||||
## 0.54.0 (2012-08-14)
|
||||
|
||||
* use Foreman::Process to extract command running [David Dollar]
|
||||
* changed to check env for bash [brntbeer]
|
||||
|
||||
## 0.53.0 (2012-07-24)
|
||||
|
||||
* put app root in $HOME [David Dollar]
|
||||
|
||||
## 0.52.0 (2012-07-24)
|
||||
|
||||
* wrap command in a runner that sources .profile.d scripts [David Dollar]
|
||||
* fix upstart export specs [David Dollar]
|
||||
* Make upstart export start/stop with network [Daniel Farrell]
|
||||
|
||||
## 0.51.0 (2012-07-11)
|
||||
|
||||
* dont try to colorize windows [David Dollar]
|
||||
|
||||
## 0.50.0 (2012-07-11)
|
||||
|
||||
* 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 (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.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.50.0)
|
||||
foreman (0.61.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.4)
|
||||
thor (0.16.0)
|
||||
timecop (0.3.5)
|
||||
win32console (1.3.0-x86-mingw32)
|
||||
xml-simple (1.0.15)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
#/ Usage: foreman-runner [-d <dir>] <command> [<args>...]
|
||||
#/ Usage: foreman-runner [-d <dir>] [-p] <command> [<args>...]
|
||||
#/
|
||||
#/ Run a command with exec, optionally changing directory first
|
||||
|
||||
@@ -16,9 +16,12 @@ usage() {
|
||||
exit
|
||||
}
|
||||
|
||||
while getopts ":hd:" OPT; do
|
||||
read_profile=""
|
||||
|
||||
while getopts ":hd:p" OPT; do
|
||||
case $OPT in
|
||||
d) cd "$OPTARG" ;;
|
||||
p) read_profile="1" ;;
|
||||
h) usage ;;
|
||||
\?) error "invalid option: -$OPTARG" ;;
|
||||
:) error "option -$OPTARG requires an argument" ;;
|
||||
@@ -29,4 +32,10 @@ shift $((OPTIND-1))
|
||||
|
||||
[ -z "$1" ] && usage
|
||||
|
||||
if [ "$read_profile" = "1" ]; then
|
||||
if [ -f .profile ]; then
|
||||
. .profile
|
||||
fi
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
|
||||
2
data/example/.profile.d/foo.sh
Normal file
2
data/example/.profile.d/foo.sh
Normal file
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
export FOO=bar
|
||||
@@ -4,14 +4,25 @@
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string><%= "#{app}-#{name}-#{num}" %></string>
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<%- engine.env.merge("PORT" => port).each_pair do |var,env| -%>
|
||||
<key><%= var.upcase %></key>
|
||||
<string><%= env %></string>
|
||||
<%- end -%>
|
||||
</dict>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string><%= process.command %></string>
|
||||
<%- command_args.each do |command| -%>
|
||||
<string><%= command %></string>
|
||||
<%- end -%>
|
||||
</array>
|
||||
<key>KeepAlive</key>
|
||||
<true/>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>StandardOutPath</key>
|
||||
<string><%= log %>/<%= app %>-<%= name %>-<%=num%>.log</string>
|
||||
<key>StandardErrorPath</key>
|
||||
<string><%= log %>/<%= app %>-<%= name %>-<%=num%>.log</string>
|
||||
<key>UserName</key>
|
||||
|
||||
@@ -6,3 +6,11 @@ bash << "EOF"
|
||||
EOF
|
||||
|
||||
end script
|
||||
|
||||
start on (started network-interface
|
||||
or started network-manager
|
||||
or started networking)
|
||||
|
||||
stop on (stopping network-interface
|
||||
or stopping network-manager
|
||||
or stopping networking)
|
||||
|
||||
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
|
||||
@@ -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?
|
||||
|
||||
54
lib/foreman/capistrano.rb
Normal file
54
lib/foreman/capistrano.rb
Normal file
@@ -0,0 +1,54 @@
|
||||
if defined?(Capistrano)
|
||||
Capistrano::Configuration.instance(:must_exist).load do
|
||||
|
||||
namespace :foreman do
|
||||
desc <<-DESC
|
||||
Export the Procfile to upstart. Will use sudo if available.
|
||||
|
||||
You can override any of these defaults by setting the variables shown below.
|
||||
|
||||
set :foreman_format, "upstart"
|
||||
set :foreman_location, "/etc/init"
|
||||
set :foreman_procfile, "Procfile"
|
||||
set :foreman_app, application
|
||||
set :foreman_user, user
|
||||
set :foreman_log, 'shared_path/log'
|
||||
set :foreman_concurrency, false
|
||||
DESC
|
||||
task :export, :roles => :app do
|
||||
bundle_cmd = fetch(:bundle_cmd, "bundle")
|
||||
foreman_format = fetch(:foreman_format, "upstart")
|
||||
foreman_location = fetch(:foreman_location, "/etc/init")
|
||||
foreman_procfile = fetch(:foreman_procfile, "Procfile")
|
||||
foreman_app = fetch(:foreman_app, application)
|
||||
foreman_user = fetch(:foreman_user, user)
|
||||
foreman_log = fetch(:foreman_log, "#{shared_path}/log")
|
||||
foreman_concurrency = fetch(:foreman_concurrency, false)
|
||||
|
||||
args = ["#{foreman_format} #{foreman_location}"]
|
||||
args << "-f #{foreman_procfile}"
|
||||
args << "-a #{foreman_app}"
|
||||
args << "-u #{foreman_user}"
|
||||
args << "-l #{foreman_log}"
|
||||
args << "-c #{foreman_concurrency}" if foreman_concurrency
|
||||
run "cd #{release_path} && #{sudo} #{bundle_cmd} exec foreman export #{args.join(' ')}"
|
||||
end
|
||||
|
||||
desc "Start the application services"
|
||||
task :start, :roles => :app do
|
||||
run "#{sudo} start #{application}"
|
||||
end
|
||||
|
||||
desc "Stop the application services"
|
||||
task :stop, :roles => :app do
|
||||
run "#{sudo} stop #{application}"
|
||||
end
|
||||
|
||||
desc "Restart the application services"
|
||||
task :restart, :roles => :app do
|
||||
run "#{sudo} start #{application} || #{sudo} restart #{application}"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -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,13 +76,27 @@ class Foreman::CLI < Thor
|
||||
|
||||
def run(*args)
|
||||
load_environment!
|
||||
begin
|
||||
exec engine.env, args.shelljoin
|
||||
rescue Errno::EACCES
|
||||
error "not executable: #{args.first}"
|
||||
rescue Errno::ENOENT
|
||||
error "command not found: #{args.first}"
|
||||
|
||||
if File.exist?(procfile)
|
||||
engine.load_procfile(procfile)
|
||||
end
|
||||
|
||||
pid = fork do
|
||||
begin
|
||||
engine.env.each { |k,v| ENV[k] = v }
|
||||
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
|
||||
error "command not found: #{args.first}"
|
||||
end
|
||||
end
|
||||
Process.wait(pid)
|
||||
exit $?.exitstatus
|
||||
end
|
||||
|
||||
desc "version", "Display Foreman gem version"
|
||||
@@ -125,7 +140,7 @@ private ######################################################################
|
||||
def procfile
|
||||
case
|
||||
when options[:procfile] then options[:procfile]
|
||||
when options[:root] then File.expand_path(File.join(options[:app_root], "Procfile"))
|
||||
when options[:root] then File.expand_path(File.join(options[:root], "Procfile"))
|
||||
else "Procfile"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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
|
||||
@@ -256,7 +260,9 @@ private
|
||||
1.upto(formation[@names[process]]) do |n|
|
||||
reader, writer = create_pipe
|
||||
begin
|
||||
pid = process.run(:output => writer, :env => { "PORT" => port_for(process, n).to_s })
|
||||
pid = process.run(:output => writer, :env => {
|
||||
"PORT" => port_for(process, n).to_s
|
||||
})
|
||||
writer.puts "started with pid #{pid}"
|
||||
rescue Errno::ENOENT
|
||||
writer.puts "unknown command: #{process.command}"
|
||||
@@ -271,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
|
||||
@@ -302,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
|
||||
|
||||
@@ -31,7 +31,7 @@ class Foreman::Engine::CLI < Foreman::Engine
|
||||
|
||||
def color?
|
||||
return true if @@color_force
|
||||
return true if Foreman.windows?
|
||||
return false if Foreman.windows?
|
||||
return false unless self.respond_to?(:isatty)
|
||||
self.isatty && ENV["TERM"]
|
||||
end
|
||||
@@ -44,18 +44,17 @@ 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
|
||||
proctitle "foreman: master"
|
||||
require "win32console" if Foreman.windows?
|
||||
Color.enable($stdout, options[:color]) unless $stdout.respond_to?(:color?)
|
||||
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|
|
||||
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)} | "
|
||||
@@ -90,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,12 +5,14 @@ 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
|
||||
# Remove single quotes
|
||||
when /\A'(.*)'\z/ then ax[key] = $1
|
||||
when /\A"(.*)"\z/ then ax[key] = $1.gsub(/\\(.)/, '\1')
|
||||
# Remove double quotes and unescape string preserving newline characters
|
||||
when /\A"(.*)"\z/ then ax[key] = $1.gsub('\n', "\n").gsub(/\\(.)/, '\1')
|
||||
else ax[key] = val
|
||||
end
|
||||
end
|
||||
|
||||
@@ -91,7 +91,7 @@ private ######################################################################
|
||||
end
|
||||
|
||||
def shell_quote(value)
|
||||
'"' + Shellwords.escape(value) + '"'
|
||||
Shellwords.escape(value)
|
||||
end
|
||||
|
||||
# deprecated
|
||||
@@ -119,7 +119,7 @@ private ######################################################################
|
||||
end
|
||||
|
||||
def write_template(name, target, binding)
|
||||
compiled = ERB.new(export_template(name)).result(binding)
|
||||
compiled = ERB.new(export_template(name), nil, '-').result(binding)
|
||||
write_file target, compiled
|
||||
end
|
||||
|
||||
|
||||
@@ -13,7 +13,16 @@ class Foreman::Export::Inittab < Foreman::Export::Base
|
||||
1.upto(engine.formation[name]) do |num|
|
||||
id = app.slice(0, 2).upcase + sprintf("%02d", index)
|
||||
port = engine.port_for(process, num)
|
||||
inittab << "#{id}:4:respawn:/bin/su - #{user} -c 'PORT=#{port} #{process.command} >> #{log}/#{name}-#{num}.log 2>&1'"
|
||||
|
||||
commands = []
|
||||
commands << "cd #{engine.root}"
|
||||
commands << "export PORT=#{port}"
|
||||
engine.env.each_pair do |var, env|
|
||||
commands << "export #{var.upcase}=#{shell_quote(env)}"
|
||||
end
|
||||
commands << "#{process.command} >> #{log}/#{name}-#{num}.log 2>&1"
|
||||
|
||||
inittab << "#{id}:4:respawn:/bin/su - #{user} -c '#{commands.join(";")}'"
|
||||
index += 1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,6 +7,8 @@ class Foreman::Export::Launchd < Foreman::Export::Base
|
||||
super
|
||||
engine.each_process do |name, process|
|
||||
1.upto(engine.formation[name]) do |num|
|
||||
port = engine.port_for(process, num)
|
||||
command_args = process.command.split(" ")
|
||||
write_template "launchd/launchd.plist.erb", "#{app}-#{name}-#{num}.plist", binding
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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,38 +45,45 @@ 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
|
||||
end
|
||||
elsif Foreman.jruby?
|
||||
Dir.chdir(cwd) do
|
||||
require "posix/spawn"
|
||||
POSIX::Spawn.spawn env, command, :out => output, :err => output
|
||||
Process.spawn env, expanded_command(env), :out => output, :err => output
|
||||
end
|
||||
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
|
||||
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
|
||||
fork do
|
||||
$stdout.reopen output
|
||||
$stderr.reopen output
|
||||
env.each { |k,v| ENV[k] = v }
|
||||
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
||||
Kernel.exec wrapped_command
|
||||
end
|
||||
else
|
||||
Dir.chdir(cwd) do
|
||||
Process.spawn env, command, :out => output, :err => output
|
||||
end
|
||||
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
||||
Process.spawn env, wrapped_command, :out => output, :err => output
|
||||
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
|
||||
@@ -93,10 +114,12 @@ class Foreman::Process
|
||||
!alive?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Returns the working directory for this +Process+
|
||||
#
|
||||
# @returns [String]
|
||||
#
|
||||
def cwd
|
||||
@options[:cwd] || "."
|
||||
File.expand_path(@options[:cwd] || ".")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -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.50.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" "June 2012" "Foreman 0.49.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.
|
||||
|
||||
|
||||
@@ -72,6 +72,15 @@ describe "Foreman::CLI", :fakefs do
|
||||
it "includes the environment" 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
|
||||
end
|
||||
end
|
||||
|
||||
describe "version" do
|
||||
|
||||
@@ -90,6 +90,14 @@ describe "Foreman::Engine", :fakefs do
|
||||
subject.env["OTHER"].should == 'escaped"quote'
|
||||
end
|
||||
|
||||
it "should handle multiline strings" do
|
||||
File.open("/tmp/env", "w") do |f|
|
||||
f.puts 'FOO="bar\nbaz"'
|
||||
end
|
||||
subject.load_env "/tmp/env"
|
||||
subject.env["FOO"].should == "bar\nbaz"
|
||||
end
|
||||
|
||||
it "should fail if specified and doesnt exist" do
|
||||
lambda { subject.load_env "/tmp/env" }.should raise_error(Errno::ENOENT)
|
||||
end
|
||||
|
||||
@@ -18,4 +18,14 @@ describe Foreman::Export::Launchd, :fakefs do
|
||||
File.read("/tmp/init/app-bravo-1.plist").should == example_export_file("launchd/launchd-b.default")
|
||||
end
|
||||
|
||||
context "with multiple command arguments" do
|
||||
let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile", "charlie") }
|
||||
|
||||
it "splits each command argument" do
|
||||
launchd.export
|
||||
File.read("/tmp/init/app-alpha-1.plist").should == example_export_file("launchd/launchd-c.default")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# ----- foreman app processes -----
|
||||
AP01:4:respawn:/bin/su - app -c 'PORT=5000 ./alpha >> /var/log/app/alpha-1.log 2>&1'
|
||||
AP02:4:respawn:/bin/su - app -c 'PORT=5001 ./alpha >> /var/log/app/alpha-2.log 2>&1'
|
||||
AP01:4:respawn:/bin/su - app -c 'cd /tmp/app;export PORT=5000;./alpha >> /var/log/app/alpha-1.log 2>&1'
|
||||
AP02:4:respawn:/bin/su - app -c 'cd /tmp/app;export PORT=5001;./alpha >> /var/log/app/alpha-2.log 2>&1'
|
||||
# ----- end foreman app processes -----
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# ----- foreman app processes -----
|
||||
AP01:4:respawn:/bin/su - app -c 'PORT=5000 ./alpha >> /var/log/app/alpha-1.log 2>&1'
|
||||
AP02:4:respawn:/bin/su - app -c 'PORT=5100 ./bravo >> /var/log/app/bravo-1.log 2>&1'
|
||||
AP01:4:respawn:/bin/su - app -c 'cd /tmp/app;export PORT=5000;./alpha >> /var/log/app/alpha-1.log 2>&1'
|
||||
AP02:4:respawn:/bin/su - app -c 'cd /tmp/app;export PORT=5100;./bravo >> /var/log/app/bravo-1.log 2>&1'
|
||||
# ----- end foreman app processes -----
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>app-alpha-1</string>
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>PORT</key>
|
||||
<string>5000</string>
|
||||
</dict>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>./alpha</string>
|
||||
@@ -12,6 +17,8 @@
|
||||
<true/>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>StandardOutPath</key>
|
||||
<string>/var/log/app/app-alpha-1.log</string>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>/var/log/app/app-alpha-1.log</string>
|
||||
<key>UserName</key>
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>app-bravo-1</string>
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>PORT</key>
|
||||
<string>5100</string>
|
||||
</dict>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>./bravo</string>
|
||||
@@ -12,6 +17,8 @@
|
||||
<true/>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>StandardOutPath</key>
|
||||
<string>/var/log/app/app-bravo-1.log</string>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>/var/log/app/app-bravo-1.log</string>
|
||||
<key>UserName</key>
|
||||
|
||||
30
spec/resources/export/launchd/launchd-c.default
Normal file
30
spec/resources/export/launchd/launchd-c.default
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>app-alpha-1</string>
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>PORT</key>
|
||||
<string>5000</string>
|
||||
</dict>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>./alpha</string>
|
||||
<string>charlie</string>
|
||||
</array>
|
||||
<key>KeepAlive</key>
|
||||
<true/>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>StandardOutPath</key>
|
||||
<string>/var/log/app/app-alpha-1.log</string>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>/var/log/app/app-alpha-1.log</string>
|
||||
<key>UserName</key>
|
||||
<string>app</string>
|
||||
<key>WorkingDirectory</key>
|
||||
<string>/tmp/app</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -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
|
||||
|
||||
@@ -6,3 +6,11 @@ bash << "EOF"
|
||||
EOF
|
||||
|
||||
end script
|
||||
|
||||
start on (started network-interface
|
||||
or started network-manager
|
||||
or started networking)
|
||||
|
||||
stop on (stopping network-interface
|
||||
or stopping network-manager
|
||||
or stopping networking)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
require "rubygems"
|
||||
|
||||
require "simplecov"
|
||||
SimpleCov.start do
|
||||
add_filter "/spec/"
|
||||
@@ -58,6 +56,12 @@ def fork_and_capture(&blk)
|
||||
end
|
||||
end
|
||||
|
||||
def fork_and_get_exitstatus(args)
|
||||
pid = Process.spawn("bundle exec bin/foreman #{args}", :out => "/dev/null", :err => "/dev/null")
|
||||
Process.wait(pid)
|
||||
$?.exitstatus
|
||||
end
|
||||
|
||||
def mock_exit(&block)
|
||||
block.should raise_error(SystemExit)
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user