Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0da42cf7d2 | ||
|
|
23561b963c | ||
|
|
cc51ab2cb1 | ||
|
|
403d40b277 | ||
|
|
f1c2347680 | ||
|
|
80f8242b11 | ||
|
|
383276bb79 | ||
|
|
5a7692ff2c | ||
|
|
405a85bc86 | ||
|
|
bff554d554 | ||
|
|
eaed989c75 | ||
|
|
93daebbf1b | ||
|
|
17a8a316b8 | ||
|
|
9e1d590734 | ||
|
|
1cb1c8812a | ||
|
|
6786f4df39 | ||
|
|
0be08a0651 | ||
|
|
3abe10e5ab | ||
|
|
66ab0f08e7 | ||
|
|
7be4375168 | ||
|
|
8d1e3a849f | ||
|
|
5ef8bbdbe3 | ||
|
|
8cf5896c3e | ||
|
|
5f8032cac8 | ||
|
|
9f3b903085 | ||
|
|
69d278d864 | ||
|
|
9325f2ca6d | ||
|
|
9a91e5df44 |
13
Changelog.md
13
Changelog.md
@@ -1,6 +1,17 @@
|
||||
## 0.62.0 (2013-03-08)
|
||||
|
||||
* Merge pull request #334 from ged/reentrant_signal_handlers [David Dollar]
|
||||
* Merge pull request #335 from ged/20_encoding_fix [David Dollar]
|
||||
* Try to allow children to shut down gracefully [Michael Granger]
|
||||
* Add deferred signal-handling (fixes #332). [Michael Granger]
|
||||
* Fix spec encoding problem under Ruby 2.0.0. [Michael Granger]
|
||||
* add ruby 2.0 to travis [David Dollar]
|
||||
* Merge pull request #327 from patheticpat/master [David Dollar]
|
||||
* Fixed a typo in cli options description [Michael Kaiser]
|
||||
* handled by mingw now [David Dollar]
|
||||
|
||||
## 0.61.0 (2013-01-14)
|
||||
|
||||
* 0.61.0 [David Dollar]
|
||||
* Fix bug in color definitons [nseo]
|
||||
* Fix for high CPU load when processes close output [Pavel Forkert]
|
||||
* Ensure foreman is the process group leader [Christos Trochalakis]
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
foreman (0.62.0)
|
||||
foreman (0.63.0)
|
||||
dotenv (>= 0.7)
|
||||
thor (>= 0.13.6)
|
||||
|
||||
GEM
|
||||
@@ -13,6 +14,7 @@ GEM
|
||||
xml-simple
|
||||
builder (3.0.0)
|
||||
diff-lcs (1.1.3)
|
||||
dotenv (0.7.0)
|
||||
fakefs (0.3.2)
|
||||
hpricot (0.8.6)
|
||||
hpricot (0.8.6-java)
|
||||
|
||||
19
LICENSE
Normal file
19
LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2012 David Dollar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -43,4 +43,6 @@ David Dollar
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
Foreman is licensed under the MIT license.
|
||||
|
||||
See LICENSE for the full license text.
|
||||
|
||||
@@ -34,7 +34,7 @@ shift $((OPTIND-1))
|
||||
|
||||
if [ "$read_profile" = "1" ]; then
|
||||
if [ -f .profile ]; then
|
||||
. .profile
|
||||
. ./.profile
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -7,10 +7,6 @@ EOF
|
||||
|
||||
end script
|
||||
|
||||
start on (started network-interface
|
||||
or started network-manager
|
||||
or started networking)
|
||||
start on runlevel [2345]
|
||||
|
||||
stop on (stopping network-interface
|
||||
or stopping network-manager
|
||||
or stopping networking)
|
||||
stop on runlevel [016]
|
||||
|
||||
@@ -18,9 +18,9 @@ Gem::Specification.new do |gem|
|
||||
gem.files << "man/foreman.1"
|
||||
|
||||
gem.add_dependency 'thor', '>= 0.13.6'
|
||||
gem.add_dependency 'dotenv', '>= 0.7'
|
||||
|
||||
if ENV["PLATFORM"] == "java"
|
||||
gem.add_dependency "posix-spawn", "~> 0.3.6"
|
||||
gem.platform = Gem::Platform.new("java")
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require "foreman"
|
||||
require "foreman/env"
|
||||
require "foreman/process"
|
||||
require "foreman/procfile"
|
||||
require "dotenv"
|
||||
require "tempfile"
|
||||
require "timeout"
|
||||
require "fileutils"
|
||||
@@ -52,9 +52,6 @@ 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?
|
||||
|
||||
register_signal_handlers
|
||||
startup
|
||||
spawn_processes
|
||||
@@ -172,9 +169,7 @@ class Foreman::Engine
|
||||
# @param [String] filename A .env file to load into the environment
|
||||
#
|
||||
def load_env(filename)
|
||||
Foreman::Env.new(filename).entries do |name, value|
|
||||
@env[name] = value
|
||||
end
|
||||
@env.update Dotenv::Environment.new(filename)
|
||||
end
|
||||
|
||||
# Send a signal to all processes started by this +Engine+
|
||||
@@ -207,7 +202,7 @@ class Foreman::Engine
|
||||
kill_children(signal)
|
||||
else
|
||||
begin
|
||||
Process.kill "-#{signal}", Process.getpgrp
|
||||
Process.kill "-#{signal}", Process.pid
|
||||
rescue Errno::ESRCH, Errno::EPERM
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
require "foreman"
|
||||
|
||||
class Foreman::Env
|
||||
|
||||
attr_reader :entries
|
||||
|
||||
def initialize(filename)
|
||||
@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
|
||||
# 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
|
||||
ax
|
||||
end
|
||||
end
|
||||
|
||||
def entries
|
||||
@entries.each do |key, value|
|
||||
yield key, value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -6,7 +6,7 @@ class Foreman::Export::Upstart < Foreman::Export::Base
|
||||
def export
|
||||
super
|
||||
|
||||
Dir["#{location}/#{app}*.conf"].each do |file|
|
||||
(Dir["#{location}/#{app}-*.conf"] << "#{location}/#{app}.conf").each do |file|
|
||||
clean file
|
||||
end
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ private
|
||||
|
||||
def parse(filename)
|
||||
File.read(filename).gsub("\r\n","\n").split("\n").map do |line|
|
||||
if line =~ /^([A-Za-z0-9_]+):\s*(.+)$/
|
||||
if line =~ /^([A-Za-z0-9_-]+):\s*(.+)$/
|
||||
[$1, $2]
|
||||
end
|
||||
end.compact
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module Foreman
|
||||
|
||||
VERSION = "0.62.0"
|
||||
VERSION = "0.63.0"
|
||||
|
||||
end
|
||||
|
||||
@@ -46,10 +46,6 @@ Specify an alternate Procfile to load, implies \fB\-d\fR at the Procfile root\.
|
||||
\fB\-p\fR, \fB\-\-port\fR
|
||||
Specify which port to use as the base for this application\. Should be a multiple of 1000\.
|
||||
.
|
||||
.TP
|
||||
\fB\-t\fR, \fB\-\-tmux\fR
|
||||
Runs the processes in a tmux session\. Creates one window for each process and an extra window containing the output of each window (requires gawk)\.
|
||||
.
|
||||
.P
|
||||
\fBforeman run\fR is used to run one\-off commands using the same environment as your defined processes\.
|
||||
.
|
||||
@@ -234,7 +230,7 @@ Run one process type from the application defined in a specific Procfile:
|
||||
.
|
||||
.nf
|
||||
|
||||
$ foreman start alpha \-p ~/myapp/Procfile
|
||||
$ foreman start alpha \-f ~/myapp/Procfile
|
||||
.
|
||||
.fi
|
||||
.
|
||||
|
||||
@@ -40,10 +40,6 @@ The following options control how the application is run:
|
||||
Specify which port to use as the base for this application. Should be
|
||||
a multiple of 1000.
|
||||
|
||||
* `-t`, `--tmux`:
|
||||
Runs the processes in a tmux session. Creates one window for each process
|
||||
and an extra window containing the output of each window (requires gawk).
|
||||
|
||||
`foreman run` is used to run one-off commands using the same environment
|
||||
as your defined processes.
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ describe "Foreman::CLI", :fakefs do
|
||||
describe "check" do
|
||||
it "with a valid Procfile displays the jobs" do
|
||||
write_procfile
|
||||
foreman("check").should == "valid procfile detected (alpha, bravo)\n"
|
||||
foreman("check").should == "valid procfile detected (alpha, bravo, foo_bar, foo-bar)\n"
|
||||
end
|
||||
|
||||
it "with a blank Procfile displays an error" do
|
||||
|
||||
@@ -29,11 +29,27 @@ describe Foreman::Export::Upstart, :fakefs do
|
||||
mock(FileUtils).rm("/tmp/init/app-alpha-1.conf")
|
||||
mock(FileUtils).rm("/tmp/init/app-bravo.conf")
|
||||
mock(FileUtils).rm("/tmp/init/app-bravo-1.conf")
|
||||
mock(FileUtils).rm("/tmp/init/app-foo-bar.conf")
|
||||
mock(FileUtils).rm("/tmp/init/app-foo-bar-1.conf")
|
||||
mock(FileUtils).rm("/tmp/init/app-foo_bar.conf")
|
||||
mock(FileUtils).rm("/tmp/init/app-foo_bar-1.conf")
|
||||
|
||||
upstart.export
|
||||
upstart.export
|
||||
end
|
||||
|
||||
it "does not delete exported files for similarly named applications" do
|
||||
FileUtils.mkdir_p "/tmp/init"
|
||||
|
||||
["app2", "app2-alpha", "app2-alpha-1"].each do |name|
|
||||
path = "/tmp/init/#{name}.conf"
|
||||
FileUtils.touch(path)
|
||||
dont_allow(FileUtils).rm(path)
|
||||
end
|
||||
|
||||
upstart.export
|
||||
end
|
||||
|
||||
it "quotes and escapes environment variables" do
|
||||
engine.env['KEY'] = 'd"\|d'
|
||||
upstart.export
|
||||
|
||||
@@ -16,8 +16,10 @@ describe Foreman::Procfile, :fakefs do
|
||||
it "loads a passed-in Procfile" do
|
||||
write_procfile
|
||||
procfile = Foreman::Procfile.new("Procfile")
|
||||
procfile["alpha"].should == "./alpha"
|
||||
procfile["bravo"].should == "./bravo"
|
||||
procfile["alpha"].should == "./alpha"
|
||||
procfile["bravo"].should == "./bravo"
|
||||
procfile["foo-bar"].should == "./foo-bar"
|
||||
procfile["foo_bar"].should == "./foo_bar"
|
||||
end
|
||||
|
||||
it "can have a process appended to it" do
|
||||
|
||||
@@ -42,5 +42,40 @@ Bluepill.application("app", :foreground => false, :log_file => "/var/log/bluepil
|
||||
process.group = "app-bravo"
|
||||
end
|
||||
|
||||
app.process("foo_bar-1") do |process|
|
||||
process.start_command = "./foo_bar"
|
||||
|
||||
process.working_dir = "/tmp/app"
|
||||
process.daemonize = true
|
||||
process.environment = {"PORT"=>"5200"}
|
||||
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
|
||||
process.stop_grace_time = 45.seconds
|
||||
|
||||
process.stdout = process.stderr = "/var/log/app/app-foo_bar-1.log"
|
||||
|
||||
process.monitor_children do |children|
|
||||
children.stop_command "kill {{PID}}"
|
||||
end
|
||||
|
||||
process.group = "app-foo_bar"
|
||||
end
|
||||
|
||||
app.process("foo-bar-1") do |process|
|
||||
process.start_command = "./foo-bar"
|
||||
|
||||
process.working_dir = "/tmp/app"
|
||||
process.daemonize = true
|
||||
process.environment = {"PORT"=>"5300"}
|
||||
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
|
||||
process.stop_grace_time = 45.seconds
|
||||
|
||||
process.stdout = process.stderr = "/var/log/app/app-foo-bar-1.log"
|
||||
|
||||
process.monitor_children do |children|
|
||||
|
||||
children.stop_command "kill {{PID}}"
|
||||
end
|
||||
|
||||
process.group = "app-foo-bar"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# ----- foreman app processes -----
|
||||
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'
|
||||
AP03:4:respawn:/bin/su - app -c 'cd /tmp/app;export PORT=5200;./foo_bar >> /var/log/app/foo_bar-1.log 2>&1'
|
||||
AP04:4:respawn:/bin/su - app -c 'cd /tmp/app;export PORT=5300;./foo-bar >> /var/log/app/foo-bar-1.log 2>&1'
|
||||
# ----- end foreman app processes -----
|
||||
|
||||
@@ -19,6 +19,26 @@ stderr_logfile=/var/log/app/bravo-1.error.log
|
||||
user=app
|
||||
directory=/tmp/app
|
||||
environment=PORT=5100
|
||||
[program:app-foo_bar-1]
|
||||
command=./foo_bar
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stopsignal=QUIT
|
||||
stdout_logfile=/var/log/app/foo_bar-1.log
|
||||
stderr_logfile=/var/log/app/foo_bar-1.error.log
|
||||
user=app
|
||||
directory=/tmp/app
|
||||
environment=PORT=5200
|
||||
[program:app-foo-bar-1]
|
||||
command=./foo-bar
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stopsignal=QUIT
|
||||
stdout_logfile=/var/log/app/foo-bar-1.log
|
||||
stderr_logfile=/var/log/app/foo-bar-1.error.log
|
||||
user=app
|
||||
directory=/tmp/app
|
||||
environment=PORT=5300
|
||||
|
||||
[group:app]
|
||||
programs=app-alpha-1,app-bravo-1
|
||||
programs=app-alpha-1,app-bravo-1,app-foo_bar-1,app-foo-bar-1
|
||||
|
||||
@@ -7,10 +7,6 @@ EOF
|
||||
|
||||
end script
|
||||
|
||||
start on (started network-interface
|
||||
or started network-manager
|
||||
or started networking)
|
||||
start on runlevel [2345]
|
||||
|
||||
stop on (stopping network-interface
|
||||
or stopping network-manager
|
||||
or stopping networking)
|
||||
stop on runlevel [016]
|
||||
|
||||
@@ -79,6 +79,8 @@ def write_procfile(procfile="Procfile", alpha_env="")
|
||||
file.puts "alpha: ./alpha" + " #{alpha_env}".rstrip
|
||||
file.puts "\n"
|
||||
file.puts "bravo:\t./bravo"
|
||||
file.puts "foo_bar:\t./foo_bar"
|
||||
file.puts "foo-bar:\t./foo-bar"
|
||||
end
|
||||
File.expand_path(procfile)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user