Compare commits

...

55 Commits

Author SHA1 Message Date
David Dollar
8c3ef1a7af 0.37.0 2012-01-29 01:13:27 -05:00
David Dollar
cf69c31ae3 raw changelog 2012-01-29 01:13:02 -05:00
David Dollar
e16a35da4b fix changelog script 2012-01-29 01:12:56 -05:00
David Dollar
2490dd2a5b put an entire line of output inside a single mutex so we don't cross the streams 2012-01-29 00:09:44 -05:00
David Dollar
2705520496 fix race condition with process termination 2012-01-29 00:09:28 -05:00
David Dollar
522fee5e9e pedantry 2012-01-29 00:08:58 -05:00
David Dollar
c462473a25 fix simplecov 2012-01-28 18:53:43 -05:00
David Dollar
224fe94dc2 add more tests 2012-01-28 18:48:26 -05:00
David Dollar
7cb73f5c36 rearrange tasks, add coverage 2012-01-28 18:48:13 -05:00
David Dollar
1537ddbcc9 tweak simplecov entry 2012-01-28 16:27:02 -05:00
David Dollar
b04c81dd06 add simplecov 2012-01-28 16:26:12 -05:00
David Dollar
ae22d34967 Merge pull request #144 from technomancy/debian
Drop the S3 publishing rake tasks.
2012-01-26 17:02:42 -08:00
Phil Hagelberg
9a359efbf7 Drop the S3 publishing rake tasks. 2012-01-26 17:00:07 -08:00
David Dollar
9632227d29 0.37.0.pre5 2012-01-24 08:34:48 -08:00
David Dollar
288d118ca4 Merge pull request #142 from apollo13/master
Fix bash string comparision
2012-01-24 08:29:38 -08:00
David Dollar
576455b8d7 rename readme 2012-01-24 08:14:50 -08:00
David Dollar
a04032454a 0.37.0.pre4 2012-01-24 08:03:07 -08:00
David Dollar
29c94c785d Merge pull request #130 from clowder/foreman
---

Because `Your::Runit::Env != My::Runit::Env` I thought that it would be nice to be able to include your own export format as a another gem along side Foreman; similar to MultiJson’s engines but using constantize because we are specifying formats via the command line.

Cheers,
Chris
2012-01-24 08:00:12 -08:00
Chris Lowder
a0a2dd9454 Don't expose the options hash. 2012-01-24 15:10:25 +00:00
Chris Lowder
1b701cddf3 Simplify subclassing by adding all arguments to the initializer. Also, clean up the method signatures for existing exporters. 2012-01-24 15:10:18 +00:00
Chris Lowder
4080b3f1f2 Add ZenTest as a development dependency, there is an autotest folder but the gem is missing. 2012-01-24 14:37:57 +00:00
Chris Lowder
84c49ae2b8 Attempt to require the custom export class. 2012-01-24 14:36:38 +00:00
Chris Lowder
d54b46806c Catching more than we need to. 2012-01-24 14:36:38 +00:00
Chris Lowder
bc1c5e4c74 Extract commonality into the base class, make life easy for our plugin writers. 2012-01-24 14:36:38 +00:00
Chris Lowder
ed4a32518f Removing the hard coding of export formats allowing the user to 'plug-in' their own export format. 2012-01-24 14:31:45 +00:00
Florian Apolloner
e1d3955d3c Fix the test for an empty string in bin/runner 2012-01-24 09:51:16 +01:00
David Dollar
c7167e1c83 Update README.markdown 2012-01-23 14:20:45 -08:00
David Dollar
db93432118 Revert "try on more rubies"
This reverts commit 5eada6b7cc.
2012-01-23 00:45:25 -05:00
David Dollar
5eada6b7cc try on more rubies 2012-01-23 00:43:25 -05:00
David Dollar
5e46b1f43a fix webhook url 2012-01-23 00:41:10 -05:00
David Dollar
ef723f5831 Update README.markdown 2012-01-23 00:37:58 -05:00
David Dollar
52e24ef64b Update README.markdown 2012-01-23 00:31:57 -05:00
David Dollar
0b1daf1927 ensure we have non-nil data, fixes #111 2012-01-22 22:01:03 -05:00
David Dollar
e0d84a56d7 make sure error method exists. fixes #104 2012-01-22 21:55:55 -05:00
David Dollar
7ee2edcc60 Merge pull request #136 from fnichol/foreman
---

Simple enough, but this helps when re-exporting runit services. Cheers, and thanks!

Conflicts:
	spec/foreman/export/runit_spec.rb
2012-01-22 21:46:57 -05:00
David Dollar
d428ac5356 remove other from install instructions 2012-01-22 21:42:51 -05:00
David Dollar
5351b49fee cleanup 2012-01-22 21:41:10 -05:00
David Dollar
6ebe76d8c1 Revert "tweak authors"
This reverts commit 7c43c672c9
2012-01-22 21:39:24 -05:00
David Dollar
7c43c672c9 tweak authors 2012-01-22 21:39:09 -05:00
David Dollar
41d9050ae3 fix authors 2012-01-22 21:38:17 -05:00
David Dollar
09e9cefa3a readme tweaks 2012-01-22 21:36:38 -05:00
David Dollar
85efe5c1ba readme tweaks 2012-01-22 21:36:24 -05:00
David Dollar
c21634c04e fix up authors 2012-01-22 21:34:23 -05:00
David Dollar
6d4f3476f1 Update README.markdown 2012-01-22 21:32:33 -05:00
David Dollar
724812d6e3 fix up specs 2012-01-22 21:17:54 -05:00
David Dollar
ce6ec4848d we're not chdiring any more 2012-01-22 21:17:38 -05:00
David Dollar
a37a097f73 use strings rather than symbols to better emulate the real thing 2012-01-22 21:17:18 -05:00
David Dollar
f28725bdac Merge pull request #139 from brainopia/foreman
---

If you remember Ive wanted to implement a prototype of process-tree monitor (and therefore restore support for complex commands), but decided to start with specing current behavior and marking desired behavior as pending specs.

This pull-request is a first pass. Its mainly Foreman::Process specs and a bit of refactoring. Specs for Foreman::Engine will be coming next (theyll cover a wide ground of possible uses). Afterwards I will replace machinery a bit to remove pending specs and ensure the rest is still passing on all available to me platforms.

If you have any notices, Ill gladly hear them.
2012-01-22 20:58:51 -05:00
brainopia
ade0005a92 Add specs for Foreman::Process#run 2012-01-22 22:07:53 +04:00
brainopia
241b91a0d5 Implement Foreman::Process#kill,detach,alive?,dead? 2012-01-22 22:07:01 +04:00
brainopia
047f106d48 - Use explicit fakefs tag in specs
- Clean up trailing whitespace
2012-01-22 15:00:43 +04:00
brainopia
df043e60d8 Simplify Foreman::Process#with_environment 2012-01-22 08:57:09 +04:00
brainopia
158c184f8c Add specs for options of Foreman::Process#run 2012-01-22 08:55:45 +04:00
brainopia
2ed1fe8d44 Add specs for initialization of Foreman::Process 2012-01-22 08:54:42 +04:00
Fletcher Nichol
e76f3533dc runit creates a full path to export directory. 2012-01-18 20:13:08 -07:00
42 changed files with 995 additions and 423 deletions

1
.env
View File

@@ -1 +0,0 @@
FOO=bar

2
.gitignore vendored
View File

@@ -5,4 +5,4 @@
/man/*.markdown
/pkg
/tags
/vendor
/vendor

View File

@@ -11,4 +11,4 @@ notifications:
on_success: always
on_failure: always
urls:
- https://dx-helper.herokuapp.com/travis
- http://dx-helper.herokuapp.com/travis

View File

@@ -1,11 +0,0 @@
0.26.1 12/05/2011 6160246da0fafe9cf8fde188d94bbc6babc667dc
==========================================================
Merge pull request #103 from csquared/load_env_from_irb [David Dollar]
refactor load_env to apply_environment [Chris Continanza]
rename load! to load_env! [Chris Continanza]
use ./.env as default [Chris Continanza]
load contents from env file [Chris Continanza]
refactor engine to expose env methods [Chris Continanza]
disable email notifications [David Dollar]
add travis config [David Dollar]

190
Changelog.md Normal file
View File

@@ -0,0 +1,190 @@
## 0.37.0.pre5 2012-01-24 9632227
0.37.0.pre5 [David Dollar]
Merge pull request #142 from apollo13/master [David Dollar]
rename readme [David Dollar]
Fix the test for an empty string in bin/runner [Florian Apolloner]
## 0.37.0.pre4 2012-01-24 a040324
0.37.0.pre4 [David Dollar]
Merge pull request #130 from clowder/foreman [David Dollar]
Don't expose the options hash. [Chris Lowder]
Simplify subclassing by adding all arguments to the initializer. Also, clean up the method signatures for existing exporters. [Chris Lowder]
Add ZenTest as a development dependency, there is an autotest folder but the gem is missing. [Chris Lowder]
Attempt to require the custom export class. [Chris Lowder]
Catching more than we need to. [Chris Lowder]
Extract commonality into the base class, make life easy for our plugin writers. [Chris Lowder]
Removing the hard coding of export formats allowing the user to 'plug-in' their own export format. [Chris Lowder]
Update README.markdown [David Dollar]
Revert "try on more rubies" [David Dollar]
try on more rubies [David Dollar]
fix webhook url [David Dollar]
Update README.markdown [David Dollar]
Update README.markdown [David Dollar]
ensure we have non-nil data, fixes #111 [David Dollar]
make sure error method exists. fixes #104 [David Dollar]
Merge pull request #136 from fnichol/foreman [David Dollar]
remove other from install instructions [David Dollar]
cleanup [David Dollar]
Revert "tweak authors" [David Dollar]
tweak authors [David Dollar]
fix authors [David Dollar]
readme tweaks [David Dollar]
readme tweaks [David Dollar]
fix up authors [David Dollar]
Update README.markdown [David Dollar]
fix up specs [David Dollar]
we're not chdiring any more [David Dollar]
use strings rather than symbols to better emulate the real thing [David Dollar]
Merge pull request #139 from brainopia/foreman [David Dollar]
Add specs for Foreman::Process#run [brainopia]
Implement Foreman::Process#kill,detach,alive?,dead? [brainopia]
- Use explicit fakefs tag in specs - Clean up trailing whitespace [brainopia]
Simplify Foreman::Process#with_environment [brainopia]
Add specs for options of Foreman::Process#run [brainopia]
Add specs for initialization of Foreman::Process [brainopia]
runit creates a full path to export directory. [Fletcher Nichol]
## 0.37.0.pre3 2012-01-22 51eee01
0.37.0.pre3 [David Dollar]
normalize platform names [David Dollar]
windows support [David Dollar]
add windows support [David Dollar]
dont need pty [David Dollar]
fix specs [David Dollar]
## 0.37.0.pre2 2012-01-22 2995a60
0.37.0.pre2 [David Dollar]
0.37.0.pre1 [David Dollar]
remove unnecessary stdout/stderr flattening [David Dollar]
use PLATFORM=jruby instead of JRUBY=true [David Dollar]
## 0.37.0.pre1 2012-01-22 3e98170
fix java build bug [David Dollar]
dont do rubygems/bundler in the Rakefile [David Dollar]
switch to posix-spawn for jruby [David Dollar]
add jruby build [David Dollar]
spork is in the gemspec now [David Dollar]
remove debugging [David Dollar]
move the spoon require into the jruby branch [David Dollar]
pass basedir along to the runner script [David Dollar]
beef up the runner script to allow a working directory to be set [David Dollar]
Merge pull request #140 from jc00ke/foreman [David Dollar]
Move spoon dep to Gemfile [jc00ke]
Using spoon for JRuby support [jc00ke]
use default bucket for storage [David Dollar]
Merge pull request #138 from technomancy/debian [David Dollar]
Add Debian packaging. [Phil Hagelberg]
Ignore vendor dir. [Phil Hagelberg]
## 0.36.1 2012-01-18 1485eeb
0.36.1 [David Dollar]
bump term-ansicolor in gemspec [David Dollar]
## 0.36.0 2012-01-17 a73dce5
0.36.0 [David Dollar]
sync the writer stream [David Dollar]
capture stderr as well [David Dollar]
## 0.35.0 2012-01-16 2bfc065
update rake [David Dollar]
0.35.0 [David Dollar]
Merge pull request #132 from Viximo/feature/concurrency [David Dollar]
Fix export specs [Matt Griffin]
Merge branch 'master' of https://github.com/michaeldwan/foreman into feature/concurrency [Matt Griffin]
default process concurrency is 0 when concurrency options specified, otherwise default concurrency is 1 [Michael Dwan]
## 0.34.1 2012-01-16 d4c2332
0.34.1 [David Dollar]
fix missing start desc [David Dollar]
## 0.34.0 2012-01-16 a278755
0.34.0 [David Dollar]
update man page [David Dollar]
update docs for -d [David Dollar]
Merge pull request #101 from ndbroadbent/foreman [David Dollar]
Wrap around to the first colour when all the colours are used [Craig R Webster]
run specs in random order [David Dollar]
update rspec [David Dollar]
pedantry [David Dollar]
Set executable bit on runit run scripts. [Matthijs Langenberg]
Merge pull request #114 from gburt/master [David Dollar]
add more colors [Gabriel Burt]
Added option to specify app_root, if executing a Procfile from a shared location [Nathan Broadbent]
## 0.33.1 2012-01-16 533139e
0.33.1 [David Dollar]
Merge pull request #129 from fnichol/resolve-home-template [David Dollar]
Expand template path under user's home directory. [Fletcher Nichol]
## 0.33.0 2012-01-15 cf269c3
0.33.0 [David Dollar]
Revert "Merge pull request #125 from brainopia/master" [David Dollar]
## 0.32.0 2012-01-12 83748cb
0.32.0 [David Dollar]
Merge pull request #125 from brainopia/master [David Dollar]
Merge pull request #121 from Viximo/feature/run [David Dollar]
Return some whitespace that was accidentally removed [Matt Griffin]
Steal the run method back from Thor so that it can be used in place for exec for running commands in the foreman environment. [Matt Griffin]
Remove old cruft [brainopia]
In case someone wants to use bin/runner directly [brainopia]
Fix for double fork [brainopia]
Use ruby exec which works with escaped cmd and replaces shell [brainopia]
Fix foreman to work with cmds containing pipes and redirects [brainopia]
Add "exec" action to allow execution of arbitrary commands with the app's environment. [Matt Griffin]
tweak readme [David Dollar]
## 0.31.0 2012-01-04 342d30b
0.31.0 [David Dollar]
make fork more robust [David Dollar]
remove unnecessary debug [David Dollar]
add more information when shutting down [David Dollar]
Merge pull request #110 from lstoll/master [David Dollar]
Use different port ranges for each process type [Lincoln Stoll]
## 0.30.1 2011-12-23 fcfa913
0.30.1 [David Dollar]
require thread for mutex [David Dollar]
## 0.30.0 2011-12-22 fc95936
0.30.0 [David Dollar]
compatibility with ruby 1.8 [David Dollar]
## 0.29.0 2011-12-22 356c61f
0.29.0 [David Dollar]
## 0.28.0.pre2 2011-12-08 dcff4da
0.28.0.pre2 [David Dollar]
fix pipe error [David Dollar]
## 0.28.0.pre1 2011-12-08 c7b6b33
0.28.0.pre1 [David Dollar]
Merge branch 'fork' [David Dollar]
wip [David Dollar]
wip [David Dollar]
wip [David Dollar]
wip [David Dollar]
wip [David Dollar]
## 0.27.0 2011-12-05 914a1ee
0.27.0 [David Dollar]
add changelog [David Dollar]
Merge pull request #103 from csquared/load_env_from_irb [David Dollar]
refactor load_env to apply_environment [Chris Continanza]
rename load! to load_env! [Chris Continanza]
use ./.env as default [Chris Continanza]
load contents from env file [Chris Continanza]
refactor engine to expose env methods [Chris Continanza]
disable email notifications [David Dollar]
add travis config [David Dollar]
## 0.26.1 2011-12-05 a5e0943
Merge pull request #103 from csquared/load_env_from_irb [David Dollar]
refactor load_env to apply_environment [Chris Continanza]
rename load! to load_env! [Chris Continanza]
use ./.env as default [Chris Continanza]
load contents from env file [Chris Continanza]
refactor engine to expose env methods [Chris Continanza]
disable email notifications [David Dollar]
add travis config [David Dollar]

View File

@@ -15,9 +15,10 @@ group :development do
gem 'rake'
gem 'ronn'
gem 'fakefs', '~> 0.3.2'
gem 'rcov', '~> 0.9.8'
gem 'rr', '~> 1.0.2'
gem 'rspec', '~> 2.0'
gem 'ZenTest'
gem 'aws-s3'
gem "rubyzip"
gem "simplecov", :require => false
end

View File

@@ -1,13 +1,14 @@
PATH
remote: .
specs:
foreman (0.37.0.pre3)
foreman (0.37.0)
term-ansicolor (~> 1.0.7)
thor (>= 0.13.6)
GEM
remote: http://rubygems.org/
specs:
ZenTest (4.6.2)
aws-s3 (0.6.2)
builder
mime-types
@@ -19,6 +20,7 @@ GEM
hpricot (0.8.2)
hpricot (0.8.2-java)
mime-types (1.16)
multi_json (1.0.4)
mustache (0.11.2)
parka (0.6.2)
crack
@@ -26,8 +28,6 @@ GEM
thor
posix-spawn (0.3.6)
rake (0.9.2.2)
rcov (0.9.8)
rcov (0.9.8-java)
rdiscount (1.6.5)
rest-client (1.6.1)
mime-types (>= 1.16)
@@ -45,6 +45,10 @@ GEM
diff-lcs (~> 1.1.2)
rspec-mocks (2.8.0)
rubyzip (0.9.4)
simplecov (0.5.4)
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)
@@ -56,15 +60,16 @@ PLATFORMS
x86-mingw32
DEPENDENCIES
ZenTest
aws-s3
fakefs (~> 0.3.2)
foreman!
parka
posix-spawn (~> 0.3.6)
rake
rcov (~> 0.9.8)
ronn
rr (~> 1.0.2)
rspec (~> 2.0)
rubyzip
simplecov
win32console (~> 1.3.0)

View File

@@ -1,50 +0,0 @@
# Foreman
## Installation
* Rubygems
gem install foreman
* OSX
http://assets.foreman.io/foreman/foreman.pkg
* Standalone Tarball
http://assets.foreman.io/foreman/foreman.tgz
## Description
http://blog.daviddollar.org/2011/05/06/introducing-foreman.html
## Manual
* [man page](http://ddollar.github.com/foreman)
* [wiki](http://github.com/ddollar/foreman/wiki)
## Authorship
Created by David Dollar
Patches contributed by:
* Adam Wiggins
* Dan Peterson
* Hunter Nield
* Jay Zeschin
* Keith Rarick
* Khaja Minhajuddin
* Matt Haynes
* Michael van Rooijen
* Mike Javorski
* Nathan L Smith
* Nick Zadrozny
* Ricardo Chimal, Jr
* Thom May
* clifff
* Greg Reinacker
## License
MIT

39
README.md Normal file
View File

@@ -0,0 +1,39 @@
# Foreman
Manage Procfile-based applications
<table>
<tr>
<th>If you have...</th>
<th>Install with...</th>
</tr>
<tr>
<td>Ruby (MRI, JRuby, Windows)</td>
<td><pre>$ gem install foreman</pre></td>
</tr>
<tr>
<td>Mac OS X</td>
<td><a href="http://assets.foreman.io/foreman/foreman.pkg">foreman.pkg</a></td>
</tr>
</table>
## Getting Started
* http://blog.daviddollar.org/2011/05/06/introducing-foreman.html
## Documentation
* [man page](http://ddollar.github.com/foreman)
* [wiki](http://github.com/ddollar/foreman/wiki)
## 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, 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
## License
MIT

185
Rakefile
View File

@@ -1,187 +1,6 @@
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"
end
desc "Commit the manual to git"
task "man:commit" => :man do
sh "git add README.markdown"
sh "git commit -m 'update readme' || echo 'nothing to commit'"
end
desc "Generate the Github docs"
task :pages => "man:commit" 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 "saving man page to github docs"
git push origin -f gh-pages
git checkout master
}
end
## dist
require "erb"
require "fileutils"
require "tmpdir"
def assemble(source, target, perms=0644)
FileUtils.mkdir_p(File.dirname(target))
File.open(target, "w") do |f|
f.puts ERB.new(File.read(source)).result(binding)
end
File.chmod(perms, target)
end
def assemble_distribution(target_dir=Dir.pwd)
distribution_files.each do |source|
target = source.gsub(/^#{project_root}/, target_dir)
FileUtils.mkdir_p(File.dirname(target))
FileUtils.cp(source, target)
end
end
GEM_BLACKLIST = %w( bundler foreman )
def assemble_gems(target_dir=Dir.pwd)
lines = %x{ bundle show }.strip.split("\n")
raise "error running bundler" unless $?.success?
%x{ env BUNDLE_WITHOUT="development:test" bundle show }.split("\n").each do |line|
if line =~ /^ \* (.*?) \((.*?)\)/
next if GEM_BLACKLIST.include?($1)
puts "vendoring: #{$1}-#{$2}"
gem_dir = %x{ bundle show #{$1} }.strip
FileUtils.mkdir_p "#{target_dir}/vendor/gems"
%x{ cp -R "#{gem_dir}" "#{target_dir}/vendor/gems" }
end
end.compact
end
def beta?
Foreman::VERSION.to_s =~ /pre/
end
def clean(file)
rm file if File.exists?(file)
end
def distribution_files(type=nil)
require "foreman/distribution"
base_files = Foreman::Distribution.files
type_files = type ?
Dir[File.expand_path("../dist/resources/#{type}/**/*", __FILE__)] :
[]
base_files.concat(type_files)
end
def mkchdir(dir)
FileUtils.mkdir_p(dir)
Dir.chdir(dir) do |dir|
yield(File.expand_path(dir))
end
end
def pkg(filename)
File.expand_path("../pkg/#{filename}", __FILE__)
end
def project_root
File.dirname(__FILE__)
end
def resource(name)
File.expand_path("../dist/resources/#{name}", __FILE__)
end
def s3_connect
return if @s3_connected
require "aws/s3"
unless ENV["DAVID_RELEASE_ACCESS"] && ENV["DAVID_RELEASE_SECRET"]
puts "please set DAVID_RELEASE_ACCESS and DAVID_RELEASE_SECRET in your environment"
exit 1
end
AWS::S3::Base.establish_connection!(
:access_key_id => ENV["DAVID_RELEASE_ACCESS"],
:secret_access_key => ENV["DAVID_RELEASE_SECRET"]
)
@s3_connected = true
end
def store(package_file, filename, bucket="assets.foreman.io")
s3_connect
puts "storing: #{filename}"
AWS::S3::S3Object.store(filename, File.open(package_file), bucket, :access => :public_read)
end
def tempdir
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
yield(dir)
end
end
end
def version
require "foreman/version"
Foreman::VERSION
end
Dir[File.expand_path("../dist/**/*.rake", __FILE__)].each do |rake|
import rake
end
task :changelog do
timestamp = Time.now.utc.strftime('%m/%d/%Y')
sha = `git log | head -1`.split(' ').last
changelog = ["#{version} #{timestamp} #{sha}"]
changelog << ('=' * changelog[0].length)
changelog << ''
last_sha = `cat Changelog | head -1`.split(' ').last
shortlog = `git log #{last_sha}..HEAD --pretty=format:'%s [%an]'`
changelog << shortlog.split("\n")
changelog.concat ['', '', '']
old_changelog = File.read('Changelog')
File.open('Changelog', 'w') do |file|
file.write(changelog.join("\n"))
file.write(old_changelog)
end
Dir[File.expand_path("../tasks/*.rake", __FILE__)].each do |task|
load task
end

View File

@@ -29,7 +29,7 @@ shift $((OPTIND-1))
command=$1
if [ "$1" == "" ]; then
if [ -z "$1" ]; then
usage
fi

View File

@@ -5,7 +5,7 @@ Bluepill.application("<%= app %>", :foreground => false, :log_file => "/var/log/
<% engine.procfile.entries.each do |process| %>
<% 1.upto(concurrency[process.name]) do |num| %>
<% port = engine.port_for(process, num, options[:port]) %>
<% port = engine.port_for(process, num, self.port) %>
app.process("<%= process.name %>-<%=num%>") do |process|
process.start_command = "<%= process.command.gsub("$PORT", port.to_s) %>"

15
dist/deb.rake vendored
View File

@@ -20,12 +20,6 @@ file pkg("/apt-#{version}/foreman-#{version}.deb") => distribution_files("deb")
deb = File.basename(t.name)
sh "ar -r #{t.name} debian-binary control.tar.gz data.tar.gz"
touch "Sources"
sh "apt-ftparchive packages . > Packages"
sh "gzip -c Packages > Packages.gz"
sh "apt-ftparchive release . > Release"
sh "gpg -abs -u 0F1B0520 -o Release.gpg Release"
end
end
@@ -37,12 +31,3 @@ task "deb:clean" do
clean pkg("foreman-#{version}.deb")
FileUtils.rm_rf("pkg/apt-#{version}") if Dir.exists?("pkg/apt-#{version}")
end
desc "Publish .deb to S3."
task "deb:release" => "deb:build" do |t|
Dir["pkg/apt-#{version}/*"].each do |file|
unless File.directory?(file)
store file, "apt/#{File.basename(file)}"
end
end
end

View File

@@ -1,10 +1,14 @@
require "foreman"
require "foreman/helpers"
require "foreman/engine"
require "foreman/export"
require "thor"
require "yaml"
class Foreman::CLI < Thor
include Foreman::Helpers
class_option :procfile, :type => :string, :aliases => "-f", :desc => "Default: Procfile"
desc "start", "Start the application"
@@ -36,22 +40,12 @@ class Foreman::CLI < Thor
method_option :port, :type => :numeric, :aliases => "-p"
method_option :user, :type => :string, :aliases => "-u"
method_option :template, :type => :string, :aliases => "-t"
method_option :concurrency, :type => :string, :aliases => "-c",
:banner => '"alpha=5,bar=3"'
method_option :concurrency, :type => :string, :aliases => "-c", :banner => '"alpha=5,bar=3"'
def export(format, location=nil)
check_procfile!
formatter = case format
when "inittab" then Foreman::Export::Inittab
when "upstart" then Foreman::Export::Upstart
when "bluepill" then Foreman::Export::Bluepill
when "runit" then Foreman::Export::Runit
else error "Unknown export format: #{format}."
end
formatter.new(engine).export(location, options)
formatter = Foreman::Export.formatter(format)
formatter.new(location, engine, options).export
rescue Foreman::Export::Exception => ex
error ex.message
end
@@ -60,7 +54,7 @@ class Foreman::CLI < Thor
def check
error "no processes defined" unless engine.procfile.entries.length > 0
display "valid procfile detected (#{engine.procfile.process_names.join(', ')})"
puts "valid procfile detected (#{engine.procfile.process_names.join(', ')})"
end
desc "run COMMAND", "Run a command using your application's environment"
@@ -90,19 +84,11 @@ private ######################################################################
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")

View File

@@ -73,14 +73,22 @@ private ######################################################################
def kill_all(signal="SIGTERM")
running_processes.each do |pid, process|
info "sending #{signal} to pid #{pid}"
Process.kill(signal, pid) rescue Errno::ESRCH
process.kill signal
end
end
def terminate_gracefully
return if @terminating
@terminating = true
info "sending SIGTERM to all processes"
kill_all "SIGTERM"
Timeout.timeout(5) { Process.waitall }
Timeout.timeout(5) do
while running_processes.length > 0
pid, status = Process.wait2
process = running_processes.delete(pid)
info "process terminated", process.name
end
end
rescue Timeout::Error
info "sending SIGKILL to all processes"
kill_all "SIGKILL"
@@ -93,7 +101,9 @@ private ######################################################################
loop do
rs, ws = IO.select(readers.values, [], [], 1)
(rs || []).each do |r|
ps, message = r.gets.split(",", 2)
data = r.gets
next unless data
ps, message = data.split(",", 2)
color = colors[ps.split(".").first]
info message, ps, color
end
@@ -110,16 +120,16 @@ private ######################################################################
process = running_processes.delete(pid)
info "process terminated", process.name
terminate_gracefully
kill_all
rescue Errno::ECHILD
end
def info(message, name="system", color=Term::ANSIColor.white)
print color
print "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(name)} | "
print Term::ANSIColor.reset
print message.chomp
puts ""
output = ""
output += color
output += "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(name)} | "
output += Term::ANSIColor.reset
output += message.chomp
puts output
end
def print(message=nil)
@@ -134,11 +144,6 @@ private ######################################################################
end
end
def error(message)
puts "ERROR: #{message}"
exit 1
end
def longest_process_name
@longest_process_name ||= begin
longest = procfile.process_names.map { |name| name.length }.sort.last
@@ -217,6 +222,11 @@ private ######################################################################
def apply_environment!
@environment.each { |k,v| ENV[k] = v }
end
def error(message)
puts "ERROR: #{message}"
exit 1
end
end
include Env

View File

@@ -1,9 +1,30 @@
require "foreman"
require "foreman/helpers"
module Foreman::Export
extend Foreman::Helpers
class Exception < ::Exception; end
def self.formatter(format)
begin
require "foreman/export/#{ format.tr('-', '_') }"
classy_format = classify(format)
formatter = constantize("Foreman::Export::#{ classy_format }")
rescue NameError => ex
error "Unknown export format: #{format} (no class Foreman::Export::#{ classy_format })."
rescue LoadError => ex
error "Unknown export format: #{format} (unable to load file 'foreman/export/#{ format.tr('-', '_') }')."
end
end
def self.error(message)
raise Foreman::Export::Exception.new(message)
end
end
require "foreman/export/base"
require "foreman/export/inittab"
require "foreman/export/upstart"

View File

@@ -3,10 +3,17 @@ require "foreman/utils"
class Foreman::Export::Base
attr_reader :engine
attr_reader :location, :engine, :app, :log, :port, :user, :template, :concurrency
def initialize(engine)
@engine = engine
def initialize(location, engine, options={})
@location = location
@engine = engine
@app = options[:app]
@log = options[:log]
@port = options[:port]
@user = options[:user]
@template = options[:template]
@concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])
end
def export

View File

@@ -3,23 +3,21 @@ require "foreman/export"
class Foreman::Export::Bluepill < Foreman::Export::Base
def export(location, options={})
def export
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}"
template_root = options[:template]
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}.pill"].each do |file|
say "cleaning up: #{file}"
FileUtils.rm(file)
end
concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])
master_template = export_template("bluepill", "master.pill.erb", template_root)
master_config = ERB.new(master_template).result(binding)
write_file "#{location}/#{app}.pill", master_config

View File

@@ -2,20 +2,18 @@ require "foreman/export"
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])
def export
app = self.app || File.basename(engine.directory)
user = self.user || app
log_root = self.log || "/var/log/#{app}"
inittab = []
inittab << "# ----- foreman #{app} processes -----"
engine.procfile.entries.inject(1) do |index, process|
1.upto(concurrency[process.name]) do |num|
1.upto(self.concurrency[process.name]) do |num|
id = app.slice(0, 2).upcase + sprintf("%02d", index)
port = engine.port_for(process, num, options[:port])
port = engine.port_for(process, num, self.port)
inittab << "#{id}:4:respawn:/bin/su - #{user} -c 'PORT=#{port} #{process.command} >> #{log_root}/#{process.name}-#{num}.log 2>&1'"
index += 1
end
@@ -26,12 +24,12 @@ class Foreman::Export::Inittab < Foreman::Export::Base
inittab = inittab.join("\n") + "\n"
if fname
if location == "-"
puts inittab
else
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
write_file(location, inittab)
end
end

View File

@@ -4,21 +4,19 @@ require "foreman/export"
class Foreman::Export::Runit < Foreman::Export::Base
ENV_VARIABLE_REGEX = /([a-zA-Z_]+[a-zA-Z0-9_]*)=(\S+)/
def export(location, options={})
def export
error("Must specify a location") unless location
app = options[:app] || File.basename(engine.directory)
user = options[:user] || app
log_root = options[:log] || "/var/log/#{app}"
template_root = options[:template]
concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])
app = self.app || File.basename(engine.directory)
user = self.user || app
log_root = self.log || "/var/log/#{app}"
template_root = self.template
run_template = export_template('runit', 'run.erb', template_root)
log_run_template = export_template('runit', 'log_run.erb', template_root)
engine.procfile.entries.each do |process|
1.upto(concurrency[process.name]) do |num|
1.upto(self.concurrency[process.name]) do |num|
process_directory = "#{location}/#{app}-#{process.name}-#{num}"
process_env_directory = "#{process_directory}/env"
process_log_directory = "#{process_directory}/log"
@@ -31,7 +29,7 @@ class Foreman::Export::Runit < Foreman::Export::Base
write_file "#{process_directory}/run", run
FileUtils.chmod 0755, "#{process_directory}/run"
port = engine.port_for(process, num, options[:port])
port = engine.port_for(process, num, self.port)
environment_variables = {'PORT' => port}.
merge(engine.environment).
merge(inline_variables(process.command))
@@ -51,7 +49,7 @@ class Foreman::Export::Runit < Foreman::Export::Base
private
def create_directory(location)
say "creating: #{location}"
FileUtils.mkdir(location)
FileUtils.mkdir_p(location)
end
def inline_variables(command)

View File

@@ -3,23 +3,21 @@ require "foreman/export"
class Foreman::Export::Upstart < Foreman::Export::Base
def export(location, options={})
def export
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}"
template_root = options[:template]
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
concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])
master_template = export_template("upstart", "master.conf.erb", template_root)
master_config = ERB.new(master_template).result(binding)
write_file "#{location}/#{app}.conf", master_config
@@ -27,13 +25,13 @@ class Foreman::Export::Upstart < Foreman::Export::Base
process_template = export_template("upstart", "process.conf.erb", template_root)
engine.procfile.entries.each do |process|
next if (conc = concurrency[process.name]) < 1
next if (conc = self.concurrency[process.name]) < 1
process_master_template = export_template("upstart", "process_master.conf.erb", template_root)
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])
1.upto(self.concurrency[process.name]) do |num|
port = engine.port_for(process, num, self.port)
process_config = ERB.new(process_template).result(binding)
write_file "#{location}/#{app}-#{process.name}-#{num}.conf", process_config
end

45
lib/foreman/helpers.rb Normal file
View File

@@ -0,0 +1,45 @@
module Foreman::Helpers
# Copied whole sale from, https://github.com/defunkt/resque/
# Given a word with dashes, returns a camel cased version of it.
#
# classify('job-name') # => 'JobName'
def classify(dashed_word)
dashed_word.split('-').each { |part| part[0] = part[0].chr.upcase }.join
end # Tries to find a constant with the name specified in the argument string:
#
# constantize("Module") # => Module
# constantize("Test::Unit") # => Test::Unit
#
# The name is assumed to be the one of a top-level constant, no matter
# whether it starts with "::" or not. No lexical context is taken into
# account:
#
# C = 'outside'
# module M
# C = 'inside'
# C # => 'inside'
# constantize("C") # => 'outside', same as ::C
# end
#
# NameError is raised when the constant is unknown.
def constantize(camel_cased_word)
camel_cased_word = camel_cased_word.to_s
names = camel_cased_word.split('::')
names.shift if names.empty? || names.first.empty?
constant = Object
names.each do |name|
args = Module.method(:const_get).arity != 1 ? [false] : []
if constant.const_defined?(name, *args)
constant = constant.const_get(name)
else
constant = constant.const_missing(name)
end
end
constant
end
end

View File

@@ -24,6 +24,24 @@ class Foreman::Process
"%s.%s" % [ entry.name, num ]
end
def kill(signal)
pid && Process.kill(signal, pid)
rescue Errno::ESRCH
false
end
def detach
pid && Process.detach(pid)
end
def alive?
kill(0)
end
def dead?
!alive?
end
private
def fork_with_io(command, basedir)
@@ -45,7 +63,7 @@ private
$stderr.reopen writer
reader.close
exec Foreman.runner, "-d", basedir, command
end
end
end
[ reader, pid ]
end
@@ -69,12 +87,10 @@ private
end
def with_environment(environment)
old_env = ENV.each_pair.inject({}) { |h,(k,v)| h.update(k => v) }
environment.each { |k,v| ENV[k] = v }
ret = yield
ENV.clear
old_env.each { |k,v| ENV[k] = v}
ret
original = ENV.to_hash
ENV.update environment
yield
ensure
ENV.replace original
end
end

View File

@@ -1,5 +1,5 @@
module Foreman
VERSION = "0.37.0.pre3"
VERSION = "0.37.0"
end

View File

@@ -1,7 +1,7 @@
require "spec_helper"
require "foreman/cli"
describe "Foreman::CLI" do
describe "Foreman::CLI", :fakefs do
subject { Foreman::CLI.new }
describe "start" do
@@ -27,10 +27,21 @@ describe "Foreman::CLI" do
describe "export" do
describe "options" do
it "uses .foreman" do
write_procfile
File.open(".foreman", "w") { |f| f.puts "concurrency: alpha=2" }
mock_export = mock(Foreman::Export::Upstart)
mock(Foreman::Export::Upstart).new("/upstart", is_a(Foreman::Engine), { "concurrency" => "alpha=2" }) { mock_export }
mock_export.export
foreman %{ export upstart /upstart }
end
it "respects --env" do
write_procfile
write_env("envfile")
mock.instance_of(Foreman::Export::Upstart).export("/upstart", { "env" => "envfile" })
mock_export = mock(Foreman::Export::Upstart)
mock(Foreman::Export::Upstart).new("/upstart", is_a(Foreman::Engine), { "env" => "envfile" }) { mock_export }
mock_export.export
foreman %{ export upstart /upstart --env envfile }
end
end
@@ -47,10 +58,18 @@ describe "Foreman::CLI" do
describe "with a Procfile" do
before(:each) { write_procfile }
describe "with an invalid formatter" do
describe "with a formatter with a generic error" do
before do
mock(Foreman::Export).formatter("errorful") { Class.new(Foreman::Export::Base) do
def export
raise Foreman::Export::Exception.new("foo")
end
end }
end
it "prints an error" do
mock_error(subject, "Unknown export format: invalidformatter.") do
subject.export("invalidformatter")
mock_error(subject, "foo") do
subject.export("errorful")
end
end
end
@@ -60,7 +79,9 @@ describe "Foreman::CLI" do
it "runs successfully" do
dont_allow(subject).error
mock.instance_of(Foreman::Export::Upstart).export("/tmp/foo", {})
mock_export = mock(Foreman::Export::Upstart)
mock(Foreman::Export::Upstart).new("/tmp/foo", is_a(Foreman::Engine), {}) { mock_export }
mock_export.export
subject.export("upstart", "/tmp/foo")
end
end
@@ -72,7 +93,7 @@ describe "Foreman::CLI" do
before { write_procfile }
it "displays the jobs" do
mock(subject).display("valid procfile detected (alpha, bravo)")
mock(subject).puts("valid procfile detected (alpha, bravo)")
subject.check
end
end
@@ -89,47 +110,47 @@ describe "Foreman::CLI" do
end
end
end
describe "run" do
describe "with a valid Procfile" do
before { write_procfile }
describe "and a command" do
let(:command) { ["ls", "-l"] }
before(:each) do
stub(subject).exec
end
it "should load the environment file" do
write_env
preserving_env do
subject.run *command
ENV["FOO"].should == "bar"
end
ENV["FOO"].should be_nil
end
it "should runute the command as a string" do
mock(subject).exec(command.join(" "))
subject.run *command
end
end
describe "and a non-existent command" do
let(:command) { "iuhtngrglhulhdfg" }
it "should print an error" do
mock_error(subject, "command not found: #{command}") do
subject.run command
end
end
end
describe "and a non-executable command" do
let(:command) { __FILE__ }
it "should print an error" do
mock_error(subject, "not executable: #{command}") do
subject.run command

View File

@@ -1,7 +1,7 @@
require "spec_helper"
require "foreman/engine"
describe "Foreman::Engine" do
describe "Foreman::Engine", :fakefs do
subject { Foreman::Engine.new("Procfile", {}) }
describe "initialize" do

View File

@@ -0,0 +1,22 @@
require "spec_helper"
require "foreman/export/base"
describe "Foreman::Export::Base" do
let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
let(:location) { "/tmp/init" }
let(:engine) { Foreman::Engine.new(procfile) }
let(:subject) { Foreman::Export::Base.new(location, engine) }
it "has a say method for displaying info" do
mock(subject).puts("[foreman export] foo")
subject.send(:say, "foo")
end
it "export needs to be overridden" do
lambda { subject.export }.should raise_error("export method must be overridden")
end
it "raises errors as a Foreman::Export::Exception" do
lambda { subject.send(:error, "foo") }.should raise_error(Foreman::Export::Exception, "foo")
end
end

View File

@@ -3,22 +3,34 @@ require "foreman/engine"
require "foreman/export/bluepill"
require "tmpdir"
describe Foreman::Export::Bluepill do
describe Foreman::Export::Bluepill, :fakefs do
let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
let(:engine) { Foreman::Engine.new(procfile) }
let(:bluepill) { Foreman::Export::Bluepill.new(engine) }
let(:engine) { Foreman::Engine.new(procfile) }
let(:options) { Hash.new }
let(:bluepill) { Foreman::Export::Bluepill.new("/tmp/init", engine, options) }
before(:each) { load_export_templates_into_fakefs("bluepill") }
before(:each) { stub(bluepill).say }
it "exports to the filesystem" do
bluepill.export("/tmp/init")
bluepill.export
normalize_space(File.read("/tmp/init/app.pill")).should == normalize_space(example_export_file("bluepill/app.pill"))
end
it "exports to the filesystem with concurrency" do
bluepill.export("/tmp/init", :concurrency => "alpha=2")
normalize_space(File.read("/tmp/init/app.pill")).should == normalize_space(example_export_file("bluepill/app-concurrency.pill"))
it "cleans up if exporting into an existing dir" do
mock(FileUtils).rm("/tmp/init/app.pill")
bluepill.export
bluepill.export
end
end
context "with concurrency" do
let(:options) { Hash[:concurrency => "alpha=2"] }
it "exports to the filesystem with concurrency" do
bluepill.export
normalize_space(File.read("/tmp/init/app.pill")).should == normalize_space(example_export_file("bluepill/app-concurrency.pill"))
end
end
end

View File

@@ -0,0 +1,40 @@
require "spec_helper"
require "foreman/engine"
require "foreman/export/inittab"
require "tmpdir"
describe Foreman::Export::Inittab, :fakefs do
let(:location) { "/tmp/inittab" }
let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
let(:location) { "/tmp/inittab" }
let(:engine) { Foreman::Engine.new(procfile) }
let(:options) { Hash.new }
let(:inittab) { Foreman::Export::Inittab.new(location, engine, options) }
before(:each) { load_export_templates_into_fakefs("inittab") }
before(:each) { stub(inittab).say }
it "exports to the filesystem" do
inittab.export
File.read("/tmp/inittab").should == example_export_file("inittab/inittab.default")
end
context "to stdout" do
let(:location) { "-" }
it "exports to stdout" do
mock(inittab).puts example_export_file("inittab/inittab.default")
inittab.export
end
end
context "with concurrency" do
let(:options) { Hash[:concurrency => "alpha=2"] }
it "exports to the filesystem with concurrency" do
inittab.export
File.read("/tmp/inittab").should == example_export_file("inittab/inittab.concurrency")
end
end
end

View File

@@ -3,34 +3,39 @@ require "foreman/engine"
require "foreman/export/runit"
require "tmpdir"
describe Foreman::Export::Runit do
describe Foreman::Export::Runit, :fakefs do
let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile", 'bar=baz') }
let(:engine) { Foreman::Engine.new(procfile) }
let(:runit) { Foreman::Export::Runit.new(engine) }
let(:runit) { Foreman::Export::Runit.new('/tmp/init', engine, :concurrency => 'alpha=2,bravo=1') }
before(:each) { load_export_templates_into_fakefs("runit") }
before(:each) { stub(runit).say }
before(:each) { stub(FakeFS::FileUtils).chmod }
it "exports to the filesystem" do
FileUtils.mkdir_p('/tmp/init')
runit.export('/tmp/init', :concurrency => "alpha=2,bravo=1")
runit.export
File.read("/tmp/init/app-alpha-1/run").should == example_export_file('runit/app-alpha-1-run')
File.read("/tmp/init/app-alpha-1/log/run").should ==
File.read("/tmp/init/app-alpha-1/log/run").should ==
example_export_file('runit/app-alpha-1-log-run')
File.read("/tmp/init/app-alpha-1/env/PORT").should == "5000\n"
File.read("/tmp/init/app-alpha-1/env/BAR").should == "baz\n"
File.read("/tmp/init/app-alpha-2/run").should == example_export_file('runit/app-alpha-2-run')
File.read("/tmp/init/app-alpha-2/log/run").should ==
File.read("/tmp/init/app-alpha-2/log/run").should ==
example_export_file('runit/app-alpha-2-log-run')
File.read("/tmp/init/app-alpha-2/env/PORT").should == "5001\n"
File.read("/tmp/init/app-alpha-2/env/BAR").should == "baz\n"
File.read("/tmp/init/app-bravo-1/run").should == example_export_file('runit/app-bravo-1-run')
File.read("/tmp/init/app-bravo-1/log/run").should ==
File.read("/tmp/init/app-bravo-1/log/run").should ==
example_export_file('runit/app-bravo-1-log-run')
File.read("/tmp/init/app-bravo-1/env/PORT").should == "5100\n"
end
end
it "creates a full path to the export directory" do
expect { runit.export }.to_not raise_error(Errno::ENOENT)
end
end

View File

@@ -3,16 +3,17 @@ require "foreman/engine"
require "foreman/export/upstart"
require "tmpdir"
describe Foreman::Export::Upstart do
describe Foreman::Export::Upstart, :fakefs do
let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
let(:engine) { Foreman::Engine.new(procfile) }
let(:upstart) { Foreman::Export::Upstart.new(engine) }
let(:engine) { Foreman::Engine.new(procfile) }
let(:options) { Hash.new }
let(:upstart) { Foreman::Export::Upstart.new("/tmp/init", engine, options) }
before(:each) { load_export_templates_into_fakefs("upstart") }
before(:each) { stub(upstart).say }
it "exports to the filesystem" do
upstart.export("/tmp/init")
upstart.export
File.read("/tmp/init/app.conf").should == example_export_file("upstart/app.conf")
File.read("/tmp/init/app-alpha.conf").should == example_export_file("upstart/app-alpha.conf")
@@ -21,18 +22,34 @@ describe Foreman::Export::Upstart do
File.read("/tmp/init/app-bravo-1.conf").should == example_export_file("upstart/app-bravo-1.conf")
end
it "exports to the filesystem with concurrency" do
upstart.export("/tmp/init", :concurrency => "alpha=2")
it "cleans up if exporting into an existing dir" do
mock(FileUtils).rm("/tmp/init/app.conf")
mock(FileUtils).rm("/tmp/init/app-alpha.conf")
mock(FileUtils).rm("/tmp/init/app-alpha-1.conf")
mock(FileUtils).rm("/tmp/init/app-bravo.conf")
mock(FileUtils).rm("/tmp/init/app-bravo-1.conf")
File.read("/tmp/init/app.conf").should == example_export_file("upstart/app.conf")
File.read("/tmp/init/app-alpha.conf").should == example_export_file("upstart/app-alpha.conf")
File.read("/tmp/init/app-alpha-1.conf").should == example_export_file("upstart/app-alpha-1.conf")
File.read("/tmp/init/app-alpha-2.conf").should == example_export_file("upstart/app-alpha-2.conf")
File.exists?("/tmp/init/app-bravo-1.conf").should == false
upstart.export
upstart.export
end
context "with concurrency" do
let(:options) { Hash[:concurrency => "alpha=2"] }
it "exports to the filesystem with concurrency" do
upstart.export
File.read("/tmp/init/app.conf").should == example_export_file("upstart/app.conf")
File.read("/tmp/init/app-alpha.conf").should == example_export_file("upstart/app-alpha.conf")
File.read("/tmp/init/app-alpha-1.conf").should == example_export_file("upstart/app-alpha-1.conf")
File.read("/tmp/init/app-alpha-2.conf").should == example_export_file("upstart/app-alpha-2.conf")
File.exists?("/tmp/init/app-bravo-1.conf").should == false
end
end
context "with alternate templates" do
let(:template_root) { "/tmp/alternate" }
let(:upstart) { Foreman::Export::Upstart.new("/tmp/init", engine, :template => template_root) }
before do
FileUtils.mkdir_p template_root
@@ -40,7 +57,7 @@ describe Foreman::Export::Upstart do
end
it "can export with alternate template files" do
upstart.export("/tmp/init", :template => template_root)
upstart.export
File.read("/tmp/init/app.conf").should == "alternate_template\n"
end
@@ -61,7 +78,7 @@ describe Foreman::Export::Upstart do
end
it "can export with alternate template files" do
upstart.export("/tmp/init")
upstart.export
File.read("/tmp/init/app.conf").should == "default_alternate_template\n"
end

View File

@@ -1,2 +1,24 @@
require "spec_helper"
require "foreman/export"
describe "Foreman::Export" do
subject { Foreman::Export }
describe "with a formatter that doesn't declare the appropriate class" do
it "prints an error" do
mock(subject).require("foreman/export/invalidformatter")
mock_export_error("Unknown export format: invalidformatter (no class Foreman::Export::Invalidformatter).") do
subject.formatter("invalidformatter")
end
end
end
describe "with an invalid formatter" do
it "prints an error" do
mock_export_error("Unknown export format: invalidformatter (unable to load file 'foreman/export/invalidformatter').") do
subject.formatter("invalidformatter")
end
end
end
end

View File

@@ -0,0 +1,26 @@
require "spec_helper"
require "foreman/helpers"
describe "Foreman::Helpers" do
before do
module Foo
class Bar; end
end
end
after do
Object.send(:remove_const, :Foo)
end
subject { o = Object.new; o.extend(Foreman::Helpers); o }
it "should classify words" do
subject.classify("foo").should == "Foo"
subject.classify("foo-bar").should == "FooBar"
end
it "should constantize words" do
subject.constantize("Object").should == Object
subject.constantize("Foo::Bar").should == Foo::Bar
end
end

View File

@@ -1,2 +1,131 @@
require "spec_helper"
require "foreman/process"
require 'spec_helper'
require 'foreman/process'
require 'ostruct'
require 'timeout'
require 'tmpdir'
describe Foreman::Process do
subject { described_class.new entry, number, port }
let(:number) { 1 }
let(:port) { 777 }
let(:command) { "script" }
let(:name) { "foobar" }
let(:entry) { OpenStruct.new :name => name, :command => command }
its(:entry) { entry }
its(:num) { number }
its(:port) { port }
its(:name) { "#{name}.#{port}" }
its(:pid) { nil }
describe '#run' do
let(:pipe) { :pipe }
let(:basedir) { Dir.mktmpdir }
let(:env) {{ 'foo' => 'bar' }}
let(:init_delta) { 0.1 }
after { FileUtils.remove_entry_secure basedir }
def run(cmd=command)
entry.command = cmd
subject.run pipe, basedir, env
subject.detach && sleep(init_delta)
end
def run_file(executable, code)
file = File.open("#{basedir}/script", 'w') {|it| it << code }
run "#{executable} #{file.path}"
end
context 'options' do
it 'should set PORT for environment' do
mock(subject).run_process(basedir, command, pipe) do
ENV['PORT'].should == port.to_s
end
run
end
it 'should set custom variables for environment' do
mock(subject).run_process(basedir, command, pipe) do
ENV['foo'].should == 'bar'
end
run
end
it 'should restore environment afterwards' do
mock(subject).run_process(basedir, command, pipe)
run
ENV.should_not include('PORT', 'foo')
end
end
context 'process' do
around do |spec|
IO.pipe do |reader, writer|
@reader, @writer = reader, writer
spec.run
end
end
let(:pipe) { @writer }
let(:output) { @reader.read_nonblock 1024 }
it 'should not block' do
expect {
Timeout.timeout(2*init_delta) { run 'sleep 2' }
}.should_not raise_exception
end
it 'should be alive' do
run 'sleep 1'
subject.should be_alive
end
it 'should be dead' do
run 'exit'
subject.should be_dead
end
it 'should be killable' do
run 'sleep 1'
subject.kill 'TERM'
subject.should be_dead
end
it 'should send different signals' do
run_file 'ruby', <<-CODE
trap "TERM", "IGNORE"
loop { sleep 1 }
CODE
sleep 1 # wait for ruby to start
subject.should be_alive
subject.kill 'TERM'
subject.should be_alive
subject.kill 'KILL'
subject.should be_dead
end
it 'should redirect stdout' do
run 'echo hey'
output.should include('hey')
end
it 'should redirect stderr' do
run 'echo hey >2'
output.should include('hey')
end
it 'should handle variables' do
run 'echo $PORT'
output.should include('777')
end
it 'should handle arguments' do
pending
run %{ sh -c "trap '' TERM; sleep 10" }
subject.should be_alive
end
end
end
end

View File

@@ -8,13 +8,8 @@ describe Foreman do
it { should be_a String }
end
describe "::load_env!(env_file)" do
before do
FakeFS.activate!
end
describe "::load_env!(env_file)", :fakefs do
after do
FakeFS.deactivate!
ENV['FOO'] = nil
end
@@ -22,7 +17,7 @@ describe Foreman do
File.open("/tmp/env1", "w") { |f| f.puts("FOO=bar") }
Foreman.load_env!("/tmp/env1")
ENV['FOO'].should == 'bar'
end
end
it "should assume env_file in ./.env" do
File.open("./.env", "w") { |f| f.puts("FOO=bar") }
@@ -30,4 +25,10 @@ describe Foreman do
ENV['FOO'].should == 'bar'
end
end
describe "runner" do
it "should exist" do
File.exists?(Foreman.runner).should == true
end
end
end

View File

@@ -3,16 +3,16 @@ require "spec_helper"
describe "spec helpers" do
describe "#preserving_env" do
after { ENV.delete "FOO" }
it "should remove added environment vars" do
preserving_env { ENV["FOO"] = "baz" }
ENV["FOO"].should == nil
end
it "should reset modified environment vars" do
ENV["FOO"] = "bar"
preserving_env { ENV["FOO"] = "baz"}
ENV["FOO"].should == "bar"
end
end
end
end

View File

@@ -0,0 +1,4 @@
# ----- foreman app processes -----
AP01:4:respawn:/bin/su - app -c 'PORT=5000 ./alpha >> /var/log/app/alpha-1.log 2>&1'
AP02:4:respawn:/bin/su - app -c 'PORT=5001 ./alpha >> /var/log/app/alpha-2.log 2>&1'
# ----- end foreman app processes -----

View File

@@ -0,0 +1,4 @@
# ----- foreman app processes -----
AP01:4:respawn:/bin/su - app -c 'PORT=5000 ./alpha >> /var/log/app/alpha-1.log 2>&1'
AP02:4:respawn:/bin/su - app -c 'PORT=5100 ./bravo >> /var/log/app/bravo-1.log 2>&1'
# ----- end foreman app processes -----

View File

@@ -1,10 +1,20 @@
require "rubygems"
require "simplecov"
SimpleCov.start do
add_filter "/spec/"
end
require "rspec"
require "fakefs/safe"
require "fakefs/spec_helpers"
$:.unshift File.expand_path("../../lib", __FILE__)
def mock_export_error(message)
lambda { yield }.should raise_error(Foreman::Export::Exception, message)
end
def mock_error(subject, message)
mock_exit do
mock(subject).puts("ERROR: #{message}")
@@ -37,9 +47,11 @@ def write_procfile(procfile="Procfile", alpha_env="")
File.expand_path(procfile)
end
def write_env(env=".env")
def write_env(env=".env", options={"FOO"=>"bar"})
File.open(env, "w") do |file|
file.puts "FOO=bar"
options.each do |key, val|
file.puts "#{key}=#{val}"
end
end
end
@@ -76,10 +88,11 @@ end
def normalize_space(s)
s.gsub(/\n[\n\s]*/, "\n")
end
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.color_enabled = true
config.order = 'rand'
config.include FakeFS::SpecHelpers
config.include FakeFS::SpecHelpers, :fakefs
config.mock_with :rr
end

113
tasks/dist.rake Normal file
View File

@@ -0,0 +1,113 @@
require "erb"
require "fileutils"
require "tmpdir"
def assemble(source, target, perms=0644)
FileUtils.mkdir_p(File.dirname(target))
File.open(target, "w") do |f|
f.puts ERB.new(File.read(source)).result(binding)
end
File.chmod(perms, target)
end
def assemble_distribution(target_dir=Dir.pwd)
distribution_files.each do |source|
target = source.gsub(/^#{project_root}/, target_dir)
FileUtils.mkdir_p(File.dirname(target))
FileUtils.cp(source, target)
end
end
GEM_BLACKLIST = %w( bundler foreman )
def assemble_gems(target_dir=Dir.pwd)
lines = %x{ bundle show }.strip.split("\n")
raise "error running bundler" unless $?.success?
%x{ env BUNDLE_WITHOUT="development:test" bundle show }.split("\n").each do |line|
if line =~ /^ \* (.*?) \((.*?)\)/
next if GEM_BLACKLIST.include?($1)
puts "vendoring: #{$1}-#{$2}"
gem_dir = %x{ bundle show #{$1} }.strip
FileUtils.mkdir_p "#{target_dir}/vendor/gems"
%x{ cp -R "#{gem_dir}" "#{target_dir}/vendor/gems" }
end
end.compact
end
def beta?
Foreman::VERSION.to_s =~ /pre/
end
def clean(file)
rm file if File.exists?(file)
end
def distribution_files(type=nil)
require "foreman/distribution"
base_files = Foreman::Distribution.files
type_files = type ?
Dir[File.expand_path("../dist/resources/#{type}/**/*", __FILE__)] :
[]
base_files.concat(type_files)
end
def mkchdir(dir)
FileUtils.mkdir_p(dir)
Dir.chdir(dir) do |dir|
yield(File.expand_path(dir))
end
end
def pkg(filename)
File.expand_path("../pkg/#{filename}", __FILE__)
end
def project_root
File.dirname(__FILE__)
end
def resource(name)
File.expand_path("../dist/resources/#{name}", __FILE__)
end
def s3_connect
return if @s3_connected
require "aws/s3"
unless ENV["DAVID_RELEASE_ACCESS"] && ENV["DAVID_RELEASE_SECRET"]
puts "please set DAVID_RELEASE_ACCESS and DAVID_RELEASE_SECRET in your environment"
exit 1
end
AWS::S3::Base.establish_connection!(
:access_key_id => ENV["DAVID_RELEASE_ACCESS"],
:secret_access_key => ENV["DAVID_RELEASE_SECRET"]
)
@s3_connected = true
end
def store(package_file, filename, bucket="assets.foreman.io")
s3_connect
puts "storing: #{filename}"
AWS::S3::S3Object.store(filename, File.open(package_file), bucket, :access => :public_read)
end
def tempdir
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
yield(dir)
end
end
end
def version
require "foreman/version"
Foreman::VERSION
end
Dir[File.expand_path("../../dist/**/*.rake", __FILE__)].each do |rake|
import rake
end

81
tasks/release.rake Normal file
View File

@@ -0,0 +1,81 @@
require "time"
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"
end
desc "Commit the manual to git"
task "man:commit" => :man do
sh "git add README.markdown"
sh "git commit -m 'update readme' || echo 'nothing to commit'"
end
desc "Generate the Github docs"
task :pages => "man:commit" 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 "saving man page to github docs"
git push origin -f gh-pages
git checkout master
}
end
desc "Generate an authors list"
task :authors do
authors = %x{ git log --pretty=format:"%an" | sort -u }.split("\n")
puts authors.join(", ")
end
def latest_release
latest = File.read("Changelog.md").split("\n").first.split(" ").last
end
def newer_release
release = %x{ git tag --contains #{latest_release} }.split("\n")[1]
end
desc "Generate a Changelog"
task :changelog do
while release = newer_release
entry = %x{ git show --format="%h %cd" #{release} | head -n 1 }
commit, date_raw = entry.split(" ", 2)
date = Time.parse(date_raw).strftime("%Y-%m-%d")
message = "## #{release[1..-1]} #{date} #{commit}\n"
message += %x{ git log --format="%s [%an]" #{latest_release}..#{release} }
changelog = File.read("Changelog.md")
changelog = message + "\n" + changelog
File.open("Changelog.md", "w") do |file|
file.puts changelog
end
end
# date =
# message = "## #{release[1..-1]}
# timestamp = Time.now.utc.strftime('%m/%d/%Y')
# sha = `git log | head -1`.split(' ').last
# changelog = ["#{version} #{timestamp} #{sha}"]
# changelog << ('=' * changelog[0].length)
# changelog << ''
# last_sha = `cat Changelog | head -1`.split(' ').last
# shortlog = `git log #{last_sha}..HEAD --pretty=format:'%s [%an]'`
# changelog << shortlog.split("\n")
# changelog.concat ['', '', '']
# old_changelog = File.read('Changelog')
# File.open('Changelog', 'w') do |file|
# file.write(changelog.join("\n"))
# file.write(old_changelog)
# end
end

8
tasks/rspec.rake Normal file
View File

@@ -0,0 +1,8 @@
require "rspec/core/rake_task"
task :default => :spec
desc "Run all specs"
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = 'spec/**/*_spec.rb'
end