Compare commits
180
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22ad6c5dd8 | ||
|
|
b117ef5b08 | ||
|
|
35474ad1a5 | ||
|
|
fc5e86b269 | ||
|
|
7f8ca7da39 | ||
|
|
31239d98d0 | ||
|
|
472395edf8 | ||
|
|
6b7d5e5161 | ||
|
|
977c80ffdd | ||
|
|
2804316bbb | ||
|
|
26859c2ec2 | ||
|
|
27152b0e76 | ||
|
|
160945b499 | ||
|
|
f2be566051 | ||
|
|
a504a59f0b | ||
|
|
e6b61801b1 | ||
|
|
dc231f072b | ||
|
|
b77b23b306 | ||
|
|
185617dddc | ||
|
|
9e4cc02827 | ||
|
|
8b6e2481f4 | ||
|
|
79f376368c | ||
|
|
3576ae82af | ||
|
|
303d54155f | ||
|
|
2e36cbf045 | ||
|
|
d3059ca563 | ||
|
|
9e42dfb253 | ||
|
|
eca48170a5 | ||
|
|
86e3cd12dd | ||
|
|
efd5a786f5 | ||
|
|
7e9117812f | ||
|
|
55f405a2b4 | ||
|
|
615bb0d4ba | ||
|
|
0ae144e468 | ||
|
|
0c2b2a4ac2 | ||
|
|
e68946f186 | ||
|
|
52edb7fd28 | ||
|
|
8446528f5a | ||
|
|
d41a8726bd | ||
|
|
7bb1e58879 | ||
|
|
62b6cac741 | ||
|
|
2a7dadc2b2 | ||
|
|
9cd772ac0f | ||
|
|
2b27d0a51a | ||
|
|
99204d7c1d | ||
|
|
e9b5ed81b8 | ||
|
|
7d751470d2 | ||
|
|
68c1a01f15 | ||
|
|
08f9027cb4 | ||
|
|
4f7692bed9 | ||
|
|
dd95cea997 | ||
|
|
f3988b0c52 | ||
|
|
fbb17dd37d | ||
|
|
31a72b454b | ||
|
|
e5a8c38da6 | ||
|
|
d199ef2b4d | ||
|
|
7a1895e435 | ||
|
|
151ddb45c8 | ||
|
|
51513dcb6d | ||
|
|
0b6fdad3a2 | ||
|
|
096f532624 | ||
|
|
efeef5b4f0 | ||
|
|
0eb08dd8ae | ||
|
|
92ba6e0ba7 | ||
|
|
2b90c48eb4 | ||
|
|
dbfd8ba49a | ||
|
|
d6837177cd | ||
|
|
58b45c4933 | ||
|
|
fbdf4d7220 | ||
|
|
895672efe8 | ||
|
|
8597e0dc16 | ||
|
|
408ba06c3f | ||
|
|
a0f82840eb | ||
|
|
1317013898 | ||
|
|
6a7720872f | ||
|
|
b3a5fa9c1b | ||
|
|
41e095cf04 | ||
|
|
2c9f6c25fc | ||
|
|
ce0261c3de | ||
|
|
f138d26e7e | ||
|
|
6000e837fe | ||
|
|
02299c4c1c | ||
|
|
6dc9fe2667 | ||
|
|
a61d808487 | ||
|
|
5f98544dab | ||
|
|
99da671f5d | ||
|
|
26599f630f | ||
|
|
cfe6a49900 | ||
|
|
ddccab4c63 | ||
|
|
3151663f37 | ||
|
|
98486513b6 | ||
|
|
b969e03086 | ||
|
|
be593846e2 | ||
|
|
2458c4e75f | ||
|
|
314e2f5530 | ||
|
|
d6c5e6ddea | ||
|
|
261164e694 | ||
|
|
92e637a231 | ||
|
|
08b94716f2 | ||
|
|
44d589a28f | ||
|
|
4bf1f26032 | ||
|
|
2a2786e676 | ||
|
|
91811425aa | ||
|
|
adb40881d7 | ||
|
|
fd3dc590d9 | ||
|
|
8651bbdbee | ||
|
|
ced0d0aa9d | ||
|
|
10e572de94 | ||
|
|
426241d461 | ||
|
|
5a258b8dc3 | ||
|
|
eeeef65c88 | ||
|
|
d67a2f4e11 | ||
|
|
ce5c8b4c04 | ||
|
|
9d859dae92 | ||
|
|
04884366b3 | ||
|
|
8c78d1e1ee | ||
|
|
35a5f972fe | ||
|
|
868bc44a4e | ||
|
|
644956db29 | ||
|
|
bd07ed809d | ||
|
|
26bb8995c9 | ||
|
|
7005860c3c | ||
|
|
90356ca41d | ||
|
|
2ce3a15bb7 | ||
|
|
f960277ae8 | ||
|
|
4f5402af4a | ||
|
|
a27f964881 | ||
|
|
cf008385b4 | ||
|
|
f633a579d6 | ||
|
|
ea90bf3615 | ||
|
|
c65c71b1c0 | ||
|
|
6f10f4f014 | ||
|
|
be6d1b805c | ||
|
|
58e936a7e2 | ||
|
|
d4f29d6909 | ||
|
|
571163795f | ||
|
|
845ee9ef38 | ||
|
|
d5d774c9c2 | ||
|
|
b77952ff7f | ||
|
|
3495fa2fea | ||
|
|
4741dceeb0 | ||
|
|
dc1cb08d27 | ||
|
|
b51e8046ce | ||
|
|
922eb7438e | ||
|
|
6811a8d96a | ||
|
|
0f7eec061d | ||
|
|
27e53eb916 | ||
|
|
b123e6b3c5 | ||
|
|
c2000484bb | ||
|
|
75f0ce4b9c | ||
|
|
d508d44fd2 | ||
|
|
35cc880d40 | ||
|
|
6434db289b | ||
|
|
1a118ee92b | ||
|
|
7bd176063c | ||
|
|
fff958f7b6 | ||
|
|
7888ee8c52 | ||
|
|
a6197c183e | ||
|
|
41a0620126 | ||
|
|
86654d7918 | ||
|
|
9929165d17 | ||
|
|
2b8d575aab | ||
|
|
56f8603a5d | ||
|
|
3f48d7c541 | ||
|
|
675ad2630d | ||
|
|
9004bf67e1 | ||
|
|
19c425d200 | ||
|
|
2ecbf8d06d | ||
|
|
7d7bb87fc7 | ||
|
|
07f2e41582 | ||
|
|
00eaa2d239 | ||
|
|
1fd1a39f4d | ||
|
|
182d344c70 | ||
|
|
ffb7e9d6a5 | ||
|
|
53eb08be4f | ||
|
|
0221c2305c | ||
|
|
93b2227dfe | ||
|
|
0f4ed89c92 | ||
|
|
0f2048e345 | ||
|
|
2dbd3e6be5 |
+9
-4
@@ -1,4 +1,9 @@
|
|||||||
/.bundle
|
.bundle
|
||||||
/coverage
|
coverage
|
||||||
/man
|
example/log/*
|
||||||
/pkg
|
man/*.?
|
||||||
|
man/*.html
|
||||||
|
man/*.markdown
|
||||||
|
pkg
|
||||||
|
tags
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
source "http://rubygems.org"
|
||||||
|
|
||||||
|
group :development do
|
||||||
|
gem 'parka'
|
||||||
|
gem 'rake'
|
||||||
|
gem 'ronn'
|
||||||
|
end
|
||||||
|
|
||||||
|
group :test do
|
||||||
|
gem 'fakefs', '~> 0.2.1'
|
||||||
|
gem 'rcov', '~> 0.9.8'
|
||||||
|
gem 'rr', '~> 1.0.2'
|
||||||
|
gem 'rspec', '~> 2.0.0'
|
||||||
|
end
|
||||||
|
|
||||||
|
gem 'json', '~> 1.5.1'
|
||||||
|
gem 'term-ansicolor', '~> 1.0.5'
|
||||||
|
gem 'thor', '>= 0.13.6'
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
GEM
|
||||||
|
remote: http://rubygems.org/
|
||||||
|
specs:
|
||||||
|
diff-lcs (1.1.2)
|
||||||
|
fakefs (0.2.1)
|
||||||
|
hpricot (0.8.2)
|
||||||
|
json (1.5.1)
|
||||||
|
mime-types (1.16)
|
||||||
|
mustache (0.11.2)
|
||||||
|
parka (0.3.1)
|
||||||
|
rest-client
|
||||||
|
thor
|
||||||
|
rake (0.8.7)
|
||||||
|
rcov (0.9.8)
|
||||||
|
rdiscount (1.6.5)
|
||||||
|
rest-client (1.6.0)
|
||||||
|
mime-types (>= 1.16)
|
||||||
|
ronn (0.7.3)
|
||||||
|
hpricot (>= 0.8.2)
|
||||||
|
mustache (>= 0.7.0)
|
||||||
|
rdiscount (>= 1.5.8)
|
||||||
|
rr (1.0.2)
|
||||||
|
rspec (2.0.1)
|
||||||
|
rspec-core (~> 2.0.1)
|
||||||
|
rspec-expectations (~> 2.0.1)
|
||||||
|
rspec-mocks (~> 2.0.1)
|
||||||
|
rspec-core (2.0.1)
|
||||||
|
rspec-expectations (2.0.1)
|
||||||
|
diff-lcs (>= 1.1.2)
|
||||||
|
rspec-mocks (2.0.1)
|
||||||
|
rspec-core (~> 2.0.1)
|
||||||
|
rspec-expectations (~> 2.0.1)
|
||||||
|
term-ansicolor (1.0.5)
|
||||||
|
thor (0.14.6)
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
ruby
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
fakefs (~> 0.2.1)
|
||||||
|
json (~> 1.5.1)
|
||||||
|
parka
|
||||||
|
rake
|
||||||
|
rcov (~> 0.9.8)
|
||||||
|
ronn
|
||||||
|
rr (~> 1.0.2)
|
||||||
|
rspec (~> 2.0.0)
|
||||||
|
term-ansicolor (~> 1.0.5)
|
||||||
|
thor (>= 0.13.6)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Foreman
|
||||||
|
|
||||||
|
## Manual
|
||||||
|
|
||||||
|
See the [man page](http://ddollar.github.com/foreman) for usage.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
require "rubygems"
|
||||||
|
require "bundler"
|
||||||
|
Bundler.setup
|
||||||
|
|
||||||
|
require "rake"
|
||||||
|
require "rspec"
|
||||||
|
require "rspec/core/rake_task"
|
||||||
|
|
||||||
|
$:.unshift File.expand_path("../lib", __FILE__)
|
||||||
|
require "foreman"
|
||||||
|
|
||||||
|
task :default => :spec
|
||||||
|
task :release => :man
|
||||||
|
|
||||||
|
desc "Run all specs"
|
||||||
|
Rspec::Core::RakeTask.new(:spec) do |t|
|
||||||
|
t.pattern = 'spec/**/*_spec.rb'
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Generate RCov code coverage report"
|
||||||
|
task :rcov => "rcov:build" do
|
||||||
|
%x{ open coverage/index.html }
|
||||||
|
end
|
||||||
|
|
||||||
|
Rspec::Core::RakeTask.new("rcov:build") do |t|
|
||||||
|
t.pattern = 'spec/**/*_spec.rb'
|
||||||
|
t.rcov = true
|
||||||
|
t.rcov_opts = [ "--exclude", ".bundle", "--exclude", "spec" ]
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'Build the manual'
|
||||||
|
task :man do
|
||||||
|
ENV['RONN_MANUAL'] = "Foreman Manual"
|
||||||
|
ENV['RONN_ORGANIZATION'] = "Foreman #{Foreman::VERSION}"
|
||||||
|
sh "ronn -w -s toc -r5 --markdown man/*.ronn"
|
||||||
|
sh "git add README.markdown"
|
||||||
|
sh "git commit -m 'update readme' || echo 'nothing to commit'"
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Generate the Github docs"
|
||||||
|
task :pages => :man do
|
||||||
|
sh %{
|
||||||
|
cp man/foreman.1.html /tmp/foreman.1.html
|
||||||
|
git checkout gh-pages
|
||||||
|
rm ./index.html
|
||||||
|
cp /tmp/foreman.1.html ./index.html
|
||||||
|
git add -u index.html
|
||||||
|
git commit -m "rebuilding man page"
|
||||||
|
git push origin -f gh-pages
|
||||||
|
git checkout master
|
||||||
|
}
|
||||||
|
end
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Autotest.add_discovery { "rspec2" }
|
||||||
Executable
+7
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
$:.unshift File.expand_path("../../lib", __FILE__)
|
||||||
|
|
||||||
|
require "foreman/cli"
|
||||||
|
|
||||||
|
Foreman::CLI.start
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ticker: ./ticker $PORT
|
||||||
|
error : ./error
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ticker ./ticker $PORT
|
||||||
|
error ./error
|
||||||
Executable
+5
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
puts "will error in 10s"
|
||||||
|
sleep 5
|
||||||
|
raise "Dying"
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
tick
|
||||||
|
tick
|
||||||
|
./never_die:6:in `sleep': Interrupt
|
||||||
|
from ./never_die:6
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
while true
|
||||||
|
puts "tick: #{ARGV.inspect}"
|
||||||
|
sleep 1
|
||||||
|
end
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
pre-start script
|
||||||
|
|
||||||
|
bash << "EOF"
|
||||||
|
mkdir -p <%= log_root %>
|
||||||
|
chown -R <%= user %> <%= log_root %>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
end script
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
start on starting <%= app %>-<%= process.name %>
|
||||||
|
stop on stopping <%= app %>-<%= process.name %>
|
||||||
|
respawn
|
||||||
|
|
||||||
|
chdir <%= engine.directory %>
|
||||||
|
exec su - <%= user %> -c 'export PORT=<%= port %>; <%= process.command %> >> <%= log_root %>/<%=process.name%>-<%=num%>.log 2>&1'
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
start on starting <%= app %>
|
||||||
|
stop on stopping <%= app %>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
$:.unshift File.expand_path("../lib", __FILE__)
|
||||||
|
require "foreman/version"
|
||||||
|
|
||||||
|
Gem::Specification.new do |gem|
|
||||||
|
gem.name = "foreman"
|
||||||
|
gem.version = Foreman::VERSION
|
||||||
|
|
||||||
|
gem.author = "David Dollar"
|
||||||
|
gem.email = "ddollar@gmail.com"
|
||||||
|
gem.homepage = "http://github.com/ddollar/foreman"
|
||||||
|
gem.summary = "Process manager for applications with multiple components"
|
||||||
|
|
||||||
|
gem.description = gem.summary
|
||||||
|
|
||||||
|
gem.executables = "foreman"
|
||||||
|
gem.files = Dir["**/*"].select { |d| d =~ %r{^(README|bin/|data/|ext/|lib/|spec/|test/)} }
|
||||||
|
gem.files << "man/foreman.1"
|
||||||
|
|
||||||
|
gem.add_dependency 'json', '~> 1.5.1'
|
||||||
|
gem.add_dependency 'term-ansicolor', '~> 1.0.5'
|
||||||
|
gem.add_dependency 'thor', '>= 0.13.6'
|
||||||
|
|
||||||
|
gem.add_development_dependency 'rake'
|
||||||
|
gem.add_development_dependency 'ronn'
|
||||||
|
gem.add_development_dependency 'fakefs', '~> 0.2.1'
|
||||||
|
gem.add_development_dependency 'rcov', '~> 0.9.8'
|
||||||
|
gem.add_development_dependency 'rr', '~> 1.0.2'
|
||||||
|
gem.add_development_dependency 'rspec', '~> 2.0.0'
|
||||||
|
end
|
||||||
-265
@@ -1,265 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv='content-type' value='text/html;charset=utf8'>
|
|
||||||
<meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
|
|
||||||
<title>foreman(1) - manage Procfile-based applications</title>
|
|
||||||
<style type='text/css' media='all'>
|
|
||||||
/* style: man */
|
|
||||||
body#manpage {margin:0}
|
|
||||||
.mp {max-width:100ex;padding:0 9ex 1ex 4ex}
|
|
||||||
.mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
|
|
||||||
.mp h2 {margin:10px 0 0 0}
|
|
||||||
.mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
|
|
||||||
.mp h3 {margin:0 0 0 4ex}
|
|
||||||
.mp dt {margin:0;clear:left}
|
|
||||||
.mp dt.flush {float:left;width:8ex}
|
|
||||||
.mp dd {margin:0 0 0 9ex}
|
|
||||||
.mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
|
|
||||||
.mp pre {margin-bottom:20px}
|
|
||||||
.mp pre+h2,.mp pre+h3 {margin-top:22px}
|
|
||||||
.mp h2+pre,.mp h3+pre {margin-top:5px}
|
|
||||||
.mp img {display:block;margin:auto}
|
|
||||||
.mp h1.man-title {display:none}
|
|
||||||
.mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
|
|
||||||
.mp h2 {font-size:16px;line-height:1.25}
|
|
||||||
.mp h1 {font-size:20px;line-height:2}
|
|
||||||
.mp {text-align:justify;background:#fff}
|
|
||||||
.mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
|
|
||||||
.mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
|
|
||||||
.mp u {text-decoration:underline}
|
|
||||||
.mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
|
|
||||||
.mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
|
|
||||||
.mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
|
|
||||||
.mp b.man-ref {font-weight:normal;color:#434241}
|
|
||||||
.mp pre {padding:0 4ex}
|
|
||||||
.mp pre code {font-weight:normal;color:#434241}
|
|
||||||
.mp h2+pre,h3+pre {padding-left:0}
|
|
||||||
ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
|
|
||||||
ol.man-decor {width:100%}
|
|
||||||
ol.man-decor li.tl {text-align:left}
|
|
||||||
ol.man-decor li.tc {text-align:center;letter-spacing:4px}
|
|
||||||
ol.man-decor li.tr {text-align:right;float:right}
|
|
||||||
</style>
|
|
||||||
<style type='text/css' media='all'>
|
|
||||||
/* style: toc */
|
|
||||||
.man-navigation {display:block !important;position:fixed;top:0;left:113ex;height:100%;width:100%;padding:48px 0 0 0;border-left:1px solid #dbdbdb;background:#eee}
|
|
||||||
.man-navigation a,.man-navigation a:hover,.man-navigation a:link,.man-navigation a:visited {display:block;margin:0;padding:5px 2px 5px 30px;color:#999;text-decoration:none}
|
|
||||||
.man-navigation a:hover {color:#111;text-decoration:underline}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<!--
|
|
||||||
The following styles are deprecated and will be removed at some point:
|
|
||||||
div#man, div#man ol.man, div#man ol.head, div#man ol.man.
|
|
||||||
|
|
||||||
The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
|
|
||||||
.man-navigation should be used instead.
|
|
||||||
-->
|
|
||||||
<body id='manpage'>
|
|
||||||
<div class='mp' id='man'>
|
|
||||||
|
|
||||||
<div class='man-navigation' style='display:none'>
|
|
||||||
<a href="#NAME">NAME</a>
|
|
||||||
<a href="#SYNOPSIS">SYNOPSIS</a>
|
|
||||||
<a href="#DESCRIPTION">DESCRIPTION</a>
|
|
||||||
<a href="#RUNNING">RUNNING</a>
|
|
||||||
<a href="#EXPORTING">EXPORTING</a>
|
|
||||||
<a href="#GLOBAL-OPTIONS">GLOBAL OPTIONS</a>
|
|
||||||
<a href="#EXPORT-FORMATS">EXPORT FORMATS</a>
|
|
||||||
<a href="#INITTAB-EXPORT">INITTAB EXPORT</a>
|
|
||||||
<a href="#UPSTART-EXPORT">UPSTART EXPORT</a>
|
|
||||||
<a href="#PROCFILE">PROCFILE</a>
|
|
||||||
<a href="#ENVIRONMENT">ENVIRONMENT</a>
|
|
||||||
<a href="#DEFAULT-OPTIONS">DEFAULT OPTIONS</a>
|
|
||||||
<a href="#EXAMPLES">EXAMPLES</a>
|
|
||||||
<a href="#COPYRIGHT">COPYRIGHT</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ol class='man-decor man-head man head'>
|
|
||||||
<li class='tl'>foreman(1)</li>
|
|
||||||
<li class='tc'>Foreman Manual</li>
|
|
||||||
<li class='tr'>foreman(1)</li>
|
|
||||||
</ol>
|
|
||||||
|
|
||||||
<h2 id="NAME">NAME</h2>
|
|
||||||
<p class="man-name">
|
|
||||||
<code>foreman</code> - <span class="man-whatis">manage Procfile-based applications</span>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h2 id="SYNOPSIS">SYNOPSIS</h2>
|
|
||||||
|
|
||||||
<p><code>foreman start [process]</code><br />
|
|
||||||
<code>foreman run <command></code><br />
|
|
||||||
<code>foreman export <format> [location]</code></p>
|
|
||||||
|
|
||||||
<h2 id="DESCRIPTION">DESCRIPTION</h2>
|
|
||||||
|
|
||||||
<p>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.</p>
|
|
||||||
|
|
||||||
<h2 id="RUNNING">RUNNING</h2>
|
|
||||||
|
|
||||||
<p><code>foreman start</code> is used to run your application directly from the command line.</p>
|
|
||||||
|
|
||||||
<p>If no additional parameters are passed, foreman will run one instance of each
|
|
||||||
type of process defined in your Procfile.</p>
|
|
||||||
|
|
||||||
<p>If a parameter is passed, foreman will run one instance of the specified
|
|
||||||
application type.</p>
|
|
||||||
|
|
||||||
<p>The following options control how the application is run:</p>
|
|
||||||
|
|
||||||
<dl>
|
|
||||||
<dt><code>-c</code>, <code>--concurrency</code></dt><dd><p>Specify the number of each process type to run. The value passed in
|
|
||||||
should be in the format <code>process=num,process=num</code></p></dd>
|
|
||||||
<dt><code>-e</code>, <code>--env</code></dt><dd><p>Specify one or more .env files to load</p></dd>
|
|
||||||
<dt><code>-f</code>, <code>--procfile</code></dt><dd><p>Specify an alternate Procfile to load, implies <code>-d</code> at the Procfile root.</p></dd>
|
|
||||||
<dt><code>-p</code>, <code>--port</code></dt><dd><p>Specify which port to use as the base for this application. Should be
|
|
||||||
a multiple of 1000.</p></dd>
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
|
|
||||||
<p><code>foreman run</code> is used to run one-off commands using the same environment
|
|
||||||
as your defined processes.</p>
|
|
||||||
|
|
||||||
<h2 id="EXPORTING">EXPORTING</h2>
|
|
||||||
|
|
||||||
<p><code>foreman export</code> is used to export your application to another process
|
|
||||||
management format.</p>
|
|
||||||
|
|
||||||
<p>An location to export can be passed as an argument. This argument may be
|
|
||||||
either required or optional depending on the export format.</p>
|
|
||||||
|
|
||||||
<p>The following options control how the application is run:</p>
|
|
||||||
|
|
||||||
<dl>
|
|
||||||
<dt><code>-a</code>, <code>--app</code></dt><dd><p>Use this name rather than the application's root directory name as the
|
|
||||||
name of the application when exporting.</p></dd>
|
|
||||||
<dt><code>-c</code>, <code>--concurrency</code></dt><dd><p>Specify the number of each process type to run. The value passed in
|
|
||||||
should be in the format <code>process=num,process=num</code></p></dd>
|
|
||||||
<dt><code>-l</code>, <code>--log</code></dt><dd><p>Specify the directory to place process logs in.</p></dd>
|
|
||||||
<dt><code>-p</code>, <code>--port</code></dt><dd><p>Specify which port to use as the base for this application. Should be
|
|
||||||
a multiple of 1000.</p></dd>
|
|
||||||
<dt><code>-t</code>, <code>--template</code></dt><dd><p>Specify an alternate template to use for creating export files.
|
|
||||||
See <a href="https://github.com/ddollar/foreman/tree/master/data/export" data-bare-link="true">https://github.com/ddollar/foreman/tree/master/data/export</a> for examples.</p></dd>
|
|
||||||
<dt><code>-u</code>, <code>--user</code></dt><dd><p>Specify the user the application should be run as. Defaults to the
|
|
||||||
app name</p></dd>
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
|
|
||||||
<h2 id="GLOBAL-OPTIONS">GLOBAL OPTIONS</h2>
|
|
||||||
|
|
||||||
<p>These options control all modes of foreman's operation.</p>
|
|
||||||
|
|
||||||
<dl>
|
|
||||||
<dt><code>-d</code>, <code>--root</code></dt><dd><p>Specify an alternate application root. This defaults to the directory
|
|
||||||
containing the Procfile.</p></dd>
|
|
||||||
<dt><code>-e</code>, <code>--env</code></dt><dd><p>Specify an alternate environment file. You can specify more than one
|
|
||||||
file by using: <code>--env file1,file2</code>.</p></dd>
|
|
||||||
<dt><code>-f</code>, <code>--procfile</code></dt><dd><p>Specify an alternate location for the application's Procfile. This file's
|
|
||||||
containing directory will be assumed to be the root directory of the
|
|
||||||
application.</p></dd>
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
|
|
||||||
<h2 id="EXPORT-FORMATS">EXPORT FORMATS</h2>
|
|
||||||
|
|
||||||
<p>foreman currently supports the following output formats:</p>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<li><p>bluepill</p></li>
|
|
||||||
<li><p>inittab</p></li>
|
|
||||||
<li><p>runit</p></li>
|
|
||||||
<li><p>upstart</p></li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
|
|
||||||
<h2 id="INITTAB-EXPORT">INITTAB EXPORT</h2>
|
|
||||||
|
|
||||||
<p>Will export a chunk of inittab-compatible configuration:</p>
|
|
||||||
|
|
||||||
<pre><code># ----- foreman example processes -----
|
|
||||||
EX01:4:respawn:/bin/su - example -c 'PORT=5000 bundle exec thin start >> /var/log/web-1.log 2>&1'
|
|
||||||
EX02:4:respawn:/bin/su - example -c 'PORT=5100 bundle exec rake jobs:work >> /var/log/job-1.log 2>&1'
|
|
||||||
# ----- end foreman example processes -----
|
|
||||||
</code></pre>
|
|
||||||
|
|
||||||
<h2 id="UPSTART-EXPORT">UPSTART EXPORT</h2>
|
|
||||||
|
|
||||||
<p>Will create a series of upstart scripts in the location you specify. Scripts
|
|
||||||
will be structured to make the following commands valid:</p>
|
|
||||||
|
|
||||||
<p> <code>start appname</code></p>
|
|
||||||
|
|
||||||
<p> <code>stop appname-processname</code></p>
|
|
||||||
|
|
||||||
<p> <code>restart appname-processname-3</code></p>
|
|
||||||
|
|
||||||
<h2 id="PROCFILE">PROCFILE</h2>
|
|
||||||
|
|
||||||
<p>A Procfile should contain both a name for the process and the command used
|
|
||||||
to run it.</p>
|
|
||||||
|
|
||||||
<pre><code>web: bundle exec thin start
|
|
||||||
job: bundle exec rake jobs:work
|
|
||||||
</code></pre>
|
|
||||||
|
|
||||||
<p>A process name may contain letters, numbers amd the underscore character.
|
|
||||||
You can validate your Procfile format using the <code>check</code> command:</p>
|
|
||||||
|
|
||||||
<pre><code>$ foreman check
|
|
||||||
</code></pre>
|
|
||||||
|
|
||||||
<h2 id="ENVIRONMENT">ENVIRONMENT</h2>
|
|
||||||
|
|
||||||
<p>If a <code>.env</code> file exists in the current directory, the default environment will
|
|
||||||
be read from it. This file should contain key/value pairs, separated by <code>=</code>, with
|
|
||||||
one key/value pair per line.</p>
|
|
||||||
|
|
||||||
<pre><code>FOO=bar
|
|
||||||
BAZ=qux
|
|
||||||
</code></pre>
|
|
||||||
|
|
||||||
<h2 id="DEFAULT-OPTIONS">DEFAULT OPTIONS</h2>
|
|
||||||
|
|
||||||
<p>If a <code>.foreman</code> file exists in the current directory, default options will
|
|
||||||
be read from it. This file should be in YAML format with the long option
|
|
||||||
name as keys. Example:</p>
|
|
||||||
|
|
||||||
<pre><code>concurrency: alpha=0,bravo=1
|
|
||||||
port: 15000
|
|
||||||
</code></pre>
|
|
||||||
|
|
||||||
<h2 id="EXAMPLES">EXAMPLES</h2>
|
|
||||||
|
|
||||||
<p>Start one instance of each process type, interleave the output on stdout:</p>
|
|
||||||
|
|
||||||
<pre><code>$ foreman start
|
|
||||||
</code></pre>
|
|
||||||
|
|
||||||
<p>Export the application in upstart format:</p>
|
|
||||||
|
|
||||||
<pre><code>$ foreman export upstart /etc/init
|
|
||||||
</code></pre>
|
|
||||||
|
|
||||||
<p>Run one process type from the application defined in a specific Procfile:</p>
|
|
||||||
|
|
||||||
<pre><code>$ foreman start alpha -p ~/myapp/Procfile
|
|
||||||
</code></pre>
|
|
||||||
|
|
||||||
<h2 id="COPYRIGHT">COPYRIGHT</h2>
|
|
||||||
|
|
||||||
<p>Foreman is Copyright (C) 2010 David Dollar <a href="http://daviddollar.org" data-bare-link="true">http://daviddollar.org</a></p>
|
|
||||||
|
|
||||||
|
|
||||||
<ol class='man-decor man-foot man foot'>
|
|
||||||
<li class='tl'>Foreman 0.63.0</li>
|
|
||||||
<li class='tc'>April 2013</li>
|
|
||||||
<li class='tr'>foreman(1)</li>
|
|
||||||
</ol>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
module Foreman
|
||||||
|
|
||||||
|
class AppDoesNotExist < Exception; end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
require "foreman"
|
||||||
|
require "foreman/engine"
|
||||||
|
require "foreman/export"
|
||||||
|
require "thor"
|
||||||
|
|
||||||
|
class Foreman::CLI < Thor
|
||||||
|
|
||||||
|
class_option :procfile, :type => :string, :aliases => "-f", :desc => "Default: Procfile"
|
||||||
|
|
||||||
|
desc "start [PROCESS]", "Start the application, or a specific process"
|
||||||
|
|
||||||
|
method_option :port, :type => :numeric, :aliases => "-p"
|
||||||
|
method_option :concurrency, :type => :string, :aliases => "-c",
|
||||||
|
:banner => '"alpha=5,bar=3"'
|
||||||
|
|
||||||
|
def start(process=nil)
|
||||||
|
check_procfile!
|
||||||
|
|
||||||
|
if process
|
||||||
|
engine.execute(process, options)
|
||||||
|
else
|
||||||
|
engine.start(options)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "export FORMAT LOCATION", "Export the application to another process management format"
|
||||||
|
|
||||||
|
method_option :app, :type => :string, :aliases => "-a"
|
||||||
|
method_option :log, :type => :string, :aliases => "-l"
|
||||||
|
method_option :port, :type => :numeric, :aliases => "-p"
|
||||||
|
method_option :user, :type => :string, :aliases => "-u"
|
||||||
|
method_option :concurrency, :type => :string, :aliases => "-c",
|
||||||
|
:banner => '"alpha=5,bar=3"'
|
||||||
|
|
||||||
|
def export(format, location=nil)
|
||||||
|
check_procfile!
|
||||||
|
|
||||||
|
formatter = case format
|
||||||
|
when "json" then Foreman::Export::JSON
|
||||||
|
when "inittab" then Foreman::Export::Inittab
|
||||||
|
when "upstart" then Foreman::Export::Upstart
|
||||||
|
else error "Unknown export format: #{format}."
|
||||||
|
end
|
||||||
|
|
||||||
|
formatter.new(engine).export(location, options)
|
||||||
|
|
||||||
|
rescue Foreman::Export::Exception => ex
|
||||||
|
error ex.message
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "check", "Validate your application's Procfile"
|
||||||
|
|
||||||
|
def check
|
||||||
|
processes = engine.processes_in_order.map { |p| p.first }
|
||||||
|
error "no processes defined" unless processes.length > 0
|
||||||
|
display "valid procfile detected (#{processes.join(', ')})"
|
||||||
|
end
|
||||||
|
|
||||||
|
private ######################################################################
|
||||||
|
|
||||||
|
def check_procfile!
|
||||||
|
error("#{procfile} does not exist.") unless File.exist?(procfile)
|
||||||
|
end
|
||||||
|
|
||||||
|
def engine
|
||||||
|
@engine ||= Foreman::Engine.new(procfile)
|
||||||
|
end
|
||||||
|
|
||||||
|
def procfile
|
||||||
|
options[:procfile] || "Procfile"
|
||||||
|
end
|
||||||
|
|
||||||
|
def display(message)
|
||||||
|
puts message
|
||||||
|
end
|
||||||
|
|
||||||
|
def error(message)
|
||||||
|
puts "ERROR: #{message}"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def procfile_exists?(procfile)
|
||||||
|
File.exist?(procfile)
|
||||||
|
end
|
||||||
|
|
||||||
|
def options
|
||||||
|
original_options = super
|
||||||
|
return original_options unless File.exists?(".foreman")
|
||||||
|
defaults = YAML::load_file(".foreman")
|
||||||
|
Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
require "foreman"
|
||||||
|
require "foreman/process"
|
||||||
|
require "foreman/utils"
|
||||||
|
require "pty"
|
||||||
|
require "tempfile"
|
||||||
|
require "term/ansicolor"
|
||||||
|
require "fileutils"
|
||||||
|
|
||||||
|
class Foreman::Engine
|
||||||
|
|
||||||
|
attr_reader :procfile
|
||||||
|
attr_reader :directory
|
||||||
|
|
||||||
|
extend Term::ANSIColor
|
||||||
|
|
||||||
|
COLORS = [ cyan, yellow, green, magenta, red ]
|
||||||
|
|
||||||
|
def initialize(procfile)
|
||||||
|
@procfile = read_procfile(procfile)
|
||||||
|
@directory = File.expand_path(File.dirname(procfile))
|
||||||
|
end
|
||||||
|
|
||||||
|
def processes
|
||||||
|
@processes ||= begin
|
||||||
|
@order = []
|
||||||
|
procfile.split("\n").inject({}) do |hash, line|
|
||||||
|
next if line.strip == ""
|
||||||
|
name, command = line.split(/ *: +/, 2)
|
||||||
|
unless command
|
||||||
|
warn_deprecated_procfile!
|
||||||
|
name, command = line.split(/ +/, 2)
|
||||||
|
end
|
||||||
|
process = Foreman::Process.new(name, command)
|
||||||
|
process.color = next_color
|
||||||
|
@order << process.name
|
||||||
|
hash.update(process.name => process)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def process_order
|
||||||
|
processes
|
||||||
|
@order.uniq
|
||||||
|
end
|
||||||
|
|
||||||
|
def processes_in_order
|
||||||
|
process_order.map do |name|
|
||||||
|
[name, processes[name]]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def start(options={})
|
||||||
|
proctitle "ruby: foreman master"
|
||||||
|
|
||||||
|
processes_in_order.each do |name, process|
|
||||||
|
fork process, options
|
||||||
|
end
|
||||||
|
|
||||||
|
trap("TERM") { puts "SIGTERM received"; kill_all("TERM") }
|
||||||
|
trap("INT") { puts "SIGINT received"; kill_all("INT") }
|
||||||
|
|
||||||
|
watch_for_termination
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute(name, options={})
|
||||||
|
fork processes[name], options
|
||||||
|
|
||||||
|
trap("TERM") { puts "SIGTERM received"; kill_all("TERM") }
|
||||||
|
trap("INT") { puts "SIGINT received"; kill_all("INT") }
|
||||||
|
|
||||||
|
watch_for_termination
|
||||||
|
end
|
||||||
|
|
||||||
|
def port_for(process, num, base_port=nil)
|
||||||
|
base_port ||= 5000
|
||||||
|
offset = processes_in_order.map { |p| p.first }.index(process.name) * 100
|
||||||
|
base_port.to_i + offset + num - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
private ######################################################################
|
||||||
|
|
||||||
|
def fork(process, options={})
|
||||||
|
concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])
|
||||||
|
|
||||||
|
1.upto(concurrency[process.name]) do |num|
|
||||||
|
fork_individual(process, num, port_for(process, num, options[:port]))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def fork_individual(process, num, port)
|
||||||
|
ENV["PORT"] = port.to_s
|
||||||
|
ENV["PS"] = "#{process.name}.#{num}"
|
||||||
|
|
||||||
|
pid = Process.fork do
|
||||||
|
run(process)
|
||||||
|
end
|
||||||
|
|
||||||
|
info "started with pid #{pid}", process
|
||||||
|
running_processes[pid] = process
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(process)
|
||||||
|
proctitle "ruby: foreman #{process.name}"
|
||||||
|
|
||||||
|
begin
|
||||||
|
Dir.chdir directory do
|
||||||
|
command = process.command
|
||||||
|
|
||||||
|
PTY.spawn("#{process.command} 2>&1") do |stdin, stdout, pid|
|
||||||
|
until stdin.eof?
|
||||||
|
info stdin.gets, process
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue PTY::ChildExited, Interrupt
|
||||||
|
begin
|
||||||
|
info "process exiting", process
|
||||||
|
rescue Interrupt
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def kill_all(signal="TERM")
|
||||||
|
info "terminating"
|
||||||
|
running_processes.each do |pid, process|
|
||||||
|
info "killing #{process.name} in pid #{pid}"
|
||||||
|
Process.kill(signal, pid)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def info(message, process=nil)
|
||||||
|
print process.color if process
|
||||||
|
print "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(process)} | "
|
||||||
|
print Term::ANSIColor.reset
|
||||||
|
print message.chomp
|
||||||
|
puts
|
||||||
|
end
|
||||||
|
|
||||||
|
def longest_process_name
|
||||||
|
@longest_process_name ||= begin
|
||||||
|
longest = processes.keys.map { |name| name.length }.sort.last
|
||||||
|
longest = 6 if longest < 6 # system
|
||||||
|
longest
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def pad_process_name(process)
|
||||||
|
name = process ? "#{ENV["PS"]}" : "system"
|
||||||
|
name.ljust(longest_process_name + 3) # add 3 for process number padding
|
||||||
|
end
|
||||||
|
|
||||||
|
def print_info
|
||||||
|
info "currently running processes:"
|
||||||
|
running_processes.each do |pid, process|
|
||||||
|
info "pid #{pid}", process
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def proctitle(title)
|
||||||
|
$0 = title
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_procfile(procfile)
|
||||||
|
File.read(procfile)
|
||||||
|
end
|
||||||
|
|
||||||
|
def watch_for_termination
|
||||||
|
pid, status = Process.wait2
|
||||||
|
process = running_processes.delete(pid)
|
||||||
|
info "process terminated", process
|
||||||
|
kill_all
|
||||||
|
Process.waitall
|
||||||
|
end
|
||||||
|
|
||||||
|
def running_processes
|
||||||
|
@running_processes ||= {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def next_color
|
||||||
|
@current_color ||= -1
|
||||||
|
@current_color += 1
|
||||||
|
@current_color >= COLORS.length ? "" : COLORS[@current_color]
|
||||||
|
end
|
||||||
|
|
||||||
|
def warn_deprecated_procfile!
|
||||||
|
return if @already_warned_deprecated
|
||||||
|
@already_warned_deprecated = true
|
||||||
|
puts "!!! This format of Procfile is deprecated, and will not work starting in v0.12"
|
||||||
|
puts "!!! Use a colon to separate the process name from the command"
|
||||||
|
puts "!!! e.g. web: thin start"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
require "foreman"
|
||||||
|
|
||||||
|
module Foreman::Export
|
||||||
|
class Exception < ::Exception; end
|
||||||
|
end
|
||||||
|
|
||||||
|
require "foreman/export/json"
|
||||||
|
require "foreman/export/inittab"
|
||||||
|
require "foreman/export/upstart"
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
require "foreman/export"
|
||||||
|
require "foreman/utils"
|
||||||
|
|
||||||
|
class Foreman::Export::Base
|
||||||
|
|
||||||
|
attr_reader :engine
|
||||||
|
|
||||||
|
def initialize(engine)
|
||||||
|
@engine = engine
|
||||||
|
end
|
||||||
|
|
||||||
|
def export
|
||||||
|
raise "export method must be overridden"
|
||||||
|
end
|
||||||
|
|
||||||
|
private ######################################################################
|
||||||
|
|
||||||
|
def error(message)
|
||||||
|
raise Foreman::Export::Exception.new(message)
|
||||||
|
end
|
||||||
|
|
||||||
|
def say(message)
|
||||||
|
puts "[foreman export] %s" % message
|
||||||
|
end
|
||||||
|
|
||||||
|
def export_template(name)
|
||||||
|
File.read(File.expand_path("../../../../data/export/#{name}", __FILE__))
|
||||||
|
end
|
||||||
|
|
||||||
|
def write_file(filename, contents)
|
||||||
|
say "writing: #{filename}"
|
||||||
|
|
||||||
|
File.open(filename, "w") do |file|
|
||||||
|
file.puts contents
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
require "foreman/export/base"
|
||||||
|
|
||||||
|
class Foreman::Export::Inittab < Foreman::Export::Base
|
||||||
|
|
||||||
|
def export(fname=nil, options={})
|
||||||
|
app = options[:app] || File.basename(engine.directory)
|
||||||
|
user = options[:user] || app
|
||||||
|
log_root = options[:log] || "/var/log/#{app}"
|
||||||
|
|
||||||
|
concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])
|
||||||
|
|
||||||
|
inittab = []
|
||||||
|
inittab << "# ----- foreman #{app} processes -----"
|
||||||
|
|
||||||
|
engine.processes.values.inject(1) do |index, process|
|
||||||
|
1.upto(concurrency[process.name]) do |num|
|
||||||
|
id = app.slice(0, 2).upcase + sprintf("%02d", index)
|
||||||
|
port = engine.port_for(process, num, options[:port])
|
||||||
|
inittab << "#{id}:4:respawn:/bin/su - #{user} -c 'PORT=#{port} #{process.command} >> #{log_root}/#{process.name}-#{num}.log 2>&1'"
|
||||||
|
index += 1
|
||||||
|
end
|
||||||
|
index
|
||||||
|
end
|
||||||
|
|
||||||
|
inittab << "# ----- end foreman #{app} processes -----"
|
||||||
|
|
||||||
|
inittab = inittab.join("\n") + "\n"
|
||||||
|
|
||||||
|
if fname
|
||||||
|
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}"
|
||||||
|
write_file(fname, inittab)
|
||||||
|
else
|
||||||
|
puts inittab
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
require "foreman/export/base"
|
||||||
|
require "json"
|
||||||
|
|
||||||
|
class Foreman::Export::JSON < Foreman::Export::Base
|
||||||
|
|
||||||
|
def export(fname=nil, options={})
|
||||||
|
processes = engine.processes.values.inject({}) do |hash, process|
|
||||||
|
hash.update(process.name => { "command" => process.command })
|
||||||
|
end
|
||||||
|
puts processes.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
require "erb"
|
||||||
|
require "foreman/export/base"
|
||||||
|
|
||||||
|
class Foreman::Export::Upstart < Foreman::Export::Base
|
||||||
|
|
||||||
|
def export(location, options={})
|
||||||
|
error("Must specify a location") unless location
|
||||||
|
|
||||||
|
FileUtils.mkdir_p location
|
||||||
|
|
||||||
|
app = options[:app] || File.basename(engine.directory)
|
||||||
|
user = options[:user] || app
|
||||||
|
log_root = options[:log] || "/var/log/#{app}"
|
||||||
|
|
||||||
|
Dir["#{location}/#{app}*.conf"].each do |file|
|
||||||
|
say "cleaning up: #{file}"
|
||||||
|
FileUtils.rm(file)
|
||||||
|
end
|
||||||
|
|
||||||
|
concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])
|
||||||
|
|
||||||
|
master_template = export_template("upstart/master.conf.erb")
|
||||||
|
master_config = ERB.new(master_template).result(binding)
|
||||||
|
write_file "#{location}/#{app}.conf", master_config
|
||||||
|
|
||||||
|
process_template = export_template("upstart/process.conf.erb")
|
||||||
|
|
||||||
|
engine.processes.values.each do |process|
|
||||||
|
process_master_template = export_template("upstart/process_master.conf.erb")
|
||||||
|
process_master_config = ERB.new(process_master_template).result(binding)
|
||||||
|
write_file "#{location}/#{app}-#{process.name}.conf", process_master_config
|
||||||
|
|
||||||
|
1.upto(concurrency[process.name]) do |num|
|
||||||
|
port = engine.port_for(process, num, options[:port])
|
||||||
|
process_config = ERB.new(process_template).result(binding)
|
||||||
|
write_file "#{location}/#{app}-#{process.name}-#{num}.conf", process_config
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
require "foreman"
|
||||||
|
|
||||||
|
class Foreman::Process
|
||||||
|
|
||||||
|
attr_reader :name
|
||||||
|
attr_reader :command
|
||||||
|
attr_accessor :color
|
||||||
|
|
||||||
|
def initialize(name, command)
|
||||||
|
@name = name
|
||||||
|
@command = command
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
require "foreman"
|
||||||
|
|
||||||
|
class Foreman::Utils
|
||||||
|
|
||||||
|
def self.parse_concurrency(concurrency)
|
||||||
|
@concurrency ||= begin
|
||||||
|
pairs = concurrency.to_s.gsub(/\s/, "").split(",")
|
||||||
|
pairs.inject(Hash.new(1)) do |hash, pair|
|
||||||
|
process, amount = pair.split("=")
|
||||||
|
hash.update(process => amount.to_i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
module Foreman
|
||||||
|
|
||||||
|
VERSION = "0.12.0.pre1"
|
||||||
|
|
||||||
|
end
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
foreman(1) -- manage Procfile-based applications
|
||||||
|
================================================
|
||||||
|
|
||||||
|
## SYNOPSIS
|
||||||
|
|
||||||
|
`foreman start [process]`<br>
|
||||||
|
`foreman export <format> [location]`
|
||||||
|
|
||||||
|
## DESCRIPTION
|
||||||
|
|
||||||
|
**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.
|
||||||
|
|
||||||
|
## RUNNING
|
||||||
|
|
||||||
|
`foreman start` is used to run your application directly from the command line.
|
||||||
|
|
||||||
|
If no additional parameters are passed, foreman will run one instance of each
|
||||||
|
type of process defined in your Procfile.
|
||||||
|
|
||||||
|
If a parameter is passed, foreman will run one instance of the specified
|
||||||
|
application type.
|
||||||
|
|
||||||
|
The following options control how the application is run:
|
||||||
|
|
||||||
|
* `-c`, `--concurrency`:
|
||||||
|
Specify the number of each process type to run. The value passed in
|
||||||
|
should be in the format `process=num,process=num`
|
||||||
|
|
||||||
|
* `-p`, `--port`:
|
||||||
|
Specify which port to use as the base for this application. Should be
|
||||||
|
a multiple of 1000.
|
||||||
|
|
||||||
|
## EXPORTING
|
||||||
|
|
||||||
|
`foreman export` is used to export your application to another process
|
||||||
|
management format.
|
||||||
|
|
||||||
|
An location to export can be passed as an argument. This argument may be
|
||||||
|
either required or optional depending on the export format.
|
||||||
|
|
||||||
|
The following options control how the application is run:
|
||||||
|
|
||||||
|
* `-a`, `--app`:
|
||||||
|
Use this name rather than the application's root directory name as the
|
||||||
|
name of the application when exporting.
|
||||||
|
|
||||||
|
* `-c`, `--concurrency`:
|
||||||
|
Specify the number of each process type to run. The value passed in
|
||||||
|
should be in the format `process=num,process=num`
|
||||||
|
|
||||||
|
* `-l`, `--log`:
|
||||||
|
Specify the directory to place process logs in.
|
||||||
|
|
||||||
|
* `-p`, `--port`:
|
||||||
|
Specify which port to use as the base for this application. Should be
|
||||||
|
a multiple of 1000.
|
||||||
|
|
||||||
|
* `-u`, `--user`:
|
||||||
|
Specify the user the application should be run as. Defaults to the
|
||||||
|
app name
|
||||||
|
|
||||||
|
## OPTIONS
|
||||||
|
|
||||||
|
These options control all modes of foreman's operation.
|
||||||
|
|
||||||
|
* `-f`, `--procfile`:
|
||||||
|
Specify an alternate location for the application's Procfile. This file's
|
||||||
|
containing directory will be assumed to be the root directory of the
|
||||||
|
application.
|
||||||
|
|
||||||
|
## EXPORT FORMATS
|
||||||
|
|
||||||
|
foreman currently supports the following output formats:
|
||||||
|
|
||||||
|
* json
|
||||||
|
|
||||||
|
* inittab
|
||||||
|
|
||||||
|
* upstart
|
||||||
|
|
||||||
|
## JSON EXPORT
|
||||||
|
|
||||||
|
Will export your processes as JSON:
|
||||||
|
|
||||||
|
{ "web": { "command": "bundle exec thin start" } }
|
||||||
|
|
||||||
|
## INITTAB EXPORT
|
||||||
|
|
||||||
|
Will export a chunk of inittab-compatible configuration:
|
||||||
|
|
||||||
|
# ----- foreman example processes -----
|
||||||
|
EX01:4:respawn:/bin/su - example -c 'PORT=5000 bundle exec thin start >> /var/log/web-1.log 2>&1'
|
||||||
|
EX02:4:respawn:/bin/su - example -c 'PORT=5100 bundle exec rake jobs:work >> /var/log/job-1.log 2>&1'
|
||||||
|
# ----- end foreman example processes -----
|
||||||
|
|
||||||
|
## UPSTART EXPORT
|
||||||
|
|
||||||
|
Will create a series of upstart scripts in the location you specify. Scripts
|
||||||
|
will be structured to make the following commands valid:
|
||||||
|
|
||||||
|
`start appname`
|
||||||
|
|
||||||
|
`stop appname-processname`
|
||||||
|
|
||||||
|
`restart appname-processname-3`
|
||||||
|
|
||||||
|
## PROCFILE
|
||||||
|
|
||||||
|
A Procfile should contain both a name for the process and the command used
|
||||||
|
to run it.
|
||||||
|
|
||||||
|
web: bundle exec thin start
|
||||||
|
job: bundle exec rake jobs:work
|
||||||
|
|
||||||
|
You can validate your Procfile format using the `check` command
|
||||||
|
|
||||||
|
$ foreman check
|
||||||
|
|
||||||
|
## DEFAULT OPTIONS
|
||||||
|
|
||||||
|
If a `.foreman` file exists in the current directory, default options will
|
||||||
|
be read from it. This file should be in YAML format with the long option
|
||||||
|
name as keys. Example:
|
||||||
|
|
||||||
|
concurrency: alpha=0
|
||||||
|
port: 15000
|
||||||
|
|
||||||
|
## EXAMPLES
|
||||||
|
|
||||||
|
Start one instance of each process type, interleave the output on stdout:
|
||||||
|
|
||||||
|
$ foreman start
|
||||||
|
|
||||||
|
Export the application in upstart format:
|
||||||
|
|
||||||
|
$ foreman export upstart /etc/init
|
||||||
|
|
||||||
|
Run one process type from the application defined in a specific Procfile:
|
||||||
|
|
||||||
|
$ foreman start alpha -p ~/myapp/Procfile
|
||||||
|
|
||||||
|
## COPYRIGHT
|
||||||
|
|
||||||
|
Foreman is Copyright (C) 2010 David Dollar <http://daviddollar.org>
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
require "spec_helper"
|
||||||
|
require "foreman/cli"
|
||||||
|
|
||||||
|
describe "Foreman::CLI" do
|
||||||
|
subject { Foreman::CLI.new }
|
||||||
|
|
||||||
|
describe "start" do
|
||||||
|
describe "with a non-existent Procfile" do
|
||||||
|
it "prints an error" do
|
||||||
|
mock_error(subject, "Procfile does not exist.") do
|
||||||
|
dont_allow.instance_of(Foreman::Engine).start
|
||||||
|
subject.start
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "with a Procfile" do
|
||||||
|
before(:each) { write_procfile }
|
||||||
|
|
||||||
|
it "runs successfully" do
|
||||||
|
dont_allow(subject).error
|
||||||
|
mock.instance_of(Foreman::Engine).start({})
|
||||||
|
subject.start
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "export" do
|
||||||
|
describe "with a non-existent Procfile" do
|
||||||
|
it "prints an error" do
|
||||||
|
mock_error(subject, "Procfile does not exist.") do
|
||||||
|
dont_allow.instance_of(Foreman::Engine).export
|
||||||
|
subject.export("testapp")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "with a Procfile" do
|
||||||
|
before(:each) { write_procfile }
|
||||||
|
|
||||||
|
describe "with an invalid formatter" do
|
||||||
|
it "prints an error" do
|
||||||
|
mock_error(subject, "Unknown export format: invalidformatter.") do
|
||||||
|
subject.export("invalidformatter")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "with a valid config" do
|
||||||
|
before(:each) { write_foreman_config("testapp") }
|
||||||
|
|
||||||
|
it "runs successfully" do
|
||||||
|
dont_allow(subject).error
|
||||||
|
mock.instance_of(Foreman::Export::Upstart).export("/tmp/foo", {})
|
||||||
|
subject.export("upstart", "/tmp/foo")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "check" do
|
||||||
|
describe "with a valid Procfile" do
|
||||||
|
before { write_procfile }
|
||||||
|
|
||||||
|
it "displays the jobs" do
|
||||||
|
mock(subject).display("valid procfile detected (alpha, bravo)")
|
||||||
|
subject.check
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "with a blank Procfile" do
|
||||||
|
before do
|
||||||
|
FileUtils.touch("Procfile")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "displays an error" do
|
||||||
|
mock_error(subject, "no processes defined") do
|
||||||
|
subject.check
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
require "spec_helper"
|
||||||
|
require "foreman/engine"
|
||||||
|
|
||||||
|
describe "Foreman::Engine" do
|
||||||
|
subject { Foreman::Engine.new("Procfile") }
|
||||||
|
|
||||||
|
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 }
|
||||||
|
|
||||||
|
it "reads the processes" do
|
||||||
|
subject.processes["alpha"].command.should == "./alpha"
|
||||||
|
subject.processes["bravo"].command.should == "./bravo"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "with a deprecated Procfile" do
|
||||||
|
before do
|
||||||
|
File.open("Procfile", "w") do |file|
|
||||||
|
file.puts "name command"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should print a deprecation warning" do
|
||||||
|
mock(subject).warn_deprecated_procfile!
|
||||||
|
subject.processes.length.should == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "start" do
|
||||||
|
it "forks the processes" do
|
||||||
|
write_procfile
|
||||||
|
mock(subject).fork(subject.processes["alpha"], {})
|
||||||
|
mock(subject).fork(subject.processes["bravo"], {})
|
||||||
|
mock(subject).watch_for_termination
|
||||||
|
subject.start
|
||||||
|
end
|
||||||
|
|
||||||
|
it "handles concurrency" do
|
||||||
|
write_procfile
|
||||||
|
mock(subject).fork_individual(subject.processes["alpha"], 1, 5000)
|
||||||
|
mock(subject).fork_individual(subject.processes["alpha"], 2, 5001)
|
||||||
|
mock(subject).fork_individual(subject.processes["bravo"], 1, 5100)
|
||||||
|
mock(subject).watch_for_termination
|
||||||
|
subject.start(:concurrency => "alpha=2")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "execute" do
|
||||||
|
it "runs the processes" do
|
||||||
|
write_procfile
|
||||||
|
mock(subject).fork(subject.processes["alpha"], {})
|
||||||
|
mock(subject).watch_for_termination
|
||||||
|
subject.execute("alpha")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
require "spec_helper"
|
||||||
|
require "foreman/export/upstart"
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
require "spec_helper"
|
||||||
|
require "foreman/export"
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
require "spec_helper"
|
||||||
|
require "foreman/process"
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
require "spec_helper"
|
||||||
|
require "foreman"
|
||||||
|
|
||||||
|
describe Foreman do
|
||||||
|
|
||||||
|
describe "VERSION" do
|
||||||
|
subject { Foreman::VERSION }
|
||||||
|
it { should be_a String }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
require "rubygems"
|
||||||
|
require "rspec"
|
||||||
|
require "fakefs/safe"
|
||||||
|
require "fakefs/spec_helpers"
|
||||||
|
|
||||||
|
$:.unshift "lib"
|
||||||
|
|
||||||
|
def mock_error(subject, message)
|
||||||
|
mock_exit do
|
||||||
|
mock(subject).puts("ERROR: #{message}")
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def mock_exit(&block)
|
||||||
|
block.should raise_error(SystemExit)
|
||||||
|
end
|
||||||
|
|
||||||
|
def write_foreman_config(app)
|
||||||
|
File.open("/etc/foreman/#{app}.conf", "w") do |file|
|
||||||
|
file.puts %{#{app}_processes="alpha bravo"}
|
||||||
|
file.puts %{#{app}_alpha="1"}
|
||||||
|
file.puts %{#{app}_bravo="2"}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def write_procfile(procfile="Procfile")
|
||||||
|
File.open(procfile, "w") do |file|
|
||||||
|
file.puts "alpha: ./alpha"
|
||||||
|
file.puts "bravo: ./bravo"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Rspec.configure do |config|
|
||||||
|
config.color_enabled = true
|
||||||
|
config.include FakeFS::SpecHelpers
|
||||||
|
config.mock_with :rr
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user