dante 0.1.5 → 0.2.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.
- checksums.yaml +15 -0
- data/README.md +13 -2
- data/lib/dante/runner.rb +13 -2
- data/lib/dante/version.rb +1 -1
- data/test/runner_test.rb +19 -0
- metadata +59 -79
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NWJkYTJiOTVkOWY1OTYzMzFhNGFmMzIzZmM5YjI0NWMxMzIxY2UwYQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NTViMjBkMGYwYWM2ZDE2YjBlMzJiZWQ1YjFlZDU0OWM2YWUzODU4NQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MzIwNDBlMGNjY2Y0YmQwMjEzNzMzMjU4MmE4Y2ZkNDhhNTUwMDg5NmRlNWEy
|
10
|
+
ZDY3MWE5NjZiYTE4Y2U3NzFiZDA5ZmZmMWM4YTdkZGU0ZjBkMTI4MjEyMGFm
|
11
|
+
YjVhNTY1NjJhMjY4MjA0NmNjY2JjN2Q1MjdmNTNhMDZjMWQ3NWM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YmQ4YTExNDIxYzc3YWUzNDA0MjBjMzUzYTcyMjI5NTY1OGM5YTQwOWJlYjZk
|
14
|
+
NThhNWRiYTM5ZmQ0MGVjOTlkNmVhZTgwOTM1ZWNhY2FjNjVjMWI2NmM5Mjhh
|
15
|
+
NmRlMzE3Y2JlMmQ5Yzg5YWMzOTAzNjg1MjJiYzg3NDc3MDY2NzU=
|
data/README.md
CHANGED
@@ -65,12 +65,19 @@ This gives your binary several useful things for free:
|
|
65
65
|
|
66
66
|
will start the app undaemonized in the terminal, handling trapping and stopping the process.
|
67
67
|
|
68
|
+
```
|
69
|
+
./bin/myapp -l /var/log/myapp.log
|
70
|
+
```
|
71
|
+
|
72
|
+
will start the app undaemonized in the terminal and redirect all stdout and stderr to the specified logfile.
|
73
|
+
|
68
74
|
```
|
69
75
|
./bin/myapp -p 8080 -d -P /var/run/myapp.pid -l /var/log/myapp.log
|
70
76
|
```
|
71
77
|
|
72
78
|
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.
|
79
|
+
All stdout and stderr will be redirected to the specified logfile. If no logfile is specified in daemon mode then all
|
80
|
+
stdout and stderr will be directed to /var/log/<myapp name>.log.
|
74
81
|
|
75
82
|
```
|
76
83
|
./bin/myapp -k -P /var/run/myapp.pid
|
@@ -104,6 +111,10 @@ runner.with_options do |opts|
|
|
104
111
|
options[:test] = test
|
105
112
|
end
|
106
113
|
end
|
114
|
+
# Create validation hook for options
|
115
|
+
runner.verify_options_hook = lambda { |opts|
|
116
|
+
raise Exception.new("Must supply test parameter") if opts[:test].nil?
|
117
|
+
}
|
107
118
|
# Parse command-line options and execute the process
|
108
119
|
runner.execute do |opts|
|
109
120
|
# opts: host, pid_path, port, daemonize, user, group
|
@@ -170,4 +181,4 @@ and that's all. Of course now you can also easily daemonize as well as start/sto
|
|
170
181
|
|
171
182
|
## Copyright
|
172
183
|
|
173
|
-
Copyright © 2011 Nathan Esquenazi. See [LICENSE](https://github.com/bazaarlabs/dante/blob/master/LICENSE) for details.
|
184
|
+
Copyright © 2011 Nathan Esquenazi. See [LICENSE](https://github.com/bazaarlabs/dante/blob/master/LICENSE) for details.
|
data/lib/dante/runner.rb
CHANGED
@@ -18,7 +18,7 @@ module Dante
|
|
18
18
|
class Runner
|
19
19
|
MAX_START_TRIES = 5
|
20
20
|
|
21
|
-
attr_accessor :options, :name, :description
|
21
|
+
attr_accessor :options, :name, :description, :verify_options_hook
|
22
22
|
|
23
23
|
class << self
|
24
24
|
def run(*args, &block)
|
@@ -50,6 +50,8 @@ module Dante
|
|
50
50
|
parse_options
|
51
51
|
self.options.merge!(opts)
|
52
52
|
|
53
|
+
@verify_options_hook.call(self.options) if @verify_options_hook
|
54
|
+
|
53
55
|
if options.include?(:kill)
|
54
56
|
self.stop
|
55
57
|
else # create process
|
@@ -76,6 +78,10 @@ module Dante
|
|
76
78
|
def daemonize
|
77
79
|
return log("Process is already started") if self.daemon_running? # daemon already started
|
78
80
|
|
81
|
+
if !options[:log_path]
|
82
|
+
options[:log_path] = "/var/log/#{@name}.log"
|
83
|
+
end
|
84
|
+
|
79
85
|
# Start process
|
80
86
|
pid = fork do
|
81
87
|
exit if fork
|
@@ -86,6 +92,7 @@ module Dante
|
|
86
92
|
redirect_output!
|
87
93
|
start
|
88
94
|
end
|
95
|
+
Process.waitpid pid
|
89
96
|
# Ensure process is running
|
90
97
|
if until_true(MAX_START_TRIES) { self.daemon_running? }
|
91
98
|
log "Daemon has started successfully"
|
@@ -99,6 +106,10 @@ module Dante
|
|
99
106
|
def start
|
100
107
|
log "Starting #{@name} service..."
|
101
108
|
|
109
|
+
if log_path = options[:log_path] && options[:daemonize].nil?
|
110
|
+
redirect_output!
|
111
|
+
end
|
112
|
+
|
102
113
|
trap("INT") {
|
103
114
|
interrupt
|
104
115
|
exit
|
@@ -175,7 +186,7 @@ module Dante
|
|
175
186
|
options[:daemonize] = v
|
176
187
|
end
|
177
188
|
|
178
|
-
opts.on("-l", "--log FILE", String, "Logfile for output") do |v|
|
189
|
+
opts.on("-l", "--log FILE", String, "Logfile for output", "(default: /var/log/#{@name}.log)") do |v|
|
179
190
|
options[:log_path] = v
|
180
191
|
end
|
181
192
|
|
data/lib/dante/version.rb
CHANGED
data/test/runner_test.rb
CHANGED
@@ -1,6 +1,25 @@
|
|
1
1
|
require File.expand_path('../test_helper', __FILE__)
|
2
2
|
|
3
3
|
describe "dante runner" do
|
4
|
+
|
5
|
+
describe "verify options fails" do
|
6
|
+
it "should bubble up exception" do
|
7
|
+
runner = Dante::Runner.new('test-process', {key1:"val2"}) {
|
8
|
+
raise Exception.new("should not get here!!!")
|
9
|
+
}
|
10
|
+
|
11
|
+
runner.verify_options_hook = lambda { |opts|
|
12
|
+
raise Exception.new("Look for this exception") if(opts[:key1] != "val1")
|
13
|
+
}
|
14
|
+
|
15
|
+
err = assert_raises(Exception) {
|
16
|
+
runner.execute
|
17
|
+
}
|
18
|
+
|
19
|
+
assert_equal(err.message, "Look for this exception")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
4
23
|
describe "with no daemonize" do
|
5
24
|
before do
|
6
25
|
@process = TestingProcess.new('a')
|
metadata
CHANGED
@@ -1,74 +1,64 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: dante
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 5
|
10
|
-
version: 0.1.5
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Nathan Esquenazi
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2013-12-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: rake
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 3
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
32
20
|
type: :development
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: minitest
|
36
21
|
prerelease: false
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
46
34
|
type: :development
|
47
|
-
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: mocha
|
50
35
|
prerelease: false
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mocha
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
60
48
|
type: :development
|
61
|
-
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
62
55
|
description: Turn any process into a demon.
|
63
|
-
email:
|
56
|
+
email:
|
64
57
|
- nesquena@gmail.com
|
65
58
|
executables: []
|
66
|
-
|
67
59
|
extensions: []
|
68
|
-
|
69
60
|
extra_rdoc_files: []
|
70
|
-
|
71
|
-
files:
|
61
|
+
files:
|
72
62
|
- .gitignore
|
73
63
|
- Gemfile
|
74
64
|
- LICENSE
|
@@ -83,38 +73,28 @@ files:
|
|
83
73
|
- test/test_helper.rb
|
84
74
|
homepage: https://github.com/bazaarlabs/dante
|
85
75
|
licenses: []
|
86
|
-
|
76
|
+
metadata: {}
|
87
77
|
post_install_message:
|
88
78
|
rdoc_options: []
|
89
|
-
|
90
|
-
require_paths:
|
79
|
+
require_paths:
|
91
80
|
- lib
|
92
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
none: false
|
103
|
-
requirements:
|
104
|
-
- - ">="
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
hash: 3
|
107
|
-
segments:
|
108
|
-
- 0
|
109
|
-
version: "0"
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
110
91
|
requirements: []
|
111
|
-
|
112
92
|
rubyforge_project: dante
|
113
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.0.7
|
114
94
|
signing_key:
|
115
|
-
specification_version:
|
95
|
+
specification_version: 4
|
116
96
|
summary: Turn any process into a demon
|
117
|
-
test_files:
|
97
|
+
test_files:
|
118
98
|
- test/dante_test.rb
|
119
99
|
- test/runner_test.rb
|
120
100
|
- test/test_helper.rb
|