foreman 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ exec ARGV.join(" ")
@@ -1,5 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ %w( SIGINT SIGTERM SIGHUP ).each do |signal|
4
+ trap(signal) do
5
+ puts "received #{signal} but i'm ignoring it!"
6
+ end
7
+ end
8
+
3
9
  while true
4
10
  puts "tick: #{ARGV.inspect} -- FOO:#{ENV["FOO"]}"
5
11
  sleep 1
@@ -3,6 +3,7 @@ require "foreman/process"
3
3
  require "foreman/utils"
4
4
  require "pty"
5
5
  require "tempfile"
6
+ require "timeout"
6
7
  require "term/ansicolor"
7
8
  require "fileutils"
8
9
 
@@ -58,8 +59,8 @@ class Foreman::Engine
58
59
  fork process, options, environment
59
60
  end
60
61
 
61
- trap("TERM") { puts "SIGTERM received"; kill_all("TERM") }
62
- trap("INT") { puts "SIGINT received"; kill_all("TERM") }
62
+ trap("TERM") { puts "SIGTERM received"; terminate_gracefully }
63
+ trap("INT") { puts "SIGINT received"; terminate_gracefully }
63
64
 
64
65
  watch_for_termination
65
66
  end
@@ -69,8 +70,8 @@ class Foreman::Engine
69
70
 
70
71
  fork processes[name], options, environment
71
72
 
72
- trap("TERM") { puts "SIGTERM received"; kill_all("TERM") }
73
- trap("INT") { puts "SIGINT received"; kill_all("TERM") }
73
+ trap("TERM") { puts "SIGTERM received"; terminate_gracefully }
74
+ trap("INT") { puts "SIGINT received"; terminate_gracefully }
74
75
 
75
76
  watch_for_termination
76
77
  end
@@ -107,12 +108,12 @@ private ######################################################################
107
108
 
108
109
  def run(process)
109
110
  proctitle "ruby: foreman #{process.name}"
111
+ trap("SIGINT", "IGNORE")
110
112
 
111
113
  begin
112
114
  Dir.chdir directory do
113
- command = process.command
114
-
115
- PTY.spawn("#{process.command} 2>&1") do |stdin, stdout, pid|
115
+ PTY.spawn(runner, process.command) do |stdin, stdout, pid|
116
+ trap("SIGTERM") { Process.kill("SIGTERM", pid) }
116
117
  until stdin.eof?
117
118
  info stdin.gets, process
118
119
  end
@@ -126,11 +127,9 @@ private ######################################################################
126
127
  end
127
128
  end
128
129
 
129
- def kill_all(signal="TERM")
130
- info "terminating"
130
+ def kill_all(signal="SIGTERM")
131
131
  running_processes.each do |pid, process|
132
- info "killing #{process.name} in pid #{pid}"
133
- Process.kill(signal, pid)
132
+ Process.kill(signal, pid) rescue Errno::ESRCH
134
133
  end
135
134
  end
136
135
 
@@ -179,8 +178,9 @@ private ######################################################################
179
178
  pid, status = Process.wait2
180
179
  process = running_processes.delete(pid)
181
180
  info "process terminated", process
181
+ terminate_gracefully
182
182
  kill_all
183
- Process.waitall
183
+ rescue Errno::ECHILD
184
184
  end
185
185
 
186
186
  def running_processes
@@ -217,4 +217,17 @@ private ######################################################################
217
217
  environment
218
218
  end
219
219
 
220
+ def runner
221
+ File.expand_path("../../../bin/foreman-runner", __FILE__)
222
+ end
223
+
224
+ def terminate_gracefully
225
+ info "sending SIGTERM to all processes"
226
+ kill_all "SIGTERM"
227
+ Timeout.timeout(3) { Process.waitall }
228
+ rescue Timeout::Error
229
+ info "sending SIGKILL to all processes"
230
+ kill_all "SIGKILL"
231
+ end
232
+
220
233
  end
@@ -1,5 +1,5 @@
1
1
  module Foreman
2
2
 
3
- VERSION = "0.17.0"
3
+ VERSION = "0.18.0"
4
4
 
5
5
  end
@@ -13,7 +13,6 @@ describe Foreman::Export::Upstart do
13
13
 
14
14
  it "exports to the filesystem" do
15
15
  upstart.export("/tmp/init")
16
- p [:d, Dir["/tmp/init/**"]]
17
16
 
18
17
  File.read("/tmp/init/app.conf").should == example_export_file("upstart/app.conf")
19
18
  File.read("/tmp/init/app-alpha.conf").should == example_export_file("upstart/app-alpha.conf")
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: foreman
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.17.0
5
+ version: 0.18.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Dollar
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-02 00:00:00 -04:00
13
+ date: 2011-06-03 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -122,6 +122,7 @@ extra_rdoc_files: []
122
122
 
123
123
  files:
124
124
  - bin/foreman
125
+ - bin/foreman-runner
125
126
  - data/example/error
126
127
  - data/example/log/neverdie.log
127
128
  - data/example/Procfile