dante 0.1.2 → 0.1.3
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/README.md +3 -2
- data/lib/dante/runner.rb +23 -3
- data/lib/dante/version.rb +1 -1
- data/test/runner_test.rb +25 -2
- data/test/test_helper.rb +11 -0
- metadata +3 -25
data/README.md
CHANGED
@@ -66,10 +66,11 @@ This gives your binary several useful things for free:
|
|
66
66
|
will start the app undaemonized in the terminal, handling trapping and stopping the process.
|
67
67
|
|
68
68
|
```
|
69
|
-
./bin/myapp -p 8080 -d -P /var/run/myapp.pid
|
69
|
+
./bin/myapp -p 8080 -d -P /var/run/myapp.pid -l /var/log/myapp.log
|
70
70
|
```
|
71
71
|
|
72
72
|
will daemonize and start the process, storing the pid in the specified pid file.
|
73
|
+
All stdout and stderr will be redirected to the specified logfile.
|
73
74
|
|
74
75
|
```
|
75
76
|
./bin/myapp -k -P /var/run/myapp.pid
|
@@ -128,7 +129,7 @@ You can also use dante programmatically to start, stop and restart arbitrary cod
|
|
128
129
|
|
129
130
|
```ruby
|
130
131
|
# daemon start
|
131
|
-
Dante::Runner.new('gitdocs').execute(:daemonize => true, :
|
132
|
+
Dante::Runner.new('gitdocs').execute(:daemonize => true, :pid\_path => @pid, :log\_path => @log\_path) { something! }
|
132
133
|
# daemon stop
|
133
134
|
Dante::Runner.new('gitdocs').execute(:kill => true, :pid_path => @pid)
|
134
135
|
# daemon restart
|
data/lib/dante/runner.rb
CHANGED
@@ -31,6 +31,7 @@ module Dante
|
|
31
31
|
@options = {
|
32
32
|
:host => '0.0.0.0',
|
33
33
|
:pid_path => "/var/run/#{@name}.pid",
|
34
|
+
:log_path => false,
|
34
35
|
:debug => true
|
35
36
|
}.merge(defaults)
|
36
37
|
end
|
@@ -69,9 +70,7 @@ module Dante
|
|
69
70
|
exit if fork
|
70
71
|
store_pid(Process.pid)
|
71
72
|
File.umask 0000
|
72
|
-
|
73
|
-
STDOUT.reopen "/dev/null", "a"
|
74
|
-
STDERR.reopen STDOUT
|
73
|
+
redirect_output!
|
75
74
|
start
|
76
75
|
end
|
77
76
|
# Ensure process is running
|
@@ -158,6 +157,10 @@ module Dante
|
|
158
157
|
options[:daemonize] = v
|
159
158
|
end
|
160
159
|
|
160
|
+
opts.on("-l", "--log FILE", String, "Logfile for output") do |v|
|
161
|
+
options[:log_path] = v
|
162
|
+
end
|
163
|
+
|
161
164
|
opts.on("-k", "--kill [PORT]", String, "Kill specified running daemons - leave blank to kill all.") do |v|
|
162
165
|
options[:kill] = v
|
163
166
|
end
|
@@ -199,6 +202,23 @@ module Dante
|
|
199
202
|
end
|
200
203
|
end
|
201
204
|
|
205
|
+
# Redirect output based on log settings (reopens stdout/stderr to specified logfile)
|
206
|
+
# If log_path is nil, redirect to /dev/null to quiet output
|
207
|
+
def redirect_output!
|
208
|
+
if log_path = options[:log_path]
|
209
|
+
FileUtils.touch log_path
|
210
|
+
File.open(log_path, 'a') do |f|
|
211
|
+
$stdout.reopen(f)
|
212
|
+
$stderr.reopen(f)
|
213
|
+
end
|
214
|
+
else # redirect to /dev/null
|
215
|
+
STDIN.reopen "/dev/null"
|
216
|
+
STDOUT.reopen "/dev/null", "a"
|
217
|
+
STDERR.reopen STDOUT
|
218
|
+
end
|
219
|
+
log_path = options[:log_path] ? options[:log_path] : "/dev/null"
|
220
|
+
end
|
221
|
+
|
202
222
|
# Runs until the block condition is met or the timeout_seconds is exceeded
|
203
223
|
# until_true(10) { ...return_condition... }
|
204
224
|
def until_true(timeout_seconds, interval=1, &block)
|
data/lib/dante/version.rb
CHANGED
data/test/runner_test.rb
CHANGED
@@ -21,7 +21,7 @@ describe "dante runner" do
|
|
21
21
|
describe "with daemonize flag" do
|
22
22
|
before do
|
23
23
|
@process = TestingProcess.new('b')
|
24
|
-
@run_options = { :daemonize => true, :pid_path => "/tmp/dante.pid", :port => 8080 }
|
24
|
+
@run_options = { :daemonize => true, :pid_path => "/tmp/dante.pid", :port => 8080, :log_path => false }
|
25
25
|
@runner = Dante::Runner.new('test-process-2', @run_options) { |opts|
|
26
26
|
@process.run_b!(opts[:port]) }
|
27
27
|
@stdout = capture_stdout { @runner.execute }
|
@@ -49,10 +49,33 @@ describe "dante runner" do
|
|
49
49
|
end
|
50
50
|
end # daemonize
|
51
51
|
|
52
|
+
describe "with daemonize flag and log file specified" do
|
53
|
+
before do
|
54
|
+
@logfile = '/tmp/dante-logging.log'
|
55
|
+
FileUtils.rm(@logfile) if File.exist?(@logfile)
|
56
|
+
@process = TestingProcess.new('c')
|
57
|
+
@run_options = { :daemonize => true, :pid_path => "/tmp/dante.pid", :port => 8081, :log_path => @logfile, :debug => false }
|
58
|
+
@runner = Dante::Runner.new('test-process-2', @run_options) { |opts|
|
59
|
+
@process.run_c!(opts[:port]) }
|
60
|
+
@runner.execute
|
61
|
+
sleep(1)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "can properly handles log to file and aborts on INT" do
|
65
|
+
refute_equal 0, @pid = `cat /tmp/dante.pid`.to_i
|
66
|
+
Process.kill "INT", @pid
|
67
|
+
sleep(1) # Wait to complete
|
68
|
+
@output = File.read(@logfile)
|
69
|
+
assert_match /Started on 8081!!/, @output
|
70
|
+
assert_match /Interrupt!!/, @output
|
71
|
+
assert_match /Closing!!/, @output
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
52
75
|
describe "with execute accepting block" do
|
53
76
|
before do
|
54
77
|
@process = TestingProcess.new('b')
|
55
|
-
@run_options = { :daemonize => true, :pid_path => "/tmp/dante.pid", :port => 8080 }
|
78
|
+
@run_options = { :daemonize => true, :pid_path => "/tmp/dante.pid", :port => 8080, :log_path => false }
|
56
79
|
@runner = Dante::Runner.new('test-process-2', @run_options)
|
57
80
|
@stdout = capture_stdout { @runner.execute { |opts| @process.run_b!(opts[:port]) } }
|
58
81
|
sleep(1)
|
data/test/test_helper.rb
CHANGED
@@ -53,4 +53,15 @@ class TestingProcess
|
|
53
53
|
@tmp.close
|
54
54
|
end
|
55
55
|
end # run_b!
|
56
|
+
|
57
|
+
# For logging test
|
58
|
+
def run_c!(port=9091)
|
59
|
+
puts "Started on #{port}!!"
|
60
|
+
sleep(100)
|
61
|
+
rescue Interrupt
|
62
|
+
puts "Interrupt!!"
|
63
|
+
exit
|
64
|
+
ensure
|
65
|
+
puts "Closing!!"
|
66
|
+
end
|
56
67
|
end # TestingProcess
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dante
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 31
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 2
|
10
|
-
version: 0.1.2
|
5
|
+
version: 0.1.3
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Nathan Esquenazi
|
@@ -15,8 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
13
|
+
date: 2012-01-31 00:00:00 Z
|
20
14
|
dependencies:
|
21
15
|
- !ruby/object:Gem::Dependency
|
22
16
|
name: rake
|
@@ -26,9 +20,6 @@ dependencies:
|
|
26
20
|
requirements:
|
27
21
|
- - ">="
|
28
22
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
|
-
segments:
|
31
|
-
- 0
|
32
23
|
version: "0"
|
33
24
|
type: :development
|
34
25
|
version_requirements: *id001
|
@@ -40,9 +31,6 @@ dependencies:
|
|
40
31
|
requirements:
|
41
32
|
- - ">="
|
42
33
|
- !ruby/object:Gem::Version
|
43
|
-
hash: 3
|
44
|
-
segments:
|
45
|
-
- 0
|
46
34
|
version: "0"
|
47
35
|
type: :development
|
48
36
|
version_requirements: *id002
|
@@ -54,9 +42,6 @@ dependencies:
|
|
54
42
|
requirements:
|
55
43
|
- - ">="
|
56
44
|
- !ruby/object:Gem::Version
|
57
|
-
hash: 3
|
58
|
-
segments:
|
59
|
-
- 0
|
60
45
|
version: "0"
|
61
46
|
type: :development
|
62
47
|
version_requirements: *id003
|
@@ -82,7 +67,6 @@ files:
|
|
82
67
|
- test/dante_test.rb
|
83
68
|
- test/runner_test.rb
|
84
69
|
- test/test_helper.rb
|
85
|
-
has_rdoc: true
|
86
70
|
homepage: https://github.com/bazaarlabs/dante
|
87
71
|
licenses: []
|
88
72
|
|
@@ -96,23 +80,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
80
|
requirements:
|
97
81
|
- - ">="
|
98
82
|
- !ruby/object:Gem::Version
|
99
|
-
hash: 3
|
100
|
-
segments:
|
101
|
-
- 0
|
102
83
|
version: "0"
|
103
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
85
|
none: false
|
105
86
|
requirements:
|
106
87
|
- - ">="
|
107
88
|
- !ruby/object:Gem::Version
|
108
|
-
hash: 3
|
109
|
-
segments:
|
110
|
-
- 0
|
111
89
|
version: "0"
|
112
90
|
requirements: []
|
113
91
|
|
114
92
|
rubyforge_project: dante
|
115
|
-
rubygems_version: 1.
|
93
|
+
rubygems_version: 1.8.12
|
116
94
|
signing_key:
|
117
95
|
specification_version: 3
|
118
96
|
summary: Turn any process into a demon
|