dante 0.1.4 → 0.1.5
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.
- data/lib/dante/runner.rb +24 -15
- data/lib/dante/version.rb +1 -1
- data/test/runner_test.rb +31 -2
- metadata +4 -4
data/lib/dante/runner.rb
CHANGED
@@ -103,8 +103,9 @@ module Dante
|
|
103
103
|
interrupt
|
104
104
|
exit
|
105
105
|
}
|
106
|
+
|
106
107
|
trap("TERM"){
|
107
|
-
|
108
|
+
log "Trying to stop #{@name}..."
|
108
109
|
exit
|
109
110
|
}
|
110
111
|
|
@@ -128,12 +129,12 @@ module Dante
|
|
128
129
|
end
|
129
130
|
|
130
131
|
def interrupt
|
131
|
-
|
132
|
+
if options[:debug]
|
132
133
|
raise Interrupt
|
133
|
-
sleep
|
134
|
-
|
135
|
-
|
136
|
-
|
134
|
+
sleep 1
|
135
|
+
else
|
136
|
+
log "Interrupt received; stopping #{@name}"
|
137
|
+
end
|
137
138
|
end
|
138
139
|
|
139
140
|
# Returns true if process is not running
|
@@ -211,7 +212,7 @@ module Dante
|
|
211
212
|
begin
|
212
213
|
pid = IO.read(f).chomp.to_i
|
213
214
|
FileUtils.rm f
|
214
|
-
Process.kill('
|
215
|
+
Process.kill('TERM', pid)
|
215
216
|
log "Stopped PID: #{pid} at #{f}"
|
216
217
|
rescue => e
|
217
218
|
log "Failed to stop! #{k}: #{e}"
|
@@ -223,17 +224,25 @@ module Dante
|
|
223
224
|
# If log_path is nil, redirect to /dev/null to quiet output
|
224
225
|
def redirect_output!
|
225
226
|
if log_path = options[:log_path]
|
227
|
+
# if the log directory doesn't exist, create it
|
228
|
+
FileUtils.mkdir_p File.dirname(options[:log_path]), :mode => 0755
|
229
|
+
# touch the log file to create it
|
226
230
|
FileUtils.touch log_path
|
227
|
-
|
228
|
-
STDERR.reopen STDOUT
|
231
|
+
# Set permissions on the log file
|
229
232
|
File.chmod(0644, log_path)
|
230
|
-
STDOUT
|
233
|
+
# Reopen $stdout (NOT +STDOUT+) to start writing to the log file
|
234
|
+
$stdout.reopen(log_path, 'a')
|
235
|
+
# Redirect $stderr to $stdout
|
236
|
+
$stderr.reopen $stdout
|
237
|
+
$stdout.sync = true
|
231
238
|
else # redirect to /dev/null
|
232
|
-
|
233
|
-
|
234
|
-
|
239
|
+
# We're not bothering to sync if we're dumping to /dev/null
|
240
|
+
# because /dev/null doesn't care about buffered output
|
241
|
+
$stdin.reopen '/dev/null'
|
242
|
+
$stdout.reopen '/dev/null', 'a'
|
243
|
+
$stderr.reopen $stdout
|
235
244
|
end
|
236
|
-
log_path = options[:log_path] ? options[:log_path] :
|
245
|
+
log_path = options[:log_path] ? options[:log_path] : '/dev/null'
|
237
246
|
end
|
238
247
|
|
239
248
|
# Runs until the block condition is met or the timeout_seconds is exceeded
|
@@ -248,7 +257,7 @@ module Dante
|
|
248
257
|
end
|
249
258
|
|
250
259
|
def log(message)
|
251
|
-
puts message
|
260
|
+
puts message
|
252
261
|
end
|
253
262
|
|
254
263
|
end
|
data/lib/dante/version.rb
CHANGED
data/test/runner_test.rb
CHANGED
@@ -33,6 +33,7 @@ describe "dante runner" do
|
|
33
33
|
Process.kill "INT", @pid
|
34
34
|
sleep(1) # Wait to complete
|
35
35
|
@output = File.read(@process.tmp_path)
|
36
|
+
|
36
37
|
assert_match /Started on 8080!!/, @output
|
37
38
|
assert_match /Interrupt!!/, @output
|
38
39
|
assert_match /Closing!!/, @output
|
@@ -43,9 +44,10 @@ describe "dante runner" do
|
|
43
44
|
Process.kill "TERM", @pid
|
44
45
|
sleep(1) # Wait to complete
|
45
46
|
@output = File.read(@process.tmp_path)
|
47
|
+
|
46
48
|
assert_match /Started on 8080!!/, @output
|
47
|
-
assert_match /Interrupt!!/, @output
|
48
49
|
assert_match /Closing!!/, @output
|
50
|
+
refute_match /Interrupt!!/, @output
|
49
51
|
end
|
50
52
|
end # daemonize
|
51
53
|
|
@@ -54,7 +56,7 @@ describe "dante runner" do
|
|
54
56
|
@logfile = '/tmp/dante-logging.log'
|
55
57
|
FileUtils.rm(@logfile) if File.exist?(@logfile)
|
56
58
|
@process = TestingProcess.new('c')
|
57
|
-
@run_options = { :daemonize => true, :pid_path => "/tmp/dante.pid", :port => 8081, :log_path => @logfile
|
59
|
+
@run_options = { :daemonize => true, :pid_path => "/tmp/dante.pid", :port => 8081, :log_path => @logfile }
|
58
60
|
@runner = Dante::Runner.new('test-process-2', @run_options) { |opts|
|
59
61
|
@process.run_c!(opts[:port]) }
|
60
62
|
@runner.execute
|
@@ -66,12 +68,38 @@ describe "dante runner" do
|
|
66
68
|
Process.kill "INT", @pid
|
67
69
|
sleep(1) # Wait to complete
|
68
70
|
@output = File.read(@logfile)
|
71
|
+
|
69
72
|
assert_match /Started on 8081!!/, @output
|
70
73
|
assert_match /Interrupt!!/, @output
|
71
74
|
assert_match /Closing!!/, @output
|
72
75
|
end
|
73
76
|
end
|
74
77
|
|
78
|
+
describe "with daemonize flag and logging flag enabled, and debug flag disabled" do
|
79
|
+
before do
|
80
|
+
@logfile = '/tmp/dante-logging.log'
|
81
|
+
FileUtils.rm(@logfile) if File.exist?(@logfile)
|
82
|
+
@process = TestingProcess.new('c')
|
83
|
+
@run_options = { :daemonize => true, :pid_path => "/tmp/dante.pid", :port => 8081, :log_path => @logfile, :debug => false }
|
84
|
+
@runner = Dante::Runner.new('test-process-2', @run_options) { |opts|
|
85
|
+
@process.run_c!(opts[:port]) }
|
86
|
+
@runner.execute
|
87
|
+
sleep(1)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "can properly handles log to file and aborts on INT" do
|
91
|
+
refute_equal 0, @pid = `cat /tmp/dante.pid`.to_i
|
92
|
+
Process.kill "INT", @pid
|
93
|
+
sleep(1) # Wait to complete
|
94
|
+
@output = File.read(@logfile)
|
95
|
+
|
96
|
+
assert_match /Started on 8081!!/, @output
|
97
|
+
assert_match /Interrupt received/, @output
|
98
|
+
assert_match /Closing!!/, @output
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
75
103
|
describe "with execute accepting block" do
|
76
104
|
before do
|
77
105
|
@process = TestingProcess.new('b')
|
@@ -86,6 +114,7 @@ describe "dante runner" do
|
|
86
114
|
Process.kill "INT", @pid
|
87
115
|
sleep(1) # Wait to complete
|
88
116
|
@output = File.read(@process.tmp_path)
|
117
|
+
|
89
118
|
assert_match /Started on 8080!!/, @output
|
90
119
|
assert_match /Interrupt!!/, @output
|
91
120
|
assert_match /Closing!!/, @output
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dante
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nathan Esquenazi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-06-
|
18
|
+
date: 2012-06-22 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rake
|