Compare commits
53
Commits
v0.28.0.pre2
...
v0.36.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1485eeb859 | ||
|
|
e0b5928e88 | ||
|
|
a73dce5405 | ||
|
|
2abddb42b3 | ||
|
|
d961a32cfe | ||
|
|
2bfc065c1d | ||
|
|
fbe3d4ec69 | ||
|
|
631187e0d8 | ||
|
|
92d1a4d367 | ||
|
|
f4123f4ae1 | ||
|
|
d4c2332c59 | ||
|
|
e257fc89c1 | ||
|
|
a278755ae4 | ||
|
|
3367a060a7 | ||
|
|
ac7e0743ac | ||
|
|
e574880814 | ||
|
|
7132cacbf6 | ||
|
|
c1f279aa6f | ||
|
|
34cfe9ef9d | ||
|
|
79fc3b8029 | ||
|
|
91140638e1 | ||
|
|
48cc60c30f | ||
|
|
533139ea9f | ||
|
|
86e2056a24 | ||
|
|
ab29963ee4 | ||
|
|
cf269c39da | ||
|
|
76cd2e794b | ||
|
|
83748cb538 | ||
|
|
d2c9ce0f34 | ||
|
|
98337c92e1 | ||
|
|
33d738b3f8 | ||
|
|
9432989fbe | ||
|
|
66b1483a75 | ||
|
|
64bd4db128 | ||
|
|
b561555f3a | ||
|
|
baa7b7685c | ||
|
|
cfa6e6f259 | ||
|
|
a34bc59721 | ||
|
|
07e8ca4a4b | ||
|
|
342d30bbb8 | ||
|
|
268dd6240e | ||
|
|
9e60b3e1a4 | ||
|
|
1c6285f8af | ||
|
|
5de1bd18ac | ||
|
|
fff15bc627 | ||
|
|
a66157d611 | ||
|
|
fcfa913fb0 | ||
|
|
fc438472f9 | ||
|
|
fc95936327 | ||
|
|
0c27f78d46 | ||
|
|
356c61f471 | ||
|
|
8bc8cb4b2e | ||
|
|
33aa1efc90 |
@@ -9,7 +9,7 @@ group :development do
|
|||||||
gem 'fakefs', '~> 0.3.2'
|
gem 'fakefs', '~> 0.3.2'
|
||||||
gem 'rcov', '~> 0.9.8'
|
gem 'rcov', '~> 0.9.8'
|
||||||
gem 'rr', '~> 1.0.2'
|
gem 'rr', '~> 1.0.2'
|
||||||
gem 'rspec', '~> 2.6.0'
|
gem 'rspec', '~> 2.0'
|
||||||
gem 'aws-s3'
|
gem 'aws-s3'
|
||||||
gem "rubyzip"
|
gem "rubyzip"
|
||||||
end
|
end
|
||||||
|
|||||||
+12
-12
@@ -1,8 +1,8 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
foreman (0.28.0.pre2)
|
foreman (0.36.1)
|
||||||
term-ansicolor (~> 1.0.5)
|
term-ansicolor (~> 1.0.7)
|
||||||
thor (>= 0.13.6)
|
thor (>= 0.13.6)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
@@ -14,7 +14,7 @@ GEM
|
|||||||
xml-simple
|
xml-simple
|
||||||
builder (3.0.0)
|
builder (3.0.0)
|
||||||
crack (0.1.8)
|
crack (0.1.8)
|
||||||
diff-lcs (1.1.2)
|
diff-lcs (1.1.3)
|
||||||
fakefs (0.3.2)
|
fakefs (0.3.2)
|
||||||
hpricot (0.8.2)
|
hpricot (0.8.2)
|
||||||
mime-types (1.16)
|
mime-types (1.16)
|
||||||
@@ -23,7 +23,7 @@ GEM
|
|||||||
crack
|
crack
|
||||||
rest-client
|
rest-client
|
||||||
thor
|
thor
|
||||||
rake (0.9.2)
|
rake (0.9.2.2)
|
||||||
rcov (0.9.8)
|
rcov (0.9.8)
|
||||||
rdiscount (1.6.5)
|
rdiscount (1.6.5)
|
||||||
rest-client (1.6.1)
|
rest-client (1.6.1)
|
||||||
@@ -33,14 +33,14 @@ GEM
|
|||||||
mustache (>= 0.7.0)
|
mustache (>= 0.7.0)
|
||||||
rdiscount (>= 1.5.8)
|
rdiscount (>= 1.5.8)
|
||||||
rr (1.0.2)
|
rr (1.0.2)
|
||||||
rspec (2.6.0)
|
rspec (2.8.0)
|
||||||
rspec-core (~> 2.6.0)
|
rspec-core (~> 2.8.0)
|
||||||
rspec-expectations (~> 2.6.0)
|
rspec-expectations (~> 2.8.0)
|
||||||
rspec-mocks (~> 2.6.0)
|
rspec-mocks (~> 2.8.0)
|
||||||
rspec-core (2.6.4)
|
rspec-core (2.8.0)
|
||||||
rspec-expectations (2.6.0)
|
rspec-expectations (2.8.0)
|
||||||
diff-lcs (~> 1.1.2)
|
diff-lcs (~> 1.1.2)
|
||||||
rspec-mocks (2.6.0)
|
rspec-mocks (2.8.0)
|
||||||
rubyzip (0.9.4)
|
rubyzip (0.9.4)
|
||||||
term-ansicolor (1.0.7)
|
term-ansicolor (1.0.7)
|
||||||
thor (0.14.6)
|
thor (0.14.6)
|
||||||
@@ -58,5 +58,5 @@ DEPENDENCIES
|
|||||||
rcov (~> 0.9.8)
|
rcov (~> 0.9.8)
|
||||||
ronn
|
ronn
|
||||||
rr (~> 1.0.2)
|
rr (~> 1.0.2)
|
||||||
rspec (~> 2.6.0)
|
rspec (~> 2.0)
|
||||||
rubyzip
|
rubyzip
|
||||||
|
|||||||
+2
-1
@@ -20,7 +20,8 @@ http://blog.daviddollar.org/2011/05/06/introducing-foreman.html
|
|||||||
|
|
||||||
## Manual
|
## Manual
|
||||||
|
|
||||||
See the [man page](http://ddollar.github.com/foreman) for usage.
|
* [man page](http://ddollar.github.com/foreman)
|
||||||
|
* [wiki](http://github.com/ddollar/foreman/wiki)
|
||||||
|
|
||||||
## Authorship
|
## Authorship
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -16,6 +16,6 @@ Gem::Specification.new do |gem|
|
|||||||
gem.files = Dir["**/*"].select { |d| d =~ %r{^(README|bin/|data/|ext/|lib/|spec/|test/)} }
|
gem.files = Dir["**/*"].select { |d| d =~ %r{^(README|bin/|data/|ext/|lib/|spec/|test/)} }
|
||||||
gem.files << "man/foreman.1"
|
gem.files << "man/foreman.1"
|
||||||
|
|
||||||
gem.add_dependency 'term-ansicolor', '~> 1.0.5'
|
gem.add_dependency 'term-ansicolor', '~> 1.0.7'
|
||||||
gem.add_dependency 'thor', '>= 0.13.6'
|
gem.add_dependency 'thor', '>= 0.13.6'
|
||||||
end
|
end
|
||||||
|
|||||||
+24
-3
@@ -6,14 +6,23 @@ require "yaml"
|
|||||||
|
|
||||||
class Foreman::CLI < Thor
|
class Foreman::CLI < Thor
|
||||||
|
|
||||||
class_option :procfile, :type => :string, :aliases => "-f", :desc => "Default: Procfile"
|
|
||||||
|
|
||||||
desc "start", "Start the application"
|
desc "start", "Start the application"
|
||||||
|
|
||||||
|
class_option :procfile, :type => :string, :aliases => "-f", :desc => "Default: Procfile"
|
||||||
|
class_option :app_root, :type => :string, :aliases => "-d", :desc => "Default: Procfile directory"
|
||||||
|
|
||||||
method_option :env, :type => :string, :aliases => "-e", :desc => "Specify an environment file to load, defaults to .env"
|
method_option :env, :type => :string, :aliases => "-e", :desc => "Specify an environment file to load, defaults to .env"
|
||||||
method_option :port, :type => :numeric, :aliases => "-p"
|
method_option :port, :type => :numeric, :aliases => "-p"
|
||||||
method_option :concurrency, :type => :string, :aliases => "-c", :banner => '"alpha=5,bar=3"'
|
method_option :concurrency, :type => :string, :aliases => "-c", :banner => '"alpha=5,bar=3"'
|
||||||
|
|
||||||
|
class << self
|
||||||
|
# Hackery. Take the run method away from Thor so that we can redefine it.
|
||||||
|
def is_thor_reserved_word?(word, type)
|
||||||
|
return false if word == 'run'
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
check_procfile!
|
check_procfile!
|
||||||
engine.start
|
engine.start
|
||||||
@@ -54,6 +63,19 @@ class Foreman::CLI < Thor
|
|||||||
display "valid procfile detected (#{engine.procfile.process_names.join(', ')})"
|
display "valid procfile detected (#{engine.procfile.process_names.join(', ')})"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "run COMMAND", "Run a command using your application's environment"
|
||||||
|
|
||||||
|
def run(*args)
|
||||||
|
engine.apply_environment!
|
||||||
|
begin
|
||||||
|
exec args.join(" ")
|
||||||
|
rescue Errno::EACCES
|
||||||
|
error "not executable: #{args.first}"
|
||||||
|
rescue Errno::ENOENT
|
||||||
|
error "command not found: #{args.first}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private ######################################################################
|
private ######################################################################
|
||||||
|
|
||||||
def check_procfile!
|
def check_procfile!
|
||||||
@@ -87,5 +109,4 @@ private ######################################################################
|
|||||||
defaults = YAML::load_file(".foreman") || {}
|
defaults = YAML::load_file(".foreman") || {}
|
||||||
Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
|
Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
+10
-5
@@ -7,6 +7,7 @@ require "tempfile"
|
|||||||
require "timeout"
|
require "timeout"
|
||||||
require "term/ansicolor"
|
require "term/ansicolor"
|
||||||
require "fileutils"
|
require "fileutils"
|
||||||
|
require "thread"
|
||||||
|
|
||||||
class Foreman::Engine
|
class Foreman::Engine
|
||||||
|
|
||||||
@@ -16,11 +17,13 @@ class Foreman::Engine
|
|||||||
|
|
||||||
extend Term::ANSIColor
|
extend Term::ANSIColor
|
||||||
|
|
||||||
COLORS = [ cyan, yellow, green, magenta, red ]
|
COLORS = [ cyan, yellow, green, magenta, red, blue,
|
||||||
|
intense_cyan, intense_yellow, intense_green, intense_magenta,
|
||||||
|
intense_red, intense_blue ]
|
||||||
|
|
||||||
def initialize(procfile, options={})
|
def initialize(procfile, options={})
|
||||||
@procfile = Foreman::Procfile.new(procfile)
|
@procfile = Foreman::Procfile.new(procfile)
|
||||||
@directory = File.expand_path(File.dirname(procfile))
|
@directory = options[:app_root] || File.expand_path(File.dirname(procfile))
|
||||||
@options = options
|
@options = options
|
||||||
@environment = read_environment_files(options[:env])
|
@environment = read_environment_files(options[:env])
|
||||||
@output_mutex = Mutex.new
|
@output_mutex = Mutex.new
|
||||||
@@ -57,7 +60,7 @@ private ######################################################################
|
|||||||
|
|
||||||
procfile.entries.each do |entry|
|
procfile.entries.each do |entry|
|
||||||
reader, writer = IO.pipe
|
reader, writer = IO.pipe
|
||||||
entry.spawn(concurrency[entry.name], writer, @directory, @environment, base_port).each do |process|
|
entry.spawn(concurrency[entry.name], writer, @directory, @environment, port_for(entry, 1, base_port)).each do |process|
|
||||||
running_processes[process.pid] = process
|
running_processes[process.pid] = process
|
||||||
readers[process] = reader
|
readers[process] = reader
|
||||||
end
|
end
|
||||||
@@ -70,6 +73,7 @@ private ######################################################################
|
|||||||
|
|
||||||
def kill_all(signal="SIGTERM")
|
def kill_all(signal="SIGTERM")
|
||||||
running_processes.each do |pid, process|
|
running_processes.each do |pid, process|
|
||||||
|
info "sending #{signal} to pid #{pid}"
|
||||||
Process.kill(signal, pid) rescue Errno::ESRCH
|
Process.kill(signal, pid) rescue Errno::ESRCH
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -115,7 +119,7 @@ private ######################################################################
|
|||||||
print "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(name)} | "
|
print "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(name)} | "
|
||||||
print Term::ANSIColor.reset
|
print Term::ANSIColor.reset
|
||||||
print message.chomp
|
print message.chomp
|
||||||
puts
|
puts ""
|
||||||
end
|
end
|
||||||
|
|
||||||
def print(message=nil)
|
def print(message=nil)
|
||||||
@@ -180,7 +184,8 @@ private ######################################################################
|
|||||||
def next_color
|
def next_color
|
||||||
@current_color ||= -1
|
@current_color ||= -1
|
||||||
@current_color += 1
|
@current_color += 1
|
||||||
@current_color >= COLORS.length ? "" : COLORS[@current_color]
|
@current_color = 0 if COLORS.length < @current_color
|
||||||
|
COLORS[@current_color]
|
||||||
end
|
end
|
||||||
|
|
||||||
module Env
|
module Env
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ private ######################################################################
|
|||||||
def export_template(exporter, file, template_root)
|
def export_template(exporter, file, template_root)
|
||||||
if template_root && File.exist?(file_path = File.join(template_root, file))
|
if template_root && File.exist?(file_path = File.join(template_root, file))
|
||||||
File.read(file_path)
|
File.read(file_path)
|
||||||
elsif File.exist?(file_path = File.join("~/.foreman/templates", file))
|
elsif File.exist?(file_path = File.expand_path(File.join("~/.foreman/templates", file)))
|
||||||
File.read(file_path)
|
File.read(file_path)
|
||||||
else
|
else
|
||||||
File.read(File.expand_path("../../../../data/export/#{exporter}/#{file}", __FILE__))
|
File.read(File.expand_path("../../../../data/export/#{exporter}/#{file}", __FILE__))
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class Foreman::Export::Runit < Foreman::Export::Base
|
|||||||
|
|
||||||
run = ERB.new(run_template).result(binding)
|
run = ERB.new(run_template).result(binding)
|
||||||
write_file "#{process_directory}/run", run
|
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, options[:port])
|
||||||
environment_variables = {'PORT' => port}.
|
environment_variables = {'PORT' => port}.
|
||||||
@@ -41,7 +42,7 @@ class Foreman::Export::Runit < Foreman::Export::Base
|
|||||||
|
|
||||||
log_run = ERB.new(log_run_template).result(binding)
|
log_run = ERB.new(log_run_template).result(binding)
|
||||||
write_file "#{process_log_directory}/run", log_run
|
write_file "#{process_log_directory}/run", log_run
|
||||||
|
FileUtils.chmod 0755, "#{process_log_directory}/run"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+14
-3
@@ -27,10 +27,21 @@ class Foreman::Process
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def fork_with_io(command)
|
||||||
|
reader, writer = IO.pipe
|
||||||
|
pid = fork do
|
||||||
|
trap("INT", "IGNORE")
|
||||||
|
writer.sync = true
|
||||||
|
$stdout.reopen writer
|
||||||
|
$stderr.reopen writer
|
||||||
|
reader.close
|
||||||
|
exec Foreman.runner, replace_command_env(command)
|
||||||
|
end
|
||||||
|
[ reader, pid ]
|
||||||
|
end
|
||||||
|
|
||||||
def run_process(command, pipe)
|
def run_process(command, pipe)
|
||||||
io = IO.popen([Foreman.runner, replace_command_env(command)], "w+")
|
io, @pid = fork_with_io(command)
|
||||||
@pid = io.pid
|
|
||||||
trap("SIGTERM") { "got sigterm for %d" % @pid }
|
|
||||||
output pipe, "started with pid %d" % @pid
|
output pipe, "started with pid %d" % @pid
|
||||||
Thread.new do
|
Thread.new do
|
||||||
until io.eof?
|
until io.eof?
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ class Foreman::Utils
|
|||||||
def self.parse_concurrency(concurrency)
|
def self.parse_concurrency(concurrency)
|
||||||
begin
|
begin
|
||||||
pairs = concurrency.to_s.gsub(/\s/, "").split(",")
|
pairs = concurrency.to_s.gsub(/\s/, "").split(",")
|
||||||
pairs.inject(Hash.new(1)) do |hash, pair|
|
|
||||||
|
default = concurrency.nil? ? 1 : 0
|
||||||
|
|
||||||
|
pairs.inject(Hash.new(default)) do |hash, pair|
|
||||||
process, amount = pair.split("=")
|
process, amount = pair.split("=")
|
||||||
hash.update(process => amount.to_i)
|
hash.update(process => amount.to_i)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Foreman
|
module Foreman
|
||||||
|
|
||||||
VERSION = "0.28.0.pre2"
|
VERSION = "0.36.1"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
+5
-1
@@ -1,7 +1,7 @@
|
|||||||
.\" generated with Ronn/v0.7.3
|
.\" generated with Ronn/v0.7.3
|
||||||
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
||||||
.
|
.
|
||||||
.TH "FOREMAN" "1" "November 2011" "Foreman 0.26.0" "Foreman Manual"
|
.TH "FOREMAN" "1" "January 2012" "Foreman 0.33.1" "Foreman Manual"
|
||||||
.
|
.
|
||||||
.SH "NAME"
|
.SH "NAME"
|
||||||
\fBforeman\fR \- manage Procfile\-based applications
|
\fBforeman\fR \- manage Procfile\-based applications
|
||||||
@@ -68,6 +68,10 @@ Specify the user the application should be run as\. Defaults to the app name
|
|||||||
These options control all modes of foreman\'s operation\.
|
These options control all modes of foreman\'s operation\.
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
|
\fB\-d\fR, \fB\-\-directory\fR
|
||||||
|
Specify an alternate application root\. This defaults to the directory containing the Procfile\.
|
||||||
|
.
|
||||||
|
.TP
|
||||||
\fB\-e\fR, \fB\-\-env\fR
|
\fB\-e\fR, \fB\-\-env\fR
|
||||||
Specify an alternate environment file\. You can specify more than one file by using: \fB\-\-env file1,file2\fR\.
|
Specify an alternate environment file\. You can specify more than one file by using: \fB\-\-env file1,file2\fR\.
|
||||||
.
|
.
|
||||||
|
|||||||
@@ -66,6 +66,10 @@ The following options control how the application is run:
|
|||||||
|
|
||||||
These options control all modes of foreman's operation.
|
These options control all modes of foreman's operation.
|
||||||
|
|
||||||
|
* `-d`, `--directory`:
|
||||||
|
Specify an alternate application root. This defaults to the directory
|
||||||
|
containing the Procfile.
|
||||||
|
|
||||||
* `-e`, `--env`:
|
* `-e`, `--env`:
|
||||||
Specify an alternate environment file. You can specify more than one
|
Specify an alternate environment file. You can specify more than one
|
||||||
file by using: `--env file1,file2`.
|
file by using: `--env file1,file2`.
|
||||||
|
|||||||
@@ -89,5 +89,54 @@ describe "Foreman::CLI" do
|
|||||||
end
|
end
|
||||||
end
|
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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ describe "Foreman::Engine" do
|
|||||||
write_procfile
|
write_procfile
|
||||||
engine = Foreman::Engine.new("Procfile",:concurrency => "alpha=2")
|
engine = Foreman::Engine.new("Procfile",:concurrency => "alpha=2")
|
||||||
mock.instance_of(Foreman::Process).run_process("./alpha", is_a(IO)).twice
|
mock.instance_of(Foreman::Process).run_process("./alpha", is_a(IO)).twice
|
||||||
mock.instance_of(Foreman::Process).run_process("./bravo", is_a(IO))
|
mock.instance_of(Foreman::Process).run_process("./bravo", is_a(IO)).never
|
||||||
mock(engine).watch_for_output
|
mock(engine).watch_for_output
|
||||||
mock(engine).watch_for_termination
|
mock(engine).watch_for_termination
|
||||||
engine.start
|
engine.start
|
||||||
|
|||||||
@@ -12,8 +12,13 @@ describe Foreman::Export::Bluepill do
|
|||||||
before(:each) { stub(bluepill).say }
|
before(:each) { stub(bluepill).say }
|
||||||
|
|
||||||
it "exports to the filesystem" do
|
it "exports to the filesystem" do
|
||||||
bluepill.export("/tmp/init", :concurrency => "alpha=2")
|
bluepill.export("/tmp/init")
|
||||||
File.read("/tmp/init/app.pill").should == example_export_file("bluepill/app.pill")
|
normalize_space(File.read("/tmp/init/app.pill")).should == normalize_space(example_export_file("bluepill/app.pill"))
|
||||||
end
|
end
|
||||||
|
|
||||||
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"))
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -10,10 +10,11 @@ describe Foreman::Export::Runit do
|
|||||||
|
|
||||||
before(:each) { load_export_templates_into_fakefs("runit") }
|
before(:each) { load_export_templates_into_fakefs("runit") }
|
||||||
before(:each) { stub(runit).say }
|
before(:each) { stub(runit).say }
|
||||||
|
before(:each) { stub(FakeFS::FileUtils).chmod }
|
||||||
|
|
||||||
it "exports to the filesystem" do
|
it "exports to the filesystem" do
|
||||||
FileUtils.mkdir_p('/tmp/init')
|
FileUtils.mkdir_p('/tmp/init')
|
||||||
runit.export('/tmp/init', :concurrency => 'alpha=2')
|
runit.export('/tmp/init', :concurrency => "alpha=2,bravo=1")
|
||||||
|
|
||||||
File.read("/tmp/init/app-alpha-1/run").should == example_export_file('runit/app-alpha-1-run')
|
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 ==
|
||||||
|
|||||||
@@ -12,14 +12,23 @@ describe Foreman::Export::Upstart do
|
|||||||
before(:each) { stub(upstart).say }
|
before(:each) { stub(upstart).say }
|
||||||
|
|
||||||
it "exports to the filesystem" do
|
it "exports to the filesystem" do
|
||||||
|
upstart.export("/tmp/init")
|
||||||
|
|
||||||
|
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-bravo.conf").should == example_export_file("upstart/app-bravo.conf")
|
||||||
|
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")
|
upstart.export("/tmp/init", :concurrency => "alpha=2")
|
||||||
|
|
||||||
File.read("/tmp/init/app.conf").should == example_export_file("upstart/app.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.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-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.read("/tmp/init/app-alpha-2.conf").should == example_export_file("upstart/app-alpha-2.conf")
|
||||||
File.read("/tmp/init/app-bravo.conf").should == example_export_file("upstart/app-bravo.conf")
|
File.exists?("/tmp/init/app-bravo-1.conf").should == false
|
||||||
File.read("/tmp/init/app-bravo-1.conf").should == example_export_file("upstart/app-bravo-1.conf")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with alternate templates" do
|
context "with alternate templates" do
|
||||||
@@ -38,13 +47,19 @@ describe Foreman::Export::Upstart do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "with alternate templates from home dir" do
|
context "with alternate templates from home dir" do
|
||||||
let(:default_template_root) {File.expand_path("~/.foreman/templates")}
|
let(:default_template_root) {File.expand_path("#{ENV['HOME']}/.foreman/templates")}
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
ENV['_FOREMAN_SPEC_HOME'] = ENV['HOME']
|
||||||
|
ENV['HOME'] = "/home/appuser"
|
||||||
FileUtils.mkdir_p default_template_root
|
FileUtils.mkdir_p default_template_root
|
||||||
File.open("#{default_template_root}/master.conf.erb", "w") { |f| f.puts "default_alternate_template" }
|
File.open("#{default_template_root}/master.conf.erb", "w") { |f| f.puts "default_alternate_template" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
ENV['HOME'] = ENV.delete('_FOREMAN_SPEC_HOME')
|
||||||
|
end
|
||||||
|
|
||||||
it "can export with alternate template files" do
|
it "can export with alternate template files" do
|
||||||
upstart.export("/tmp/init")
|
upstart.export("/tmp/init")
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
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
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
Bluepill.application("app", :foreground => false, :log_file => "/var/log/bluepill.log") do |app|
|
||||||
|
|
||||||
|
app.uid = "app"
|
||||||
|
app.gid = "app"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
app.process("alpha-1") do |process|
|
||||||
|
process.start_command = "./alpha"
|
||||||
|
|
||||||
|
process.working_dir = "/tmp/app"
|
||||||
|
process.daemonize = true
|
||||||
|
process.environment = {"PORT" => "5000"}
|
||||||
|
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
|
||||||
|
|
||||||
|
process.stdout = process.stderr = "/var/log/app/app-alpha-1.log"
|
||||||
|
|
||||||
|
process.monitor_children do |children|
|
||||||
|
children.stop_command "kill -QUIT {{PID}}"
|
||||||
|
end
|
||||||
|
|
||||||
|
process.group = "app-alpha"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
app.process("alpha-2") do |process|
|
||||||
|
process.start_command = "./alpha"
|
||||||
|
|
||||||
|
process.working_dir = "/tmp/app"
|
||||||
|
process.daemonize = true
|
||||||
|
process.environment = {"PORT" => "5001"}
|
||||||
|
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
|
||||||
|
|
||||||
|
process.stdout = process.stderr = "/var/log/app/app-alpha-2.log"
|
||||||
|
|
||||||
|
process.monitor_children do |children|
|
||||||
|
children.stop_command "kill -QUIT {{PID}}"
|
||||||
|
end
|
||||||
|
|
||||||
|
process.group = "app-alpha"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
@@ -23,27 +23,6 @@ Bluepill.application("app", :foreground => false, :log_file => "/var/log/bluepil
|
|||||||
process.group = "app-alpha"
|
process.group = "app-alpha"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
app.process("alpha-2") do |process|
|
|
||||||
process.start_command = "./alpha"
|
|
||||||
|
|
||||||
process.working_dir = "/tmp/app"
|
|
||||||
process.daemonize = true
|
|
||||||
process.environment = {"PORT" => "5001"}
|
|
||||||
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
|
|
||||||
|
|
||||||
process.stdout = process.stderr = "/var/log/app/app-alpha-2.log"
|
|
||||||
|
|
||||||
process.monitor_children do |children|
|
|
||||||
children.stop_command "kill -QUIT {{PID}}"
|
|
||||||
end
|
|
||||||
|
|
||||||
process.group = "app-alpha"
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.process("bravo-1") do |process|
|
app.process("bravo-1") do |process|
|
||||||
process.start_command = "./bravo"
|
process.start_command = "./bravo"
|
||||||
|
|
||||||
|
|||||||
@@ -63,8 +63,23 @@ def example_export_file(filename)
|
|||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def preserving_env
|
||||||
|
old_env = ENV.to_hash
|
||||||
|
begin
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
ENV.clear
|
||||||
|
ENV.update(old_env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def normalize_space(s)
|
||||||
|
s.gsub(/\n[\n\s]*/, "\n")
|
||||||
|
end
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.color_enabled = true
|
config.color_enabled = true
|
||||||
|
config.order = 'rand'
|
||||||
config.include FakeFS::SpecHelpers
|
config.include FakeFS::SpecHelpers
|
||||||
config.mock_with :rr
|
config.mock_with :rr
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user