Compare commits

..

32 Commits

Author SHA1 Message Date
David Dollar
a87a882e60 0.47.0 2012-06-07 22:49:51 -04:00
David Dollar
6ba9252d0f Merge pull request #165 from elf-pavlik/master
list of ports to other languages added to README
2012-06-07 19:45:11 -07:00
David Dollar
efd9e2119b Merge pull request #173 from Viximo/feature/escape-env
Quote and escape environment variables in upstart templates
2012-06-07 19:43:20 -07:00
David Dollar
bf9bdbf118 Merge pull request #194 from maxpow4h/master
Added launchd to exporters
2012-06-07 19:41:23 -07:00
David Dollar
929a138e54 Merge pull request #195 from aneeth/patch-1
Updated data/export/bluepill/master.pill.erb
2012-06-07 19:41:09 -07:00
David Dollar
d6514b4f33 Merge pull request #201 from sos4nt/patch-1
Terminate gracefully upon SIGHUP
2012-06-07 19:40:38 -07:00
David Dollar
8696a36833 Merge pull request #208 from dbrock/master
Fix multi-word argument handling in `foreman run`.
2012-06-06 07:48:44 -07:00
Daniel Brockman
3ea5de42aa Fix multi-word argument handling in foreman run. 2012-06-06 15:36:59 +02:00
David Dollar
4a13122082 Merge pull request #199 from atog/master
set port from .env if specified
2012-05-16 15:06:56 -07:00
Koen Van der Auwera
9b2987c3f0 make 'PORT=5000 foreman start' work 2012-05-16 23:59:09 +02:00
Stefan Schüßler
6274f99225 Terminate gracefully upon SIGHUP
Tmux sends SIGHUP when a session is killed which can result in orphaned processes. Adding a SIGHUP handler terminates the processes as expected.
2012-05-14 13:04:46 +03:00
Koen Van der Auwera
0b0324fed9 set port from .env if specified 2012-05-11 14:17:03 +02:00
Aneeth
32db70b778 Updated data/export/bluepill/master.pill.erb to read in the environment variables from the foreman .env file and reflect it in the pill file 2012-05-04 15:53:16 +08:00
Maxwell Swadling
3db1ad6fbc Added launchd exporter 2012-05-04 15:21:16 +10:00
David Dollar
003b466a17 Merge pull request #193 from pat2man/patch-1
Add stop_grace_time to bluepill config
2012-05-03 12:16:23 -07:00
Patrick Tescher
2a896a0fb5 Add stop_grace_time to bluepill config. Fixes this error message:
Config Error: Stop_grace_time should be greater than the sum of stop_signals delays!

Changed bluepill spec example files to include stop_grace_time
2012-05-03 12:11:24 -07:00
David Dollar
6a8c81a38b Revert "Merge pull request #192 from pat2man/patch-1"
This reverts commit a83dab363e, reversing
changes made to e0fe5baf1b.
2012-05-03 14:53:31 -04:00
David Dollar
a83dab363e Merge pull request #192 from pat2man/patch-1
Add stop_grace_time to bluepill config
2012-05-03 11:52:02 -07:00
Patrick Tescher
53e0f4ecf9 Add stop_grace_time to bluepill config. Fixes this error message:
Config Error: Stop_grace_time should be greater than the sum of stop_signals delays!
2012-05-03 11:50:29 -07:00
David Dollar
e0fe5baf1b update docs 2012-05-02 13:21:02 -04:00
David Dollar
1aa1f15b8f update changelog 2012-05-02 13:20:54 -04:00
David Dollar
fa46a605bb 0.46.0 2012-05-02 13:19:11 -04:00
David Dollar
3077857ab7 Merge pull request #191 from ged/profile_load_write_append
Add Procfile load/write/append API
2012-05-02 10:03:31 -07:00
David Dollar
08aa8f9d5d Merge pull request #190 from ged/remove_obsolete_spec
Remove spec obsoleted by 91a8704
2012-05-02 10:01:30 -07:00
Michael Granger
771489dec9 Remove spec obsoleted by 91a8704 2012-05-02 09:37:32 -07:00
Michael Granger
053ae8f0be Add Profile load/write/append API 2012-05-02 09:30:57 -07:00
David Dollar
af58af1c60 Merge pull request #187 from bkaney/master
Guard against missing Procfile in engine.rb
2012-04-29 21:00:58 -07:00
David Dollar
9075d93370 update docs 2012-04-26 17:50:03 -04:00
David Dollar
0c2e9df722 changelog 2012-04-26 17:50:00 -04:00
Brian Kaney
91a87049db Guard against missing Procfile in engine.rb
Should be able to 'foreman run <task>' without a Procfile.  This seems true to the orig. intent as the cli does not directly check with 'run' (as it  does for 'start').
2012-04-24 15:51:14 -04:00
Matt Griffin
2fcb64959b Quote and escape environment variables in upstart templates 2012-04-03 16:36:18 -04:00
elf Pavlik
a5465bf55e added list of ports to other languages to README 2012-03-18 09:35:51 +01:00
28 changed files with 273 additions and 32 deletions

View File

@@ -1,3 +1,13 @@
## 0.46.0 (2012-05-02)
* Add Profile load/write/append API [Michael Granger]
* Guard against missing Procfile in engine.rb [Brian Kaney]
## 0.45.0 (2012-04-26)
* create and chown log dir in upstart export. [Phil Hagelberg]
* remove parka from dist files [David Dollar]
## 0.44.0 (2012-04-23)
* make var output order repeatable in supervisord export [David Dollar]

View File

@@ -1,7 +1,7 @@
PATH
remote: .
specs:
foreman (0.45.0)
foreman (0.47.0)
thor (>= 0.13.6)
GEM

View File

@@ -27,6 +27,12 @@ Manage Procfile-based applications
* [wiki](http://github.com/ddollar/foreman/wiki)
* [changelog](https://github.com/ddollar/foreman/blob/master/Changelog.md)
## Ports
* [shoreman](https://github.com/hecticjeff/shoreman) - shell
* [honcho](https://github.com/nickstenning/honcho) - python
* [norman](https://github.com/josh/norman) - node.js
## Authors
#### Created and maintained by

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
#/ Usage: foreman-runner [-d <dir>] <command>
#/ Usage: foreman-runner [-d <dir>] <command> [<args>...]
#/
#/ Run a command with exec, optionally changing directory first
@@ -27,10 +27,6 @@ done
shift $((OPTIND-1))
command=$1
[ -z "$1" ] && usage
if [ -z "$1" ]; then
usage
fi
exec $1
exec "$@"

View File

@@ -11,8 +11,9 @@ Bluepill.application("<%= app %>", :foreground => false, :log_file => "/var/log/
process.working_dir = "<%= engine.directory %>"
process.daemonize = true
process.environment = {"PORT" => "<%= port %>"}
process.environment = {"PORT" => "<%= port %>"<% engine.environment.each_pair do |var,env| %> , "<%= var.upcase %>" => "<%= env %>" <% end %>}
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
process.stop_grace_time = 45.seconds
process.stdout = process.stderr = "<%= log_root %>/<%= app %>-<%= process.name %>-<%=num%>.log"

View File

@@ -0,0 +1,22 @@
<?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}-#{process.name}-#{num}" %></string>
<key>ProgramArguments</key>
<array>
<string><%= process.command %></string>
</array>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string><%= log_root %>/<%= app %>-<%= process.name %>-<%=num%>.log</string>
<key>UserName</key>
<string><%= user %></string>
<key>WorkingDirectory</key>
<string><%= engine.directory %></string>
</dict>
</plist>

View File

@@ -2,4 +2,4 @@ start on starting <%= app %>-<%= process.name %>
stop on stopping <%= app %>-<%= process.name %>
respawn
exec su - <%= user %> -c 'cd <%= engine.directory %>; export PORT=<%= port %>;<% engine.environment.each_pair do |var,env| %> export <%= var.upcase %>=<%= env %>; <% end %> <%= process.command %> >> <%= log_root %>/<%=process.name%>-<%=num%>.log 2>&1'
exec su - <%= user %> -c 'cd <%= engine.directory %>; export PORT=<%= port %>;<% engine.environment.each_pair do |var,env| %> export <%= var.upcase %>=<%= shell_quote(env) %>; <% end %> <%= process.command %> >> <%= log_root %>/<%=process.name%>-<%=num%>.log 2>&1'

View File

@@ -2,6 +2,7 @@ require "foreman"
require "foreman/helpers"
require "foreman/engine"
require "foreman/export"
require "shellwords"
require "thor"
require "yaml"
@@ -59,12 +60,12 @@ class Foreman::CLI < Thor
puts "valid procfile detected (#{engine.procfile.process_names.join(', ')})"
end
desc "run COMMAND", "Run a command using your application's environment"
desc "run COMMAND [ARGS...]", "Run a command using your application's environment"
def run(*args)
engine.apply_environment!
begin
exec args.join(" ")
exec args.shelljoin
rescue Errno::EACCES
error "not executable: #{args.first}"
rescue Errno::ENOENT

View File

@@ -21,7 +21,7 @@ class Foreman::Engine
Foreman::Color.enable($stdout)
def initialize(procfile, options={})
@procfile = Foreman::Procfile.new(procfile)
@procfile = Foreman::Procfile.new(procfile) if File.exists?(procfile)
@directory = options[:app_root] || File.expand_path(File.dirname(procfile))
@options = options.dup
@output_mutex = Mutex.new
@@ -36,6 +36,7 @@ class Foreman::Engine
trap("TERM") { puts "SIGTERM received"; terminate_gracefully }
trap("INT") { puts "SIGINT received"; terminate_gracefully }
trap("HUP") { puts "SIGHUP received"; terminate_gracefully }
assign_colors
spawn_processes
@@ -84,7 +85,7 @@ private ######################################################################
end
def base_port
options[:port] || 5000
options[:port] || environment["PORT"] || ENV["PORT"] || 5000
end
def kill_all(signal="SIGTERM")

View File

@@ -31,4 +31,5 @@ require "foreman/export/upstart"
require "foreman/export/bluepill"
require "foreman/export/runit"
require "foreman/export/supervisord"
require "foreman/export/launchd"

View File

@@ -48,4 +48,19 @@ private ######################################################################
end
end
# Quote a string to be used on the command line. Backslashes are escapde to \\ and quotes
# escaped to \"
#
# str - string to be quoted
#
# Examples
#
# shell_quote("FB|123\"\\1")
# # => "\"FB|123\"\\"\\\\1\""
#
# Returns the the escaped string surrounded by quotes
def shell_quote(str)
"\"#{str.gsub(/\\/){ '\\\\' }.gsub(/["]/){ "\\\"" }}\""
end
end

View File

@@ -0,0 +1,27 @@
require "erb"
require "foreman/export"
class Foreman::Export::Launchd < Foreman::Export::Base
def export
error("Must specify a location") unless location
app = self.app || File.basename(engine.directory)
user = self.user || app
log_root = self.log || "/var/log/#{app}"
template_root = self.template
FileUtils.mkdir_p(location)
engine.procfile.entries.each do |process|
1.upto(self.concurrency[process.name]) do |num|
master_template = export_template("launchd", "launchd.plist.erb", template_root)
master_config = ERB.new(master_template).result(binding)
write_file "#{location}/#{app}-#{process.name}-#{num}.plist", master_config
end
end
end
end

View File

@@ -62,7 +62,7 @@ private
$stdout.reopen writer
$stderr.reopen writer
reader.close
exec Foreman.runner, "-d", basedir, command
exec Foreman.runner, "-d", basedir, *command.shellsplit
end
end
[ reader, pid ]

View File

@@ -13,8 +13,9 @@ class Foreman::Procfile
attr_reader :entries
def initialize(filename)
@entries = parse_procfile(filename)
def initialize(filename=nil)
@entries = []
load(filename) if filename
end
def [](name)
@@ -25,12 +26,31 @@ class Foreman::Procfile
entries.map(&:name)
end
private
def load(filename)
entries.clear
parse_procfile(filename)
end
def write(filename)
File.open(filename, 'w') do |io|
entries.each do |ent|
io.puts(ent)
end
end
end
def <<(entry)
entries << Foreman::ProcfileEntry.new(*entry)
self
end
protected
def parse_procfile(filename)
File.read(filename).split("\n").map do |line|
if line =~ /^([A-Za-z0-9_]+):\s*(.+)$/
Foreman::ProcfileEntry.new($1, $2)
self << [ $1, $2 ]
end
end.compact
end

View File

@@ -19,4 +19,8 @@ class Foreman::ProcfileEntry
end
end
def to_s
"#{name}: #{command}"
end
end

View File

@@ -1,5 +1,5 @@
module Foreman
VERSION = "0.45.0"
VERSION = "0.47.0"
end

View File

@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "FOREMAN" "1" "April 2012" "Foreman 0.44.0" "Foreman Manual"
.TH "FOREMAN" "1" "April 2012" "Foreman 0.46.0" "Foreman Manual"
.
.SH "NAME"
\fBforeman\fR \- manage Procfile\-based applications

View File

@@ -144,7 +144,7 @@ describe "Foreman::CLI", :fakefs do
before { write_procfile }
describe "and a command" do
let(:command) { ["ls", "-l"] }
let(:command) { ["ls", "-l", "foo bar"] }
before(:each) do
stub(subject).exec
@@ -160,8 +160,8 @@ describe "Foreman::CLI", :fakefs do
ENV["FOO"].should be_nil
end
it "should runute the command as a string" do
mock(subject).exec(command.join(" "))
it "should exec the argument list as a shell command" do
mock(subject).exec(command.shelljoin)
subject.run *command
end
end

View File

@@ -12,12 +12,6 @@ describe "Foreman::Engine", :fakefs do
end
describe "initialize" do
describe "without an existing Procfile" do
it "raises an error" do
lambda { subject }.should raise_error
end
end
describe "with a Procfile" do
before { write_procfile }
@@ -106,6 +100,13 @@ describe "Foreman::Engine", :fakefs do
engine.start
end
it "should set port from .env if specified" do
File.open(".env", "w") { |f| f.puts("PORT=8017") }
engine = Foreman::Engine.new("Procfile")
engine.send(:base_port).should == "8017"
engine.start
end
it "should be loaded relative to the Procfile" do
FileUtils.mkdir_p "/some/app"
File.open("/some/app/.env", "w") { |f| f.puts("FOO=qoo") }

View File

@@ -0,0 +1,24 @@
require "spec_helper"
require "foreman/engine"
require "foreman/export/launchd"
require "tmpdir"
describe Foreman::Export::Launchd, :fakefs do
let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
let(:engine) { Foreman::Engine.new(procfile) }
let(:options) { Hash.new }
let(:launchd) { Foreman::Export::Launchd.new("/tmp/init", engine, options) }
before(:each) { load_export_templates_into_fakefs("launchd") }
before(:each) { stub(launchd).say }
it "exports to the filesystem" do
launchd.export
normalize_space(File.read("/tmp/init/app-alpha-1.plist")).should == normalize_space(example_export_file("launchd/launchd-a.default"))
normalize_space(File.read("/tmp/init/app-bravo-1.plist")).should == normalize_space(example_export_file("launchd/launchd-b.default"))
end
end

View File

@@ -33,6 +33,12 @@ describe Foreman::Export::Upstart, :fakefs do
upstart.export
end
it "quotes and escapes environment variables" do
engine.environment['KEY'] = 'd"\|d'
upstart.export
File.read("/tmp/init/app-alpha-1.conf").should include('KEY="d\"\\\\|d"')
end
context "with concurrency" do
let(:options) { Hash[:concurrency => "alpha=2"] }

View File

@@ -121,11 +121,25 @@ describe Foreman::Process do
output.should include('777')
end
it 'should handle arguments' do
pending
it 'should handle multi-word arguments (old test)' do
# TODO: This test used to be marked pending; it now passes,
# but is very slow. The next test is a fast replacement.
run %{ sh -c "trap '' TERM; sleep 10" }
subject.should be_alive
end
it 'should handle multi-word arguments' do
# We have to be a little clever here since Foreman will always
# print a status message that includes the command.
run %{ sh -c 'echo abcdef | tr a-c x | tr d-f y' }
output.should include('xxxyyy')
end
it 'should not clobber "$x"-subexpressions' do
pending 'this conflicts with the variable interpolation hack'
run %{ sh -c 'echo \$abcdef | tr \$ %' }
output.should include('%abcdef')
end
end
end
end

View File

@@ -0,0 +1,13 @@
require 'spec_helper'
require 'foreman/procfile_entry'
require 'pathname'
require 'tmpdir'
describe Foreman::ProcfileEntry do
subject { described_class.new('alpha', './alpha') }
it "stringifies as a Procfile line" do
subject.to_s.should == 'alpha: ./alpha'
end
end

View File

@@ -0,0 +1,31 @@
require 'spec_helper'
require 'foreman/procfile'
require 'pathname'
require 'tmpdir'
describe Foreman::Procfile do
subject { described_class.new }
let(:testdir) { Pathname(Dir.tmpdir) }
let(:procfile) { testdir + 'Procfile' }
it "can have a process appended to it" do
subject << ['alpha', './alpha']
subject['alpha'].should be_a(Foreman::ProcfileEntry)
end
it "can write itself out to a file" do
subject << ['alpha', './alpha']
subject.write(procfile)
procfile.read.should == "alpha: ./alpha\n"
end
it "can re-read entries from a file" do
procfile.open('w') { |io| io.puts "gamma: ./radiation", "theta: ./rate" }
subject << ['alpha', './alpha']
subject.load(procfile)
subject.process_names.should have(2).members
subject.process_names.should include('gamma', 'theta')
end
end

View File

@@ -13,6 +13,7 @@ Bluepill.application("app", :foreground => false, :log_file => "/var/log/bluepil
process.daemonize = true
process.environment = {"PORT" => "5000"}
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
process.stop_grace_time = 45.seconds
process.stdout = process.stderr = "/var/log/app/app-alpha-1.log"
@@ -31,6 +32,7 @@ Bluepill.application("app", :foreground => false, :log_file => "/var/log/bluepil
process.daemonize = true
process.environment = {"PORT" => "5001"}
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
process.stop_grace_time = 45.seconds
process.stdout = process.stderr = "/var/log/app/app-alpha-2.log"

View File

@@ -13,6 +13,7 @@ Bluepill.application("app", :foreground => false, :log_file => "/var/log/bluepil
process.daemonize = true
process.environment = {"PORT" => "5000"}
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
process.stop_grace_time = 45.seconds
process.stdout = process.stderr = "/var/log/app/app-alpha-1.log"
@@ -30,6 +31,7 @@ Bluepill.application("app", :foreground => false, :log_file => "/var/log/bluepil
process.daemonize = true
process.environment = {"PORT" => "5100"}
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
process.stop_grace_time = 45.seconds
process.stdout = process.stderr = "/var/log/app/app-bravo-1.log"

View File

@@ -0,0 +1,22 @@
<?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>ProgramArguments</key>
<array>
<string>./alpha</string>
</array>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<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>

View File

@@ -0,0 +1,22 @@
<?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-bravo-1</string>
<key>ProgramArguments</key>
<array>
<string>./bravo</string>
</array>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/var/log/app/app-bravo-1.log</string>
<key>UserName</key>
<string>app</string>
<key>WorkingDirectory</key>
<string>/tmp/app</string>
</dict>
</plist>