Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b49256175 | ||
|
|
37d777f224 | ||
|
|
73fc059634 | ||
|
|
f7b7029cc0 | ||
|
|
3a101ec7dd | ||
|
|
6c931ea15e | ||
|
|
d173570d98 | ||
|
|
0cd41fee7f | ||
|
|
9da4e38209 | ||
|
|
5d9dfd294e | ||
|
|
8998e9a47c | ||
|
|
8238a86942 | ||
|
|
1153fb0f0c | ||
|
|
f69c755d9a | ||
|
|
64f0749d16 | ||
|
|
6b77ca1e46 | ||
|
|
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 | ||
|
|
efb6d2f11d | ||
|
|
ac528d3b50 | ||
|
|
cefd4e351e | ||
|
|
9849f4558a | ||
|
|
4b53b42be1 | ||
|
|
219acaf690 | ||
|
|
f8118d7b40 | ||
|
|
7fdade277c | ||
|
|
1a0943c495 | ||
|
|
4a732abd77 | ||
|
|
3e71fea777 | ||
|
|
ae7aeabb63 | ||
|
|
0a61b1a62f | ||
|
|
9901b9f924 | ||
|
|
4c2d569810 | ||
|
|
26f9c8186d | ||
|
|
24ed8946f3 | ||
|
|
83b2a9cc50 | ||
|
|
a0228b9fa0 | ||
|
|
b1a2a4a0cd | ||
|
|
7774b7f150 | ||
|
|
b01355a093 | ||
|
|
8b18143281 | ||
|
|
e06886ed57 | ||
|
|
d6a00d7262 |
+11
-3
@@ -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,8 @@ notifications:
|
|||||||
on_failure: always
|
on_failure: always
|
||||||
urls:
|
urls:
|
||||||
- http://dx-helper.herokuapp.com/travis
|
- http://dx-helper.herokuapp.com/travis
|
||||||
|
|
||||||
|
rvm:
|
||||||
|
- 1.9.2
|
||||||
|
- 1.9.3
|
||||||
|
- jruby
|
||||||
|
|||||||
+102
@@ -1,3 +1,105 @@
|
|||||||
|
## 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 [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)
|
||||||
|
|
||||||
|
* 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
@@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
foreman (0.47.0)
|
foreman (0.60.2)
|
||||||
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.16.0)
|
||||||
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)
|
||||||
|
|||||||
+11
-2
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/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
|
#/ Run a command with exec, optionally changing directory first
|
||||||
|
|
||||||
@@ -16,9 +16,12 @@ usage() {
|
|||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts ":hd:" OPT; do
|
read_profile=""
|
||||||
|
|
||||||
|
while getopts ":hd:p" OPT; do
|
||||||
case $OPT in
|
case $OPT in
|
||||||
d) cd "$OPTARG" ;;
|
d) cd "$OPTARG" ;;
|
||||||
|
p) read_profile="1" ;;
|
||||||
h) usage ;;
|
h) usage ;;
|
||||||
\?) error "invalid option: -$OPTARG" ;;
|
\?) error "invalid option: -$OPTARG" ;;
|
||||||
:) error "option -$OPTARG requires an argument" ;;
|
:) error "option -$OPTARG requires an argument" ;;
|
||||||
@@ -29,4 +32,10 @@ shift $((OPTIND-1))
|
|||||||
|
|
||||||
[ -z "$1" ] && usage
|
[ -z "$1" ] && usage
|
||||||
|
|
||||||
|
if [ "$read_profile" = "1" ]; then
|
||||||
|
if [ -f .profile ]; then
|
||||||
|
. .profile
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
exec "$@"
|
exec "$@"
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
export FOO=bar
|
||||||
@@ -9,6 +9,6 @@ sigterm() {
|
|||||||
#trap sigterm SIGTERM
|
#trap sigterm SIGTERM
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
echo "$NAME: ping"
|
echo "$NAME: ping $$"
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -4,14 +4,25 @@
|
|||||||
<dict>
|
<dict>
|
||||||
<key>Label</key>
|
<key>Label</key>
|
||||||
<string><%= "#{app}-#{name}-#{num}" %></string>
|
<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>
|
<key>ProgramArguments</key>
|
||||||
<array>
|
<array>
|
||||||
<string><%= process.command %></string>
|
<%- command_args.each do |command| -%>
|
||||||
|
<string><%= command %></string>
|
||||||
|
<%- end -%>
|
||||||
</array>
|
</array>
|
||||||
<key>KeepAlive</key>
|
<key>KeepAlive</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>RunAtLoad</key>
|
<key>RunAtLoad</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>StandardOutPath</key>
|
||||||
|
<string><%= log %>/<%= app %>-<%= name %>-<%=num%>.log</string>
|
||||||
<key>StandardErrorPath</key>
|
<key>StandardErrorPath</key>
|
||||||
<string><%= log %>/<%= app %>-<%= name %>-<%=num%>.log</string>
|
<string><%= log %>/<%= app %>-<%= name %>-<%=num%>.log</string>
|
||||||
<key>UserName</key>
|
<key>UserName</key>
|
||||||
|
|||||||
@@ -6,3 +6,11 @@ bash << "EOF"
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
end script
|
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)
|
||||||
|
|||||||
Vendored
+16
@@ -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"
|
defined?(RUBY_PLATFORM) and RUBY_PLATFORM == "java"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.ruby_18?
|
||||||
|
defined?(RUBY_VERSION) and RUBY_VERSION =~ /^1\.8\.\d+/
|
||||||
|
end
|
||||||
|
|
||||||
def self.windows?
|
def self.windows?
|
||||||
defined?(RUBY_PLATFORM) and RUBY_PLATFORM =~ /(win|w)32$/
|
defined?(RUBY_PLATFORM) and RUBY_PLATFORM =~ /(win|w)32$/
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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
|
||||||
+34
-13
@@ -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"
|
||||||
@@ -70,24 +75,40 @@ class Foreman::CLI < Thor
|
|||||||
|
|
||||||
def run(*args)
|
def run(*args)
|
||||||
load_environment!
|
load_environment!
|
||||||
begin
|
|
||||||
exec engine.env, args.shelljoin
|
if File.exist?(procfile)
|
||||||
rescue Errno::EACCES
|
engine.load_procfile(procfile)
|
||||||
error "not executable: #{args.first}"
|
|
||||||
rescue Errno::ENOENT
|
|
||||||
error "command not found: #{args.first}"
|
|
||||||
end
|
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"
|
||||||
|
|
||||||
|
def version
|
||||||
|
puts Foreman::VERSION
|
||||||
end
|
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
|
||||||
@@ -118,7 +139,7 @@ private ######################################################################
|
|||||||
def procfile
|
def procfile
|
||||||
case
|
case
|
||||||
when options[:procfile] then options[:procfile]
|
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"
|
else "Procfile"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -126,7 +147,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
|
||||||
|
|
||||||
|
|||||||
+45
-17
@@ -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
|
||||||
@@ -99,10 +99,17 @@ class Foreman::Engine
|
|||||||
# @param [String] signal The signal to send to each process
|
# @param [String] signal The signal to send to each process
|
||||||
#
|
#
|
||||||
def killall(signal="SIGTERM")
|
def killall(signal="SIGTERM")
|
||||||
@running.each do |pid, (process, index)|
|
if Foreman.windows?
|
||||||
system "sending #{signal} to #{name_for(pid)} at pid #{pid}"
|
@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
|
begin
|
||||||
Process.kill(signal, -1 * pid)
|
Process.kill "-#{signal}", Process.pid
|
||||||
rescue Errno::ESRCH, Errno::EPERM
|
rescue Errno::ESRCH, Errno::EPERM
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -157,8 +164,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 +203,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 +213,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("=")
|
||||||
@@ -236,7 +256,9 @@ private
|
|||||||
1.upto(formation[@names[process]]) do |n|
|
1.upto(formation[@names[process]]) do |n|
|
||||||
reader, writer = create_pipe
|
reader, writer = create_pipe
|
||||||
begin
|
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}"
|
writer.puts "started with pid #{pid}"
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
writer.puts "unknown command: #{process.command}"
|
writer.puts "unknown command: #{process.command}"
|
||||||
@@ -251,9 +273,10 @@ private
|
|||||||
Thread.new do
|
Thread.new do
|
||||||
begin
|
begin
|
||||||
loop do
|
loop do
|
||||||
(IO.select(@readers.values).first || []).each do |reader|
|
io = IO.select(@readers.values, nil, nil, 30)
|
||||||
|
(io.nil? ? [] : io.first).each do |reader|
|
||||||
data = reader.gets
|
data = reader.gets
|
||||||
output_with_mutex name_for(@readers.key(reader)), data
|
output_with_mutex name_for(@readers.invert[reader]), data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Exception => ex
|
rescue Exception => ex
|
||||||
@@ -275,8 +298,13 @@ private
|
|||||||
def terminate_gracefully
|
def terminate_gracefully
|
||||||
return if @terminating
|
return if @terminating
|
||||||
@terminating = true
|
@terminating = true
|
||||||
system "sending SIGTERM to all processes"
|
if Foreman.windows?
|
||||||
killall "SIGTERM"
|
system "sending SIGKILL to all processes"
|
||||||
|
killall "SIGKILL"
|
||||||
|
else
|
||||||
|
system "sending SIGTERM to all processes"
|
||||||
|
killall "SIGTERM"
|
||||||
|
end
|
||||||
Timeout.timeout(5) do
|
Timeout.timeout(5) do
|
||||||
watch_for_termination while @running.length > 0
|
watch_for_termination while @running.length > 0
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,11 +24,14 @@ 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 if Foreman.windows?
|
||||||
return false unless self.respond_to?(:isatty)
|
return false unless self.respond_to?(:isatty)
|
||||||
self.isatty && ENV["TERM"]
|
self.isatty && ENV["TERM"]
|
||||||
end
|
end
|
||||||
@@ -46,19 +49,22 @@ class Foreman::Engine::CLI < Foreman::Engine
|
|||||||
|
|
||||||
def startup
|
def startup
|
||||||
@colors = map_colors
|
@colors = map_colors
|
||||||
proctitle "foreman: master"
|
proctitle "foreman: master" unless Foreman.windows?
|
||||||
|
Color.enable($stdout, options[:color])
|
||||||
end
|
end
|
||||||
|
|
||||||
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?)
|
|
||||||
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
|
||||||
|
|||||||
+3
-1
@@ -9,8 +9,10 @@ class Foreman::Env
|
|||||||
if line =~ /\A([A-Za-z_0-9]+)=(.*)\z/
|
if line =~ /\A([A-Za-z_0-9]+)=(.*)\z/
|
||||||
key = $1
|
key = $1
|
||||||
case val = $2
|
case val = $2
|
||||||
|
# Remove single quotes
|
||||||
when /\A'(.*)'\z/ then ax[key] = $1
|
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
|
else ax[key] = val
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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,17 +94,32 @@ 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)
|
||||||
compiled = ERB.new(export_template(name)).result(binding)
|
compiled = ERB.new(export_template(name), nil, '-').result(binding)
|
||||||
write_file target, compiled
|
write_file target, compiled
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -13,7 +13,16 @@ class Foreman::Export::Inittab < Foreman::Export::Base
|
|||||||
1.upto(engine.formation[name]) do |num|
|
1.upto(engine.formation[name]) do |num|
|
||||||
id = app.slice(0, 2).upcase + sprintf("%02d", index)
|
id = app.slice(0, 2).upcase + sprintf("%02d", index)
|
||||||
port = engine.port_for(process, num)
|
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
|
index += 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ class Foreman::Export::Launchd < Foreman::Export::Base
|
|||||||
super
|
super
|
||||||
engine.each_process do |name, process|
|
engine.each_process do |name, process|
|
||||||
1.upto(engine.formation[name]) do |num|
|
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
|
write_template "launchd/launchd.plist.erb", "#{app}-#{name}-#{num}.plist", binding
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+53
-12
@@ -21,6 +21,21 @@ class Foreman::Process
|
|||||||
@options[:env] ||= {}
|
@options[:env] ||= {}
|
||||||
end
|
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+
|
# Run a +Process+
|
||||||
#
|
#
|
||||||
# @param [Hash] options
|
# @param [Hash] options
|
||||||
@@ -31,31 +46,55 @@ class Foreman::Process
|
|||||||
# @returns [Fixnum] pid The +pid+ of the process
|
# @returns [Fixnum] pid The +pid+ of the process
|
||||||
#
|
#
|
||||||
def run(options={})
|
def run(options={})
|
||||||
env = options[:env] ? @options[:env].merge(options[:env]) : @options[:env]
|
env = @options[:env].merge(options[:env] || {})
|
||||||
output = options[:output] || $stdout
|
output = options[:output] || $stdout
|
||||||
|
|
||||||
if Foreman.windows?
|
if Foreman.windows?
|
||||||
Dir.chdir(cwd) do
|
Dir.chdir(cwd) do
|
||||||
Process.spawn env, command, :out => output, :err => output, :new_pgroup => true
|
Process.spawn env, expanded_command(env), :out => output, :err => output
|
||||||
end
|
end
|
||||||
elsif Foreman.jruby?
|
elsif Foreman.jruby?
|
||||||
Dir.chdir(cwd) do
|
require "posix/spawn"
|
||||||
require "posix/spawn"
|
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
||||||
POSIX::Spawn.spawn env, command, :out => output, :err => output, :pgroup => 0
|
POSIX::Spawn.spawn env, wrapped_command, :out => output, :err => output
|
||||||
|
elsif Foreman.ruby_18?
|
||||||
|
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
|
end
|
||||||
else
|
else
|
||||||
Dir.chdir(cwd) do
|
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
||||||
Process.spawn env, command, :out => output, :err => output, :pgroup => 0
|
Process.spawn env, wrapped_command, :out => output, :err => output
|
||||||
end
|
|
||||||
end
|
end
|
||||||
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+
|
# Send a signal to this +Process+
|
||||||
#
|
#
|
||||||
# @param [String] signal The signal to send
|
# @param [String] signal The signal to send
|
||||||
#
|
#
|
||||||
def kill(signal)
|
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
|
rescue Errno::ESRCH
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
@@ -76,10 +115,12 @@ class Foreman::Process
|
|||||||
!alive?
|
!alive?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
# Returns the working directory for this +Process+
|
||||||
|
#
|
||||||
|
# @returns [String]
|
||||||
|
#
|
||||||
def cwd
|
def cwd
|
||||||
@options[:cwd] || "."
|
File.expand_path(@options[:cwd] || ".")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Foreman
|
module Foreman
|
||||||
|
|
||||||
VERSION = "0.47.0"
|
VERSION = "0.60.2"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
.\" generated with Ronn/v0.7.3
|
.\" generated with Ronn/v0.7.3
|
||||||
.\" http://github.com/rtomayko/ronn/tree/0.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" "August 2012" "Foreman 0.60.1" "Foreman Manual"
|
||||||
.
|
.
|
||||||
.SH "NAME"
|
.SH "NAME"
|
||||||
\fBforeman\fR \- manage Procfile\-based applications
|
\fBforeman\fR \- manage Procfile\-based applications
|
||||||
|
|||||||
@@ -72,6 +72,25 @@ describe "Foreman::CLI", :fakefs do
|
|||||||
it "includes the environment" do
|
it "includes the environment" do
|
||||||
forked_foreman("run #{resource_path("bin/env FOO")} -e #{resource_path(".env")}").should == "bar\n"
|
forked_foreman("run #{resource_path("bin/env FOO")} -e #{resource_path(".env")}").should == "bar\n"
|
||||||
end
|
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
|
||||||
|
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
|
end
|
||||||
|
|||||||
@@ -90,6 +90,14 @@ describe "Foreman::Engine", :fakefs do
|
|||||||
subject.env["OTHER"].should == 'escaped"quote'
|
subject.env["OTHER"].should == 'escaped"quote'
|
||||||
end
|
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
|
it "should fail if specified and doesnt exist" do
|
||||||
lambda { subject.load_env "/tmp/env" }.should raise_error(Errno::ENOENT)
|
lambda { subject.load_env "/tmp/env" }.should raise_error(Errno::ENOENT)
|
||||||
end
|
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")
|
File.read("/tmp/init/app-bravo-1.plist").should == example_export_file("launchd/launchd-b.default")
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# ----- foreman app processes -----
|
# ----- foreman app processes -----
|
||||||
AP01:4:respawn:/bin/su - app -c 'PORT=5000 ./alpha >> /var/log/app/alpha-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 'PORT=5001 ./alpha >> /var/log/app/alpha-2.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 -----
|
# ----- end foreman app processes -----
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# ----- foreman app processes -----
|
# ----- foreman app processes -----
|
||||||
AP01:4:respawn:/bin/su - app -c 'PORT=5000 ./alpha >> /var/log/app/alpha-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 'PORT=5100 ./bravo >> /var/log/app/bravo-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 -----
|
# ----- end foreman app processes -----
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
<dict>
|
<dict>
|
||||||
<key>Label</key>
|
<key>Label</key>
|
||||||
<string>app-alpha-1</string>
|
<string>app-alpha-1</string>
|
||||||
|
<key>EnvironmentVariables</key>
|
||||||
|
<dict>
|
||||||
|
<key>PORT</key>
|
||||||
|
<string>5000</string>
|
||||||
|
</dict>
|
||||||
<key>ProgramArguments</key>
|
<key>ProgramArguments</key>
|
||||||
<array>
|
<array>
|
||||||
<string>./alpha</string>
|
<string>./alpha</string>
|
||||||
@@ -12,6 +17,8 @@
|
|||||||
<true/>
|
<true/>
|
||||||
<key>RunAtLoad</key>
|
<key>RunAtLoad</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>StandardOutPath</key>
|
||||||
|
<string>/var/log/app/app-alpha-1.log</string>
|
||||||
<key>StandardErrorPath</key>
|
<key>StandardErrorPath</key>
|
||||||
<string>/var/log/app/app-alpha-1.log</string>
|
<string>/var/log/app/app-alpha-1.log</string>
|
||||||
<key>UserName</key>
|
<key>UserName</key>
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
<dict>
|
<dict>
|
||||||
<key>Label</key>
|
<key>Label</key>
|
||||||
<string>app-bravo-1</string>
|
<string>app-bravo-1</string>
|
||||||
|
<key>EnvironmentVariables</key>
|
||||||
|
<dict>
|
||||||
|
<key>PORT</key>
|
||||||
|
<string>5100</string>
|
||||||
|
</dict>
|
||||||
<key>ProgramArguments</key>
|
<key>ProgramArguments</key>
|
||||||
<array>
|
<array>
|
||||||
<string>./bravo</string>
|
<string>./bravo</string>
|
||||||
@@ -12,6 +17,8 @@
|
|||||||
<true/>
|
<true/>
|
||||||
<key>RunAtLoad</key>
|
<key>RunAtLoad</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>StandardOutPath</key>
|
||||||
|
<string>/var/log/app/app-bravo-1.log</string>
|
||||||
<key>StandardErrorPath</key>
|
<key>StandardErrorPath</key>
|
||||||
<string>/var/log/app/app-bravo-1.log</string>
|
<string>/var/log/app/app-bravo-1.log</string>
|
||||||
<key>UserName</key>
|
<key>UserName</key>
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -6,3 +6,11 @@ bash << "EOF"
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
end script
|
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)
|
||||||
|
|||||||
+6
-1
@@ -54,11 +54,16 @@ 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
|
||||||
|
|
||||||
|
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)
|
def mock_exit(&block)
|
||||||
block.should raise_error(SystemExit)
|
block.should raise_error(SystemExit)
|
||||||
end
|
end
|
||||||
|
|||||||
+2
-3
@@ -32,10 +32,10 @@ def latest_release
|
|||||||
end
|
end
|
||||||
|
|
||||||
def newer_release
|
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])
|
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"
|
||||||
@@ -60,7 +60,6 @@ end
|
|||||||
|
|
||||||
desc "Cut a release"
|
desc "Cut a release"
|
||||||
task :release do
|
task :release do
|
||||||
Rake::Task["authors"].invoke
|
|
||||||
Rake::Task["changelog"].invoke
|
Rake::Task["changelog"].invoke
|
||||||
Rake::Task["pages"].invoke
|
Rake::Task["pages"].invoke
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user