Compare commits

...
10 Commits
Author SHA1 Message Date
David Dollar fd234b8044 0.18.0 2011-06-03 01:32:14 -04:00
David Dollar f2f09554c8 correct shutdown signals
processes are sent SIGTERM followed 3 seconds later by SIGKILL
2011-06-03 01:31:51 -04:00
David Dollar 6c465b4ef1 remove debug print 2011-06-03 01:31:08 -04:00
David Dollar c419f8213b 0.17.0 2011-06-02 12:10:30 -04:00
David Dollar 7f61fb61ea credits 2011-06-02 12:10:21 -04:00
David Dollar 577a5c7c5c make sure tests run on machines other than mine 2011-06-02 12:09:30 -04:00
David Dollar 56940c56d9 Merge pull request #31 from jayzes/master
Loading the shell environment in the exported upstart configuration
2011-06-02 08:51:45 -07:00
Jay Zeschin f308ad886d Change directories when using su - -c to execute a command since you lose the current working directory 2011-06-01 10:38:07 -06:00
Jay Zeschin 55375b9bde Edited data/export/upstart/process.conf.erb via GitHub 2011-05-31 16:30:45 -07:00
David Dollar 85fcccffa8 more readme touchup 2011-05-13 12:10:38 -04:00
20 changed files with 81 additions and 61 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
PATH PATH
remote: . remote: .
specs: specs:
foreman (0.16.0) foreman (0.18.0)
term-ansicolor (~> 1.0.5) term-ansicolor (~> 1.0.5)
thor (>= 0.13.6) thor (>= 0.13.6)
+9 -8
View File
@@ -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
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env ruby
exec ARGV.join(" ")
+6
View File
@@ -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
+1 -2
View File
@@ -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'
+25 -12
View File
@@ -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
+1 -1
View File
@@ -1,5 +1,5 @@
module Foreman module Foreman
VERSION = "0.16.0" VERSION = "0.18.0"
end end
+9 -7
View File
@@ -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,11 @@ 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 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
+8
View File
@@ -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