Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2ba079665 | ||
|
|
c8d0dba1cb | ||
|
|
e8d2552caa | ||
|
|
927a57f738 | ||
|
|
f65538c1b1 | ||
|
|
470c8043af | ||
|
|
3e69b27f5f | ||
|
|
f4b1e3701b | ||
|
|
fd234b8044 | ||
|
|
f2f09554c8 | ||
|
|
6c465b4ef1 | ||
|
|
c419f8213b | ||
|
|
7f61fb61ea | ||
|
|
577a5c7c5c | ||
|
|
56940c56d9 | ||
|
|
f308ad886d | ||
|
|
55375b9bde | ||
|
|
85fcccffa8 |
+10
-12
@@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
foreman (0.16.0)
|
foreman (0.19.0)
|
||||||
term-ansicolor (~> 1.0.5)
|
term-ansicolor (~> 1.0.5)
|
||||||
thor (>= 0.13.6)
|
thor (>= 0.13.6)
|
||||||
|
|
||||||
@@ -28,16 +28,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.0.1)
|
rspec (2.6.0)
|
||||||
rspec-core (~> 2.0.1)
|
rspec-core (~> 2.6.0)
|
||||||
rspec-expectations (~> 2.0.1)
|
rspec-expectations (~> 2.6.0)
|
||||||
rspec-mocks (~> 2.0.1)
|
rspec-mocks (~> 2.6.0)
|
||||||
rspec-core (2.0.1)
|
rspec-core (2.6.4)
|
||||||
rspec-expectations (2.0.1)
|
rspec-expectations (2.6.0)
|
||||||
diff-lcs (>= 1.1.2)
|
diff-lcs (~> 1.1.2)
|
||||||
rspec-mocks (2.0.1)
|
rspec-mocks (2.6.0)
|
||||||
rspec-core (~> 2.0.1)
|
|
||||||
rspec-expectations (~> 2.0.1)
|
|
||||||
term-ansicolor (1.0.5)
|
term-ansicolor (1.0.5)
|
||||||
thor (0.14.6)
|
thor (0.14.6)
|
||||||
|
|
||||||
@@ -52,4 +50,4 @@ DEPENDENCIES
|
|||||||
rcov (~> 0.9.8)
|
rcov (~> 0.9.8)
|
||||||
ronn
|
ronn
|
||||||
rr (~> 1.0.2)
|
rr (~> 1.0.2)
|
||||||
rspec (~> 2.0.0)
|
rspec (~> 2.6.0)
|
||||||
|
|||||||
+9
-8
@@ -12,17 +12,18 @@ http://blog.daviddollar.org/2011/05/06/introducing-foreman.html
|
|||||||
|
|
||||||
See the [man page](http://ddollar.github.com/foreman) for usage.
|
See the [man page](http://ddollar.github.com/foreman) for usage.
|
||||||
|
|
||||||
## Author
|
## Authorship
|
||||||
|
|
||||||
David Dollar
|
Created by David Dollar
|
||||||
|
|
||||||
## Contributors
|
Patches contributed by:
|
||||||
|
|
||||||
Adam Wiggins
|
* Adam Wiggins
|
||||||
clifff
|
* clifff
|
||||||
Dan Peterson
|
* Dan Peterson
|
||||||
Keith Rarick
|
* Jay Zeschin
|
||||||
Ricardo Chimal, Jr
|
* Keith Rarick
|
||||||
|
* Ricardo Chimal, Jr
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ task :default => :spec
|
|||||||
task :release => :man
|
task :release => :man
|
||||||
|
|
||||||
desc "Run all specs"
|
desc "Run all specs"
|
||||||
Rspec::Core::RakeTask.new(:spec) do |t|
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
||||||
t.pattern = 'spec/**/*_spec.rb'
|
t.pattern = 'spec/**/*_spec.rb'
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ task :rcov => "rcov:build" do
|
|||||||
%x{ open coverage/index.html }
|
%x{ open coverage/index.html }
|
||||||
end
|
end
|
||||||
|
|
||||||
Rspec::Core::RakeTask.new("rcov:build") do |t|
|
RSpec::Core::RakeTask.new("rcov:build") do |t|
|
||||||
t.pattern = 'spec/**/*_spec.rb'
|
t.pattern = 'spec/**/*_spec.rb'
|
||||||
t.rcov = true
|
t.rcov = true
|
||||||
t.rcov_opts = [ "--exclude", ".bundle", "--exclude", "spec" ]
|
t.rcov_opts = [ "--exclude", ".bundle", "--exclude", "spec" ]
|
||||||
|
|||||||
Executable
+2
@@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
exec ARGV.join(" ")
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
%w( SIGINT SIGTERM SIGHUP ).each do |signal|
|
||||||
|
trap(signal) do
|
||||||
|
puts "received #{signal} but i'm ignoring it!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
while true
|
while true
|
||||||
puts "tick: #{ARGV.inspect} -- FOO:#{ENV["FOO"]}"
|
puts "tick: #{ARGV.inspect} -- FOO:#{ENV["FOO"]}"
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|||||||
@@ -2,5 +2,4 @@ start on starting <%= app %>-<%= process.name %>
|
|||||||
stop on stopping <%= app %>-<%= process.name %>
|
stop on stopping <%= app %>-<%= process.name %>
|
||||||
respawn
|
respawn
|
||||||
|
|
||||||
chdir <%= engine.directory %>
|
exec su - <%= user %> -c 'cd <%= engine.directory %>; export PORT=<%= port %>; <%= process.command %> >> <%= log_root %>/<%=process.name%>-<%=num%>.log 2>&1'
|
||||||
exec su <%= user %> -c 'export PORT=<%= port %>; <%= process.command %> >> <%= log_root %>/<%=process.name%>-<%=num%>.log 2>&1'
|
|
||||||
|
|||||||
+1
-1
@@ -25,5 +25,5 @@ Gem::Specification.new do |gem|
|
|||||||
gem.add_development_dependency 'fakefs', '~> 0.2.1'
|
gem.add_development_dependency 'fakefs', '~> 0.2.1'
|
||||||
gem.add_development_dependency 'rcov', '~> 0.9.8'
|
gem.add_development_dependency 'rcov', '~> 0.9.8'
|
||||||
gem.add_development_dependency 'rr', '~> 1.0.2'
|
gem.add_development_dependency 'rr', '~> 1.0.2'
|
||||||
gem.add_development_dependency 'rspec', '~> 2.0.0'
|
gem.add_development_dependency 'rspec', '~> 2.6.0'
|
||||||
end
|
end
|
||||||
|
|||||||
+2
-1
@@ -30,6 +30,7 @@ class Foreman::CLI < Thor
|
|||||||
method_option :log, :type => :string, :aliases => "-l"
|
method_option :log, :type => :string, :aliases => "-l"
|
||||||
method_option :port, :type => :numeric, :aliases => "-p"
|
method_option :port, :type => :numeric, :aliases => "-p"
|
||||||
method_option :user, :type => :string, :aliases => "-u"
|
method_option :user, :type => :string, :aliases => "-u"
|
||||||
|
method_option :template, :type => :string, :aliases => "-t"
|
||||||
method_option :concurrency, :type => :string, :aliases => "-c",
|
method_option :concurrency, :type => :string, :aliases => "-c",
|
||||||
:banner => '"alpha=5,bar=3"'
|
:banner => '"alpha=5,bar=3"'
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ private ######################################################################
|
|||||||
def options
|
def options
|
||||||
original_options = super
|
original_options = super
|
||||||
return original_options unless File.exists?(".foreman")
|
return original_options unless File.exists?(".foreman")
|
||||||
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
|
||||||
|
|
||||||
|
|||||||
+25
-12
@@ -3,6 +3,7 @@ require "foreman/process"
|
|||||||
require "foreman/utils"
|
require "foreman/utils"
|
||||||
require "pty"
|
require "pty"
|
||||||
require "tempfile"
|
require "tempfile"
|
||||||
|
require "timeout"
|
||||||
require "term/ansicolor"
|
require "term/ansicolor"
|
||||||
require "fileutils"
|
require "fileutils"
|
||||||
|
|
||||||
@@ -58,8 +59,8 @@ class Foreman::Engine
|
|||||||
fork process, options, environment
|
fork process, options, environment
|
||||||
end
|
end
|
||||||
|
|
||||||
trap("TERM") { puts "SIGTERM received"; kill_all("TERM") }
|
trap("TERM") { puts "SIGTERM received"; terminate_gracefully }
|
||||||
trap("INT") { puts "SIGINT received"; kill_all("TERM") }
|
trap("INT") { puts "SIGINT received"; terminate_gracefully }
|
||||||
|
|
||||||
watch_for_termination
|
watch_for_termination
|
||||||
end
|
end
|
||||||
@@ -69,8 +70,8 @@ class Foreman::Engine
|
|||||||
|
|
||||||
fork processes[name], options, environment
|
fork processes[name], options, environment
|
||||||
|
|
||||||
trap("TERM") { puts "SIGTERM received"; kill_all("TERM") }
|
trap("TERM") { puts "SIGTERM received"; terminate_gracefully }
|
||||||
trap("INT") { puts "SIGINT received"; kill_all("TERM") }
|
trap("INT") { puts "SIGINT received"; terminate_gracefully }
|
||||||
|
|
||||||
watch_for_termination
|
watch_for_termination
|
||||||
end
|
end
|
||||||
@@ -107,12 +108,12 @@ private ######################################################################
|
|||||||
|
|
||||||
def run(process)
|
def run(process)
|
||||||
proctitle "ruby: foreman #{process.name}"
|
proctitle "ruby: foreman #{process.name}"
|
||||||
|
trap("SIGINT", "IGNORE")
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Dir.chdir directory do
|
Dir.chdir directory do
|
||||||
command = process.command
|
PTY.spawn(runner, process.command) do |stdin, stdout, pid|
|
||||||
|
trap("SIGTERM") { Process.kill("SIGTERM", pid) }
|
||||||
PTY.spawn("#{process.command} 2>&1") do |stdin, stdout, pid|
|
|
||||||
until stdin.eof?
|
until stdin.eof?
|
||||||
info stdin.gets, process
|
info stdin.gets, process
|
||||||
end
|
end
|
||||||
@@ -126,11 +127,9 @@ private ######################################################################
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def kill_all(signal="TERM")
|
def kill_all(signal="SIGTERM")
|
||||||
info "terminating"
|
|
||||||
running_processes.each do |pid, process|
|
running_processes.each do |pid, process|
|
||||||
info "killing #{process.name} in pid #{pid}"
|
Process.kill(signal, pid) rescue Errno::ESRCH
|
||||||
Process.kill(signal, pid)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -179,8 +178,9 @@ private ######################################################################
|
|||||||
pid, status = Process.wait2
|
pid, status = Process.wait2
|
||||||
process = running_processes.delete(pid)
|
process = running_processes.delete(pid)
|
||||||
info "process terminated", process
|
info "process terminated", process
|
||||||
|
terminate_gracefully
|
||||||
kill_all
|
kill_all
|
||||||
Process.waitall
|
rescue Errno::ECHILD
|
||||||
end
|
end
|
||||||
|
|
||||||
def running_processes
|
def running_processes
|
||||||
@@ -217,4 +217,17 @@ private ######################################################################
|
|||||||
environment
|
environment
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def runner
|
||||||
|
File.expand_path("../../../bin/foreman-runner", __FILE__)
|
||||||
|
end
|
||||||
|
|
||||||
|
def terminate_gracefully
|
||||||
|
info "sending SIGTERM to all processes"
|
||||||
|
kill_all "SIGTERM"
|
||||||
|
Timeout.timeout(3) { Process.waitall }
|
||||||
|
rescue Timeout::Error
|
||||||
|
info "sending SIGKILL to all processes"
|
||||||
|
kill_all "SIGKILL"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,8 +23,12 @@ private ######################################################################
|
|||||||
puts "[foreman export] %s" % message
|
puts "[foreman export] %s" % message
|
||||||
end
|
end
|
||||||
|
|
||||||
def export_template(name)
|
def export_template(exporter, file, template_root)
|
||||||
File.read(File.expand_path("../../../../data/export/#{name}", __FILE__))
|
if template_root && File.exist?(file_path = File.join(template_root, file))
|
||||||
|
File.read(file_path)
|
||||||
|
else
|
||||||
|
File.read(File.expand_path("../../../../data/export/#{exporter}/#{file}", __FILE__))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_file(filename, contents)
|
def write_file(filename, contents)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class Foreman::Export::Upstart < Foreman::Export::Base
|
|||||||
app = options[:app] || File.basename(engine.directory)
|
app = options[:app] || File.basename(engine.directory)
|
||||||
user = options[:user] || app
|
user = options[:user] || app
|
||||||
log_root = options[:log] || "/var/log/#{app}"
|
log_root = options[:log] || "/var/log/#{app}"
|
||||||
|
template_root = options[:template]
|
||||||
|
|
||||||
Dir["#{location}/#{app}*.conf"].each do |file|
|
Dir["#{location}/#{app}*.conf"].each do |file|
|
||||||
say "cleaning up: #{file}"
|
say "cleaning up: #{file}"
|
||||||
@@ -19,14 +20,14 @@ class Foreman::Export::Upstart < Foreman::Export::Base
|
|||||||
|
|
||||||
concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])
|
concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])
|
||||||
|
|
||||||
master_template = export_template("upstart/master.conf.erb")
|
master_template = export_template("upstart", "master.conf.erb", template_root)
|
||||||
master_config = ERB.new(master_template).result(binding)
|
master_config = ERB.new(master_template).result(binding)
|
||||||
write_file "#{location}/#{app}.conf", master_config
|
write_file "#{location}/#{app}.conf", master_config
|
||||||
|
|
||||||
process_template = export_template("upstart/process.conf.erb")
|
process_template = export_template("upstart", "process.conf.erb", template_root)
|
||||||
|
|
||||||
engine.processes.values.each do |process|
|
engine.processes.values.each do |process|
|
||||||
process_master_template = export_template("upstart/process_master.conf.erb")
|
process_master_template = export_template("upstart", "process_master.conf.erb", template_root)
|
||||||
process_master_config = ERB.new(process_master_template).result(binding)
|
process_master_config = ERB.new(process_master_template).result(binding)
|
||||||
write_file "#{location}/#{app}-#{process.name}.conf", process_master_config
|
write_file "#{location}/#{app}-#{process.name}.conf", process_master_config
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Foreman
|
module Foreman
|
||||||
|
|
||||||
VERSION = "0.16.0"
|
VERSION = "0.19.0"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
require "spec_helper"
|
require "spec_helper"
|
||||||
require "foreman/engine"
|
require "foreman/engine"
|
||||||
require "foreman/export/upstart"
|
require "foreman/export/upstart"
|
||||||
|
require "tmpdir"
|
||||||
|
|
||||||
describe Foreman::Export::Upstart do
|
describe Foreman::Export::Upstart do
|
||||||
let(:engine) { Foreman::Engine.new(write_procfile) }
|
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(:upstart) { Foreman::Export::Upstart.new(engine) }
|
||||||
|
|
||||||
before(:each) { load_export_templates_into_fakefs("upstart") }
|
before(:each) { load_export_templates_into_fakefs("upstart") }
|
||||||
@@ -12,11 +14,26 @@ describe Foreman::Export::Upstart do
|
|||||||
it "exports to the filesystem" do
|
it "exports to the filesystem" do
|
||||||
upstart.export("/tmp/init")
|
upstart.export("/tmp/init")
|
||||||
|
|
||||||
File.read("/tmp/init/foreman.conf").should == example_export_file("upstart/foreman.conf")
|
File.read("/tmp/init/app.conf").should == example_export_file("upstart/app.conf")
|
||||||
File.read("/tmp/init/foreman-alpha.conf").should == example_export_file("upstart/foreman-alpha.conf")
|
File.read("/tmp/init/app-alpha.conf").should == example_export_file("upstart/app-alpha.conf")
|
||||||
File.read("/tmp/init/foreman-alpha-1.conf").should == example_export_file("upstart/foreman-alpha-1.conf")
|
File.read("/tmp/init/app-alpha-1.conf").should == example_export_file("upstart/app-alpha-1.conf")
|
||||||
File.read("/tmp/init/foreman-alpha-2.conf").should == example_export_file("upstart/foreman-alpha-2.conf")
|
File.read("/tmp/init/app-alpha-2.conf").should == example_export_file("upstart/app-alpha-2.conf")
|
||||||
File.read("/tmp/init/foreman-bravo.conf").should == example_export_file("upstart/foreman.bravo.conf")
|
File.read("/tmp/init/app-bravo.conf").should == example_export_file("upstart/app-bravo.conf")
|
||||||
File.read("/tmp/init/foreman-bravo-1.conf").should == example_export_file("upstart/foreman-bravo-1.conf")
|
File.read("/tmp/init/app-bravo-1.conf").should == example_export_file("upstart/app-bravo-1.conf")
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with alternate templates" do
|
||||||
|
let(:template_root) { "/tmp/alternate" }
|
||||||
|
|
||||||
|
before do
|
||||||
|
FileUtils.mkdir_p template_root
|
||||||
|
File.open("#{template_root}/master.conf.erb", "w") { |f| f.puts "alternate_template" }
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can export with alternate template files" do
|
||||||
|
upstart.export("/tmp/init", :template => template_root)
|
||||||
|
|
||||||
|
File.read("/tmp/init/app.conf").should == "alternate_template\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
start on starting app-alpha
|
||||||
|
stop on stopping app-alpha
|
||||||
|
respawn
|
||||||
|
|
||||||
|
exec su - app -c 'cd /tmp/app; export PORT=5000; ./alpha >> /var/log/app/alpha-1.log 2>&1'
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
start on starting app-alpha
|
||||||
|
stop on stopping app-alpha
|
||||||
|
respawn
|
||||||
|
|
||||||
|
exec su - app -c 'cd /tmp/app; export PORT=5001; ./alpha >> /var/log/app/alpha-2.log 2>&1'
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
start on starting app
|
||||||
|
stop on stopping app
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
start on starting app-bravo
|
||||||
|
stop on stopping app-bravo
|
||||||
|
respawn
|
||||||
|
|
||||||
|
exec su - app -c 'cd /tmp/app; export PORT=5100; ./bravo >> /var/log/app/bravo-1.log 2>&1'
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
start on starting app
|
||||||
|
stop on stopping app
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
pre-start script
|
||||||
|
|
||||||
|
bash << "EOF"
|
||||||
|
mkdir -p /var/log/app
|
||||||
|
chown -R app /var/log/app
|
||||||
|
EOF
|
||||||
|
|
||||||
|
end script
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
start on starting foreman-alpha
|
|
||||||
stop on stopping foreman-alpha
|
|
||||||
respawn
|
|
||||||
|
|
||||||
chdir /Users/david/Code/foreman
|
|
||||||
exec su foreman -c 'export PORT=5000; ./alpha >> /var/log/foreman/alpha-1.log 2>&1'
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
start on starting foreman-alpha
|
|
||||||
stop on stopping foreman-alpha
|
|
||||||
respawn
|
|
||||||
|
|
||||||
chdir /Users/david/Code/foreman
|
|
||||||
exec su foreman -c 'export PORT=5001; ./alpha >> /var/log/foreman/alpha-2.log 2>&1'
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
start on starting foreman
|
|
||||||
stop on stopping foreman
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
start on starting foreman-bravo
|
|
||||||
stop on stopping foreman-bravo
|
|
||||||
respawn
|
|
||||||
|
|
||||||
chdir /Users/david/Code/foreman
|
|
||||||
exec su foreman -c 'export PORT=5100; ./bravo >> /var/log/foreman/bravo-1.log 2>&1'
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
start on starting foreman
|
|
||||||
stop on stopping foreman
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
pre-start script
|
|
||||||
|
|
||||||
bash << "EOF"
|
|
||||||
mkdir -p /var/log/foreman
|
|
||||||
chown -R foreman /var/log/foreman
|
|
||||||
EOF
|
|
||||||
|
|
||||||
end script
|
|
||||||
+1
-1
@@ -52,7 +52,7 @@ def example_export_file(filename)
|
|||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
Rspec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.color_enabled = true
|
config.color_enabled = true
|
||||||
config.include FakeFS::SpecHelpers
|
config.include FakeFS::SpecHelpers
|
||||||
config.mock_with :rr
|
config.mock_with :rr
|
||||||
|
|||||||
Reference in New Issue
Block a user