Compare commits

...

113 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
David Dollar
047f1ff5c4 0.45.0 2012-04-26 17:49:35 -04:00
David Dollar
26b54a62c5 Merge pull request #188 from technomancy/upstart-log-dir
Create and chown log dir in upstart export.
2012-04-24 17:50:42 -07:00
Phil Hagelberg
7b85ad7c1a Create and chown log dir in upstart export. 2012-04-24 17:24:53 -07: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
David Dollar
f46408e8be remove parka from dist files 2012-04-23 16:00:27 -04:00
David Dollar
93f04e42ac update docs 2012-04-23 15:57:06 -04:00
David Dollar
97c4582acc changelog 2012-04-23 15:57:00 -04:00
David Dollar
5689d75a87 0.44.0 2012-04-23 15:55:56 -04:00
David Dollar
1325b6750e make var output order repeatable 2012-04-23 15:53:59 -04:00
David Dollar
638005403f clean up file/directory interaction, add some tests 2012-04-23 15:50:23 -04:00
David Dollar
55f274532f Merge pull request #183 from technomancy/app_root
Look for .env and app_root in the same dir as the Procfile.
2012-04-23 12:20:10 -07:00
Phil Hagelberg
66f76c2036 Look for .env and app_root in the same dir as the Procfile. 2012-04-20 20:59:37 -07:00
David Dollar
865cabb525 update docs 2012-04-20 19:33:14 -04:00
David Dollar
7c3c4bc58f add more options to the start docs 2012-04-20 19:33:11 -04:00
David Dollar
2dbe8c733b update docs 2012-04-20 17:42:47 -04:00
David Dollar
84352b82cc changelog 2012-04-20 17:42:33 -04:00
David Dollar
383c1f87af 0.43.0 2012-04-20 17:41:08 -04:00
David Dollar
ce3003b026 factor out wrap_environment 2012-04-20 17:40:53 -04:00
David Dollar
e06f4b2f9e Merge pull request #182 from leahpar/master
Supervisord Export fix for environments containing commas
2012-04-20 14:36:26 -07:00
Raphael Randschau
b721fd894e per default wrap every environment value in quotes 2012-04-20 21:15:43 +02:00
Raphael Randschau
b8ea6fd4b3 fix typo in spec description 2012-04-20 09:14:12 +02:00
Raphael Randschau
dbda63263b fix supervisord export for environments containing commas 2012-04-20 09:11:25 +02:00
David Dollar
93cdc31be0 update docs 2012-04-18 13:04:45 -04:00
David Dollar
4dfbe46690 update changelog 2012-04-18 13:03:58 -04:00
David Dollar
0033f9caeb 0.42.0 2012-04-18 13:02:51 -04:00
David Dollar
74839800a9 Merge pull request #181 from technomancy/master
Public read_environment
2012-04-18 10:01:38 -07:00
Phil Hagelberg
b75337e21e Move read_environment to a public class method. 2012-04-18 09:56:17 -07:00
David Dollar
d94f941189 update gemfile.lock 2012-04-18 12:49:33 -04:00
David Dollar
0b34f067cb Revert "Merge pull request #176 from rtyler/feature/156-foreman-stop-command"
Rewriting using a better Process API

This reverts commit dbe51832b0, reversing
changes made to 69216b4c5e.
2012-04-18 12:48:51 -04:00
David Dollar
dbe51832b0 Merge pull request #176 from rtyler/feature/156-foreman-stop-command
Adding #stop method to Foreman::Engine
2012-04-11 10:29:54 -07:00
R. Tyler Croy
3a2a53be95 Remove ALL_PROCESSES and default the name arguments to #start/#stop to nil 2012-04-11 10:25:58 -07:00
R. Tyler Croy
b2bf95479e Refactor #stop to reference ALL_PROCESSES for a bit clearer readability 2012-04-10 20:35:59 -07:00
R. Tyler Croy
48f764e347 Refactor #spawn_processes into #start(name)
When passed nil (aka ALL_PROCESSES) #start will start all processes in the
Procfile as per existing behavior
2012-04-10 20:35:59 -07:00
R. Tyler Croy
de62d0655e Re-name the main Foreman::Engine method to #run to avoid a name collision with #start(name) 2012-04-10 20:35:59 -07:00
R. Tyler Croy
38aecff886 When executing #stop(nil), all processes should be sent the signal 2012-04-10 20:35:58 -07:00
R. Tyler Croy
e4a3215257 Re-implement #terminate_gracefully with #stop(name) 2012-04-10 20:19:23 -07:00
R. Tyler Croy
c705b5fbef Add #stop method on Foreman::Engine for stopping certain named processes
This will make embedding foreman "nicer" since the embedder can then stop
a specific process (e.g. turning off a service for an integration fail-over test)
2012-04-10 20:10:51 -07:00
Matt Griffin
2fcb64959b Quote and escape environment variables in upstart templates 2012-04-03 16:36:18 -04:00
David Dollar
69216b4c5e Merge pull request #171 from technomancy/0.41.0-deparkaed
Drop parka dependency to make things easier on the build slaves.
2012-03-26 15:05:35 -07:00
Phil Hagelberg
5d2930745a Drop parka dependency to make things easier on the build slaves. 2012-03-26 15:01:04 -07:00
elf Pavlik
a5465bf55e added list of ports to other languages to README 2012-03-18 09:35:51 +01:00
David Dollar
8fc3d1ef24 Merge pull request #161 from leahpar/master
Supervisord Support (Update & Bugfix)
2012-03-16 18:47:15 -07:00
David Dollar
d33e4fb0ed update changelog 2012-03-16 16:36:16 -04:00
David Dollar
39b48b566f 0.41.0 2012-03-16 16:34:32 -04:00
David Dollar
2f982ff9c7 replace term-ansicolor with built-in colorization 2012-03-16 16:34:14 -04:00
Raphael Randschau
1217ef1b56 fix typo 2012-03-05 15:51:10 +01:00
Raphael Randschau
c9943d70ec add group support for supervisord 2012-03-05 15:48:40 +01:00
Raphael Randschau
08dca57eb4 fix enviroment export 2012-02-25 17:24:27 +01:00
David Dollar
bb3377407a Merge pull request #160 from leahpar/master
supervisord support
2012-02-24 11:49:55 -08:00
Raphael Randschau
084b9493d1 revert bundle update 2012-02-24 20:31:07 +01:00
Raphael Randschau
279a251c78 fix whitespaces 2012-02-24 20:29:16 +01:00
Raphael Randschau
a49ef286e8 all specs are passing 2012-02-24 20:18:38 +01:00
Raphael Randschau
0b3da59947 passing first export 2012-02-24 19:52:18 +01:00
David Dollar
1f725dd68a let github show authors 2012-02-24 11:34:34 -05:00
David Dollar
2272f76479 authors 2012-02-24 11:33:33 -05:00
David Dollar
cf4762071c changelog 2012-02-24 11:33:18 -05:00
David Dollar
d86b0bed1f 0.40.0 2012-02-24 11:32:00 -05:00
David Dollar
12f825204b support various quoting styles in .env 2012-02-24 11:31:21 -05:00
David Dollar
62c9d1db45 remove load_env! as it's made unnecessary by foreman run 2012-02-24 11:31:21 -05:00
Raphael Randschau
1127551369 rename supervisord base template to app
add supervisord stub
2012-02-23 17:24:08 +01:00
Raphael Randschau
8cb58b8517 require supervisord export 2012-02-23 17:11:19 +01:00
Raphael Randschau
d03e931b67 add supervisord export engine 2012-02-23 17:10:57 +01:00
Raphael Randschau
9ba2b32b36 add supervisord base template 2012-02-23 17:02:59 +01:00
David Dollar
cf5689a77a Merge pull request #155 from rtyler/bug/152-check-exception-no-procfile
Provide a useful error if `foreman check` fails to find a Procfile
2012-02-21 17:40:20 -08:00
R. Tyler Croy
c23dbb79af Provide a useful error if foreman check fails to find a Procfile
Fixes #152
2012-02-21 17:27:15 -08:00
David Dollar
7e55d8d3e2 update docs 2012-02-21 11:58:57 -05:00
David Dollar
d4f23d45a4 add run to docs 2012-02-21 11:58:52 -05:00
David Dollar
93fa1645e7 update docs 2012-02-21 11:50:11 -05:00
David Dollar
7bdada4a10 update docs 2012-02-21 11:49:57 -05:00
David Dollar
2b47d24ab7 Travis doesn't support cext. Revert "try java again"
This reverts commit 24695348fb.
2012-02-09 19:16:14 -05:00
David Dollar
24695348fb try java again 2012-02-09 19:12:11 -05:00
David Dollar
38b6482af5 changelog 2012-02-07 11:19:12 -05:00
David Dollar
501bc138c5 authors 2012-02-07 11:18:06 -05:00
David Dollar
df8c05cd6c 0.39.0 2012-02-07 11:17:59 -05:00
David Dollar
edcc4f3567 move to foreman-runner 2012-02-07 11:17:44 -05:00
David Dollar
3759dbb463 fix tgz release 2012-02-07 11:16:07 -05:00
David Dollar
b673931c05 Double Revert "Revert "bundle update hpricot""
This reverts commit 137e43b040.
2012-02-04 19:47:48 -05:00
David Dollar
137e43b040 Revert "bundle update hpricot"
This reverts commit 16d4b84a5d.
2012-02-04 19:25:01 -05:00
David Dollar
79211d9bbf Merge pull request #147 from jfirebaugh/rubinius
bundle update hpricot
2012-02-04 14:05:06 -08:00
John Firebaugh
16d4b84a5d bundle update hpricot
0.8.2 doesn't compile on Rubinius; 0.8.6 does.
2012-02-04 13:46:48 -08:00
David Dollar
5ea4537046 remove version from inner pkg 2012-02-02 21:31:58 -05:00
David Dollar
d51433ff82 fix foreman pkg builder 2012-02-02 21:08:01 -05:00
David Dollar
54ab74d305 fix release tasks 2012-02-02 17:32:52 -05:00
David Dollar
e8b8f34f41 changelog 2012-02-02 17:27:56 -05:00
52 changed files with 794 additions and 169 deletions

View File

@@ -1,3 +1,56 @@
## 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]
* make --procfile and --app-root influence each other in a more intuitive way [David Dollar]
* Look for .env and app_root in the same dir as the Procfile. [Phil Hagelberg]
## 0.43.0 (2012-04-20)
* wrap supervisord env vars in quotes [Raphael Randschau]
## 0.42.0 (2012-04-18)
* Move read_environment to a public class method. [Phil Hagelberg]
* Drop parka dependency [Phil Hagelberg]
* add group support for supervisord [Raphael Randschau]
* fix enviroment export [Raphael Randschau]
## 0.41.0 (2012-03-16)
* replace term-ansicolor with built-in colorization [David Dollar]
* supervisord export template [Raphael Randschau]
## 0.40.0 (2012-02-24)
* support various quoting styles in .env [David Dollar]
* remove load_env! as it's made unnecessary by foreman run [David Dollar]
* Provide a useful error if `foreman check` fails to find a Procfile [R. Tyler Croy]
* update docs [David Dollar]
## 0.39.0 (2012-02-07)
* rename bin/runner to bin/foreman-runner [David Dollar]
* fix tgz release [David Dollar]
* bundle update hpricot [John Firebaugh]
* touch up .pkg release tasks [David Dollar]
## 0.38.0 (2012-02-02)
* bring back single process starting [David Dollar]
* more attempts at getting ci working with jruby [David Dollar]
* ignore .rbenv-version [David Dollar]
* force to binary encoding if supported [David Dollar]
## 0.37.2 (2012-01-29)
* handle directories with spaces in runner [David Dollar]

View File

@@ -11,7 +11,7 @@ platform :jruby do
end
group :development do
gem 'parka'
gem 'aws-s3'
gem 'rake'
gem 'ronn'
gem 'fakefs', '~> 0.3.2'

View File

@@ -1,30 +1,27 @@
PATH
remote: .
specs:
foreman (0.38.0)
term-ansicolor (~> 1.0.7)
foreman (0.47.0)
thor (>= 0.13.6)
GEM
remote: http://rubygems.org/
specs:
crack (0.1.8)
aws-s3 (0.6.2)
builder
mime-types
xml-simple
builder (3.0.0)
diff-lcs (1.1.3)
fakefs (0.3.2)
hpricot (0.8.2)
hpricot (0.8.2-java)
hpricot (0.8.6)
hpricot (0.8.6-java)
mime-types (1.16)
multi_json (1.0.4)
mustache (0.11.2)
parka (0.6.2)
crack
rest-client
thor
posix-spawn (0.3.6)
rake (0.9.2.2)
rdiscount (1.6.5)
rest-client (1.6.1)
mime-types (>= 1.16)
ronn (0.7.3)
hpricot (>= 0.8.2)
mustache (>= 0.7.0)
@@ -42,9 +39,9 @@ GEM
multi_json (~> 1.0.3)
simplecov-html (~> 0.5.3)
simplecov-html (0.5.3)
term-ansicolor (1.0.7)
thor (0.14.6)
win32console (1.3.0-x86-mingw32)
xml-simple (1.0.15)
PLATFORMS
java
@@ -52,9 +49,9 @@ PLATFORMS
x86-mingw32
DEPENDENCIES
aws-s3
fakefs (~> 0.3.2)
foreman!
parka
posix-spawn (~> 0.3.6)
rake
ronn

View File

@@ -27,13 +27,19 @@ 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
David Dollar
#### Patches contributed by
Adam Wiggins, Chris Continanza, Chris Lowder, Craig R Webster, Dan Farina, Dan Peterson, David Dollar, Fletcher Nichol, Florian Apolloner, Gabriel Burt, Gamaliel Toro, Greg Reinacker, Hugues Le Gendre, Hunter Nield, Iain Hecker, Jay Zeschin, Keith Rarick, Khaja Minhajuddin, Lincoln Stoll, Marcos Muino Garcia, Mark McGranaghan, Matt Griffin, Matt Haynes, Matthijs Langenberg, Michael Dwan, Michael van Rooijen, Mike Javorski, Nathan Broadbent, Nathan L Smith, Nick Zadrozny, Phil Hagelberg, Ricardo Chimal, Jr, Thom May, Tom Ward, brainopia, clifff, jc00ke
[Contributor List](https://github.com/ddollar/foreman/contributors)
## License

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
#/ Usage: 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

@@ -0,0 +1,27 @@
<%
app_names = []
engine.procfile.entries.each do |process|
next if (conc = self.concurrency[process.name]) < 1
1.upto(self.concurrency[process.name]) do |num|
port = engine.port_for(process, num, self.port)
name = if (conc > 1); "#{process.name}-#{num}" else process.name; end
environment = (engine.environment.keys.sort.map{ |var| %{#{var.upcase}="#{engine.environment[var]}"} } + [%{PORT="#{port}"}])
app_name = "#{app}-#{name}"
app_names << app_name
%>
[program:<%= app_name %>]
command=<%= process.command %>
autostart=true
autorestart=true
stopsignal=QUIT
stdout_logfile=<%= log_root %>/<%=process.name%>-<%=num%>-out.log
stderr_logfile=<%= log_root %>/<%=process.name%>-<%=num%>-err.log
user=<%= user %>
directory=<%= engine.directory %>
environment=<%= environment.join(',') %><%
end
end
%>
[group:<%= app %>]
programs=<%= app_names.join(',') %>

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'

2
dist/deb.rake vendored
View File

@@ -4,7 +4,7 @@ file pkg("/apt-#{version}/foreman-#{version}.deb") => distribution_files("deb")
assemble_distribution
assemble_gems
assemble resource("deb/foreman"), "bin/foreman", 0755
File.chmod 0755, "bin/runner"
File.chmod 0755, "bin/foreman-runner"
end
assemble resource("deb/control"), "control"

2
dist/gem.rake vendored
View File

@@ -10,5 +10,5 @@ task "gem:clean" do
end
task "gem:release" => "gem:build" do |t|
sh "parka push -f #{pkg("foreman-#{version}.gem")}"
sh "gem push #{pkg("foreman-#{version}.gem")} || echo 'error'"
end

6
dist/jruby.rake vendored
View File

@@ -1,5 +1,7 @@
file pkg("foreman-#{version}-jruby.gem") => distribution_files do |t|
sh "env PLATFORM=java gem build foreman.gemspec"
Bundler.with_clean_env do
sh "env PLATFORM=java gem build foreman.gemspec"
end
sh "mv foreman-#{version}-java.gem #{t.name}"
end
@@ -10,5 +12,5 @@ task "jruby:clean" do
end
task "jruby:release" => "jruby:build" do |t|
sh "parka push -f #{pkg("foreman-#{version}-jruby.gem")}"
sh "gem push #{pkg("foreman-#{version}-jruby.gem")} || echo 'error'"
end

6
dist/mingw32.rake vendored
View File

@@ -1,5 +1,7 @@
file pkg("foreman-#{version}-mingw32.gem") => distribution_files do |t|
sh "env PLATFORM=mingw32 gem build foreman.gemspec"
Bundler.with_clean_env do
sh "env PLATFORM=mingw32 gem build foreman.gemspec"
end
sh "mv foreman-#{version}-mingw32.gem #{t.name}"
end
@@ -10,5 +12,5 @@ task "mingw32:clean" do
end
task "mingw32:release" => "mingw32:build" do |t|
sh "parka push -f #{pkg("foreman-#{version}-mingw32.gem")}"
sh "gem push #{pkg("foreman-#{version}-mingw32.gem")} || echo 'error'"
end

15
dist/pkg.rake vendored
View File

@@ -13,7 +13,7 @@ file pkg("foreman-#{version}.pkg") => distribution_files do |t|
mkdir_p "pkg"
mkdir_p "pkg/Resources"
mkdir_p "pkg/foreman-#{version}.pkg"
mkdir_p "pkg/foreman.pkg"
dist = File.read(resource("pkg/Distribution.erb"))
dist = ERB.new(dist).result(binding)
@@ -21,20 +21,21 @@ file pkg("foreman-#{version}.pkg") => distribution_files do |t|
dist = File.read(resource("pkg/PackageInfo.erb"))
dist = ERB.new(dist).result(binding)
File.open("pkg/foreman-#{version}.pkg/PackageInfo", "w") { |f| f.puts dist }
File.open("pkg/foreman.pkg/PackageInfo", "w") { |f| f.puts dist }
mkdir_p "pkg/foreman-#{version}.pkg/Scripts"
cp resource("pkg/postinstall"), "pkg/foreman-#{version}.pkg/Scripts/postinstall"
chmod 0755, "pkg/foreman-#{version}.pkg/Scripts/postinstall"
mkdir_p "pkg/foreman.pkg/Scripts"
cp resource("pkg/postinstall"), "pkg/foreman.pkg/Scripts/postinstall"
chmod 0755, "pkg/foreman.pkg/Scripts/postinstall"
sh %{ mkbom -s foreman pkg/foreman-#{version}.pkg/Bom }
sh %{ mkbom -s foreman pkg/foreman.pkg/Bom }
Dir.chdir("foreman") do
sh %{ pax -wz -x cpio . > ../pkg/foreman-#{version}.pkg/Payload }
sh %{ pax -wz -x cpio . > ../pkg/foreman.pkg/Payload }
end
sh %{ pkgutil --flatten pkg foreman-#{version}.pkg }
FileUtils.mkdir_p(File.dirname(t.name))
cp_r "foreman-#{version}.pkg", t.name
end
end

View File

@@ -10,14 +10,14 @@
]]></script>
<choices-outline>
<line choice="git"/>
<line choice="foreman-<%= version %>"/>
<line choice="foreman"/>
</choices-outline>
<choice id="git" title="git" start_selected="false" start_enabled="false" selected="needs_git()" enabled="needs_git()">
<pkg-ref id="git.pkg" />
</choice>
<choice id="foreman-<%= version %>" title="foreman">
<choice id="foreman" title="foreman">
<pkg-ref id="io.foreman.installer"/>
</choice>
<pkg-ref id="io.foreman.installer" installKBytes="<%= kbytes %>" version="<%= version %>" auth="Root">#foreman-<%= version %>.pkg</pkg-ref>
<pkg-ref id="io.foreman.installer" installKBytes="<%= kbytes %>" version="<%= version %>" auth="Root">#foreman.pkg</pkg-ref>
</installer-script>

View File

@@ -4,4 +4,3 @@
<postinstall file="./postinstall"/>
</scripts>
</pkg-info>

2
dist/tgz.rake vendored
View File

@@ -3,7 +3,7 @@ file pkg("foreman-#{version}.tgz") => distribution_files do |t|
mkchdir("foreman") do
assemble_distribution
assemble_gems
rm_rf "bin"
rm_f "bin/foreman"
assemble resource("tgz/foreman"), "foreman", 0755
end

View File

@@ -16,8 +16,7 @@ Gem::Specification.new do |gem|
gem.files = Dir["**/*"].select { |d| d =~ %r{^(README|bin/|data/|ext/|lib/|spec/|test/)} }
gem.files << "man/foreman.1"
gem.add_dependency 'term-ansicolor', '~> 1.0.7'
gem.add_dependency 'thor', '>= 0.13.6'
gem.add_dependency 'thor', '>= 0.13.6'
if ENV["PLATFORM"] == "java"
gem.add_dependency "posix-spawn", "~> 0.3.6"

View File

@@ -4,14 +4,8 @@ module Foreman
class AppDoesNotExist < Exception; end
# load contents of env_file into ENV
def self.load_env!(env_file = './.env')
require 'foreman/engine'
Foreman::Engine.load_env!(env_file)
end
def self.runner
File.expand_path("../../bin/runner", __FILE__)
File.expand_path("../../bin/foreman-runner", __FILE__)
end
def self.jruby?

View File

@@ -2,6 +2,7 @@ require "foreman"
require "foreman/helpers"
require "foreman/engine"
require "foreman/export"
require "shellwords"
require "thor"
require "yaml"
@@ -54,16 +55,17 @@ class Foreman::CLI < Thor
desc "check", "Validate your application's Procfile"
def check
check_procfile!
error "no processes defined" unless engine.procfile.entries.length > 0
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
@@ -82,7 +84,11 @@ private ######################################################################
end
def procfile
options[:procfile] || "Procfile"
case
when options[:procfile] then options[:procfile]
when options[:app_root] then File.expand_path(File.join(options[:app_root], "Procfile"))
else "Procfile"
end
end
def error(message)

40
lib/foreman/color.rb Normal file
View File

@@ -0,0 +1,40 @@
require "foreman"
module Foreman::Color
ANSI = {
:reset => 0,
:black => 30,
:red => 31,
:green => 32,
:yellow => 33,
:blue => 34,
:magenta => 35,
:cyan => 36,
:white => 37,
:bright_black => 30,
:bright_red => 31,
:bright_green => 32,
:bright_yellow => 33,
:bright_blue => 34,
:bright_magenta => 35,
:bright_cyan => 36,
:bright_white => 37,
}
def self.enable(io)
io.extend(self)
end
def color?
return false unless self.respond_to?(:isatty)
self.isatty && ENV["TERM"]
end
def color(name)
return "" unless color?
return "" unless ansi = ANSI[name.to_sym]
"\e[#{ansi}m"
end
end

View File

@@ -1,36 +1,33 @@
require "foreman"
require "foreman/color"
require "foreman/process"
require "foreman/procfile"
require "foreman/utils"
require "tempfile"
require "timeout"
require "term/ansicolor"
require "fileutils"
require "thread"
class Foreman::Engine
attr_reader :environment
attr_reader :procfile
attr_reader :directory
attr_reader :options
extend Term::ANSIColor
COLORS = %w( cyan yellow green magenta red blue intense_cyan intense_yellow
intense_green intense_magenta intense_red, intense_blue )
COLORS = [ cyan, yellow, green, magenta, red, blue,
intense_cyan, intense_yellow, intense_green, intense_magenta,
intense_red, intense_blue ]
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
@environment = read_environment_files(options[:env])
@output_mutex = Mutex.new
end
def self.load_env!(env_file)
@environment = read_environment_files(env_file)
apply_environment!
@options[:env] ||= default_env
@environment = read_environment_files(@options[:env])
end
def start
@@ -39,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
@@ -52,6 +50,26 @@ class Foreman::Engine
base_port.to_i + offset + num - 1
end
def apply_environment!
environment.each { |k,v| ENV[k] = v }
end
def self.read_environment(filename)
return {} unless File.exists?(filename)
File.read(filename).split("\n").inject({}) do |hash, line|
if line =~ /\A([A-Za-z_0-9]+)=(.*)\z/
key, val = [$1, $2]
case val
when /\A'(.*)'\z/ then hash[key] = $1
when /\A"(.*)"\z/ then hash[key] = $1.gsub(/\\(.)/, '\1')
else hash[key] = val
end
end
hash
end
end
private ######################################################################
def spawn_processes
@@ -67,7 +85,7 @@ private ######################################################################
end
def base_port
options[:port] || 5000
options[:port] || environment["PORT"] || ENV["PORT"] || 5000
end
def kill_all(signal="SIGTERM")
@@ -128,11 +146,11 @@ private ######################################################################
rescue Errno::ECHILD
end
def info(message, name="system", color=Term::ANSIColor.white)
def info(message, name="system", color=:white)
output = ""
output += color
output += $stdout.color(color)
output += "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(name)} | "
output += Term::ANSIColor.reset
output += $stdout.color(:reset)
output += message.chomp
puts output
end
@@ -182,8 +200,8 @@ private ######################################################################
end
def assign_colors
procfile.entries.each do |entry|
colors[entry.name] = next_color
procfile.entries.each_with_index do |entry, idx|
colors[entry.name] = COLORS[idx % COLORS.length]
end
end
@@ -191,49 +209,20 @@ private ######################################################################
readers.invert[reader]
end
def next_color
@current_color ||= -1
@current_color += 1
@current_color = 0 if COLORS.length < @current_color
COLORS[@current_color]
def read_environment_files(filenames)
environment = {}
(filenames || "").split(",").map(&:strip).each do |filename|
error "No such file: #{filename}" unless File.exists?(filename)
environment.merge!(Foreman::Engine.read_environment(filename))
end
environment
end
module Env
attr_reader :environment
def read_environment_files(filenames)
environment = {}
(filenames || "").split(",").map(&:strip).each do |filename|
error "No such file: #{filename}" unless File.exists?(filename)
environment.merge!(read_environment(filename))
end
environment.merge!(read_environment(".env")) unless filenames
environment
end
def read_environment(filename)
return {} unless File.exists?(filename)
File.read(filename).split("\n").inject({}) do |hash, line|
if line =~ /\A([A-Za-z_0-9]+)=(.*)\z/
hash[$1] = $2
end
hash
end
end
def apply_environment!
@environment.each { |k,v| ENV[k] = v }
end
def error(message)
puts "ERROR: #{message}"
exit 1
end
def default_env
env = File.join(directory, ".env")
File.exists?(env) ? env : ""
end
include Env
extend Env
end

View File

@@ -30,3 +30,6 @@ require "foreman/export/inittab"
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

@@ -0,0 +1,26 @@
require "erb"
require "foreman/export"
class Foreman::Export::Supervisord < Foreman::Export::Base
def export
error("Must specify a location") unless location
FileUtils.mkdir_p location
app = self.app || File.basename(engine.directory)
user = self.user || app
log_root = self.log || "/var/log/#{app}"
template_root = self.template
Dir["#{location}/#{app}*.conf"].each do |file|
say "cleaning up: #{file}"
FileUtils.rm(file)
end
app_template = export_template("supervisord", "app.conf.erb", template_root)
app_config = ERB.new(app_template, 0, '<').result(binding)
write_file "#{location}/#{app}.conf", app_config
end
end

View File

@@ -36,6 +36,8 @@ class Foreman::Export::Upstart < Foreman::Export::Base
write_file "#{location}/#{app}-#{process.name}-#{num}.conf", process_config
end
end
end
FileUtils.mkdir_p(log_root) rescue error "could not create #{log_root}"
FileUtils.chown(user, nil, log_root) rescue error "could not chown #{log_root} to #{user}"
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.38.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" "January 2012" "Foreman 0.37.2" "Foreman Manual"
.TH "FOREMAN" "1" "April 2012" "Foreman 0.46.0" "Foreman Manual"
.
.SH "NAME"
\fBforeman\fR \- manage Procfile\-based applications
@@ -10,10 +10,13 @@
\fBforeman start [process]\fR
.
.br
\fBforeman run <command>\fR
.
.br
\fBforeman export <format> [location]\fR
.
.SH "DESCRIPTION"
\fBForeman\fR is a manager for Procfile\-based applications\. Its aim is to abstract away the details of the Procfile format, and allow you to either run your application directly or export it to some other process management format\.
Foreman is a manager for Procfile\-based applications\. Its aim is to abstract away the details of the Procfile format, and allow you to either run your application directly or export it to some other process management format\.
.
.SH "RUNNING"
\fBforeman start\fR is used to run your application directly from the command line\.
@@ -32,9 +35,20 @@ The following options control how the application is run:
Specify the number of each process type to run\. The value passed in should be in the format \fBprocess=num,process=num\fR
.
.TP
\fB\-e\fR, \fB\-\-env\fR
Specify one or more \.env files to load
.
.TP
\fB\-f\fR, \fB\-\-procfile\fR
Specify an alternate Procfile to load, implies \fB\-d\fR at the Procfile root\.
.
.TP
\fB\-p\fR, \fB\-\-port\fR
Specify which port to use as the base for this application\. Should be a multiple of 1000\.
.
.P
\fBforeman run\fR is used to run one\-off commands using the same environment as your defined processes\.
.
.SH "EXPORTING"
\fBforeman export\fR is used to export your application to another process management format\.
.
@@ -61,10 +75,14 @@ Specify the directory to place process logs in\.
Specify which port to use as the base for this application\. Should be a multiple of 1000\.
.
.TP
\fB\-t\fR, \fB\-\-template\fR
Specify an alternate template to use for creating export files\. See \fIhttps://github\.com/ddollar/foreman/tree/master/data/export\fR for examples\.
.
.TP
\fB\-u\fR, \fB\-\-user\fR
Specify the user the application should be run as\. Defaults to the app name
.
.SH "OPTIONS"
.SH "GLOBAL OPTIONS"
These options control all modes of foreman\'s operation\.
.
.TP

View File

@@ -4,11 +4,12 @@ foreman(1) -- manage Procfile-based applications
## SYNOPSIS
`foreman start [process]`<br>
`foreman run <command>`<br>
`foreman export <format> [location]`
## DESCRIPTION
**Foreman** is a manager for Procfile-based applications. Its aim is to
Foreman is a manager for Procfile-based applications. Its aim is to
abstract away the details of the Procfile format, and allow you to either run
your application directly or export it to some other process management
format.
@@ -29,10 +30,19 @@ The following options control how the application is run:
Specify the number of each process type to run. The value passed in
should be in the format `process=num,process=num`
* `-e`, `--env`:
Specify one or more .env files to load
* `-f`, `--procfile`:
Specify an alternate Procfile to load, implies `-d` at the Procfile root.
* `-p`, `--port`:
Specify which port to use as the base for this application. Should be
a multiple of 1000.
`foreman run` is used to run one-off commands using the same environment
as your defined processes.
## EXPORTING
`foreman export` is used to export your application to another process
@@ -58,11 +68,15 @@ 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`, `--template`:
Specify an alternate template to use for creating export files.
See <https://github.com/ddollar/foreman/tree/master/data/export> for examples.
* `-u`, `--user`:
Specify the user the application should be run as. Defaults to the
app name
## OPTIONS
## GLOBAL OPTIONS
These options control all modes of foreman's operation.

View File

@@ -34,6 +34,15 @@ describe "Foreman::CLI", :fakefs do
subject.start("alpha")
end
end
describe "with an alternate root" do
it "reads the Procfile from that root" do
write_procfile "/some/app/Procfile"
mock(Foreman::Procfile).new("/some/app/Procfile")
mock.instance_of(Foreman::Engine).start
foreman %{ start -d /some/app }
end
end
end
describe "export" do
@@ -120,6 +129,14 @@ describe "Foreman::CLI", :fakefs do
end
end
end
describe "without a Procfile" do
it "displays an error" do
mock_error(subject, "Procfile does not exist.") do
subject.check
end
end
end
end
describe "run" do
@@ -127,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
@@ -143,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

@@ -0,0 +1,31 @@
require "spec_helper"
require "foreman/color"
describe Foreman::Color do
let(:io) { Object.new }
it "should extend an object with colorization" do
Foreman::Color.enable(io)
io.should respond_to(:color)
end
it "should not colorize if the object does not respond to isatty" do
mock(io).respond_to?(:isatty) { false }
Foreman::Color.enable(io)
io.color(:white).should == ""
end
it "should not colorize if the object is not a tty" do
mock(io).isatty { false }
Foreman::Color.enable(io)
io.color(:white).should == ""
end
it "should colorize if the object is a tty" do
mock(io).isatty { true }
Foreman::Color.enable(io)
io.color(:white).should == "\e[37m"
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 }
@@ -49,18 +43,28 @@ describe "Foreman::Engine", :fakefs do
end
end
describe "directories" do
it "has the directory default relative to the Procfile" do
write_procfile "/some/app/Procfile"
engine = Foreman::Engine.new("/some/app/Procfile")
engine.directory.should == "/some/app"
end
end
describe "environment" do
before(:each) do
write_procfile
stub(Process).fork
any_instance_of(Foreman::Engine) do |engine|
stub(engine).info
stub(engine).spawn_processes
stub(engine).watch_for_termination
end
end
it "should read if specified" do
File.open("/tmp/env", "w") { |f| f.puts("FOO=baz") }
engine = Foreman::Engine.new("Procfile", :env => "/tmp/env")
stub(engine).info
mock(engine).spawn_processes
mock(engine).watch_for_termination
engine.environment.should == {"FOO"=>"baz"}
engine.start
end
@@ -69,13 +73,21 @@ describe "Foreman::Engine", :fakefs do
File.open("/tmp/env1", "w") { |f| f.puts("FOO=bar") }
File.open("/tmp/env2", "w") { |f| f.puts("BAZ=qux") }
engine = Foreman::Engine.new("Procfile", :env => "/tmp/env1,/tmp/env2")
stub(engine).info
mock(engine).spawn_processes
mock(engine).watch_for_termination
engine.environment.should == { "FOO"=>"bar", "BAZ"=>"qux" }
engine.start
end
it "should handle quoted values" do
File.open("/tmp/env", "w") do |f|
f.puts 'FOO=bar'
f.puts 'BAZ="qux"'
f.puts "FRED='barney'"
f.puts 'OTHER="escaped\"quote"'
end
engine = Foreman::Engine.new("Procfile", :env => "/tmp/env")
engine.environment.should == { "FOO" => "bar", "BAZ" => "qux", "FRED" => "barney", "OTHER" => 'escaped"quote' }
end
it "should fail if specified and doesnt exist" do
mock.instance_of(Foreman::Engine).error("No such file: /tmp/env")
engine = Foreman::Engine.new("Procfile", :env => "/tmp/env")
@@ -84,8 +96,22 @@ describe "Foreman::Engine", :fakefs do
it "should read .env if none specified" do
File.open(".env", "w") { |f| f.puts("FOO=qoo") }
engine = Foreman::Engine.new("Procfile")
mock(engine).spawn_processes
mock(engine).watch_for_termination
engine.environment.should == {"FOO"=>"qoo"}
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") }
write_procfile "/some/app/Procfile"
engine = Foreman::Engine.new("/some/app/Procfile")
engine.environment.should == {"FOO"=>"qoo"}
engine.start
end

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

@@ -0,0 +1,85 @@
require "spec_helper"
require "foreman/engine"
require "foreman/export/supervisord"
require "tmpdir"
describe Foreman::Export::Supervisord, :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(:supervisord) { Foreman::Export::Supervisord.new("/tmp/init", engine, options) }
before(:each) { load_export_templates_into_fakefs("supervisord") }
before(:each) { stub(supervisord).say }
it "exports to the filesystem" do
supervisord.export
File.read("/tmp/init/app.conf").should == example_export_file("supervisord/app.conf")
end
it "cleans up if exporting into an existing dir" do
mock(FileUtils).rm("/tmp/init/app.conf")
supervisord.export
supervisord.export
end
context "with concurrency" do
let(:options) { Hash[:concurrency => "alpha=2"] }
it "exports to the filesystem with concurrency" do
supervisord.export
File.read("/tmp/init/app.conf").should == example_export_file("supervisord/app-alpha-2.conf")
end
end
context "with alternate templates" do
let(:template_root) { "/tmp/alternate" }
let(:supervisord) { Foreman::Export::Supervisord.new("/tmp/init", engine, :template => template_root) }
before do
FileUtils.mkdir_p template_root
File.open("#{template_root}/app.conf.erb", "w") { |f| f.puts "alternate_template" }
end
it "can export with alternate template files" do
supervisord.export
File.read("/tmp/init/app.conf").should == "alternate_template\n"
end
end
context "with alternate templates from home dir" do
let(:default_template_root) {File.expand_path("#{ENV['HOME']}/.foreman/templates")}
before do
ENV['_FOREMAN_SPEC_HOME'] = ENV['HOME']
ENV['HOME'] = "/home/appuser"
FileUtils.mkdir_p default_template_root
File.open("#{default_template_root}/app.conf.erb", "w") { |f| f.puts "default_alternate_template" }
end
after do
ENV['HOME'] = ENV.delete('_FOREMAN_SPEC_HOME')
end
it "can export with alternate template files" do
supervisord.export
File.read("/tmp/init/app.conf").should == "default_alternate_template\n"
end
end
context "environment export" do
it "correctly translates environment when exporting" do
File.open("/tmp/supervisord_env", "w") { |f| f.puts("QUEUE=fastqueue,slowqueue\nVERBOSE=1") }
engine = Foreman::Engine.new(procfile,:env => "/tmp/supervisord_env")
supervisor = Foreman::Export::Supervisord.new("/tmp/init", engine, options)
stub(supervisor).say
supervisor.export
File.read("/tmp/init/app.conf").should == example_export_file("supervisord/app-env-with-comma.conf")
end
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

@@ -8,24 +8,6 @@ describe Foreman do
it { should be_a String }
end
describe "::load_env!(env_file)", :fakefs do
after do
ENV['FOO'] = nil
end
it "should load env_file into ENV" do
File.open("/tmp/env1", "w") { |f| f.puts("FOO=bar") }
Foreman.load_env!("/tmp/env1")
ENV['FOO'].should == 'bar'
end
it "should assume env_file in ./.env" do
File.open("./.env", "w") { |f| f.puts("FOO=bar") }
Foreman.load_env!
ENV['FOO'].should == 'bar'
end
end
describe "runner" do
it "should exist" do
File.exists?(Foreman.runner).should == true

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>

View File

@@ -0,0 +1,24 @@
[program:app-alpha-1]
command=./alpha
autostart=true
autorestart=true
stopsignal=QUIT
stdout_logfile=/var/log/app/alpha-1-out.log
stderr_logfile=/var/log/app/alpha-1-err.log
user=app
directory=/tmp/app
environment=PORT="5000"
[program:app-alpha-2]
command=./alpha
autostart=true
autorestart=true
stopsignal=QUIT
stdout_logfile=/var/log/app/alpha-2-out.log
stderr_logfile=/var/log/app/alpha-2-err.log
user=app
directory=/tmp/app
environment=PORT="5001"
[group:app]
programs=app-alpha-1,app-alpha-2

View File

@@ -0,0 +1,24 @@
[program:app-alpha]
command=./alpha
autostart=true
autorestart=true
stopsignal=QUIT
stdout_logfile=/var/log/app/alpha-1-out.log
stderr_logfile=/var/log/app/alpha-1-err.log
user=app
directory=/tmp/app
environment=QUEUE="fastqueue,slowqueue",VERBOSE="1",PORT="5000"
[program:app-bravo]
command=./bravo
autostart=true
autorestart=true
stopsignal=QUIT
stdout_logfile=/var/log/app/bravo-1-out.log
stderr_logfile=/var/log/app/bravo-1-err.log
user=app
directory=/tmp/app
environment=QUEUE="fastqueue,slowqueue",VERBOSE="1",PORT="5100"
[group:app]
programs=app-alpha,app-bravo

View File

@@ -0,0 +1,21 @@
[program:app-alpha]
command=./alpha
autostart=true
autorestart=true
stopsignal=QUIT
stdout_logfile=/var/log/app/alpha-1-out.log
stderr_logfile=/var/log/app/alpha-1-err.log
user=app
directory=/tmp/app
environment=FOO="bar",PORT="5000"
[program:app-bravo]
command=./bravo
autostart=true
autorestart=true
stopsignal=QUIT
stdout_logfile=/var/log/app/bravo-1-out.log
stderr_logfile=/var/log/app/bravo-1-err.log
user=app
directory=/tmp/app
environment=FOO="bar",PORT="5100"

View File

@@ -0,0 +1,24 @@
[program:app-alpha]
command=./alpha
autostart=true
autorestart=true
stopsignal=QUIT
stdout_logfile=/var/log/app/alpha-1-out.log
stderr_logfile=/var/log/app/alpha-1-err.log
user=app
directory=/tmp/app
environment=PORT="5000"
[program:app-bravo]
command=./bravo
autostart=true
autorestart=true
stopsignal=QUIT
stdout_logfile=/var/log/app/bravo-1-out.log
stderr_logfile=/var/log/app/bravo-1-err.log
user=app
directory=/tmp/app
environment=PORT="5100"
[group:app]
programs=app-alpha,app-bravo

View File

@@ -27,14 +27,6 @@ task :pages => "man:commit" do
}
end
desc "Generate an authors list"
task :authors do
authors = %x{ git log --pretty=format:"%an" | sort -u }.split("\n")
readme = File.read("README.md")
readme.gsub!(/#### Patches contributed by\n([^\n]*)\n/m, "#### Patches contributed by\n#{authors.join(", ")}\n")
File.open("README.md", "w") { |f| f.print readme }
end
def latest_release
latest = File.read("Changelog.md").split("\n").first.split(" ")[1]
end