process-daemon 0.5.3 → 0.5.4
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 +4 -4
- data/.travis.yml +3 -2
- data/README.md +2 -3
- data/Rakefile +3 -6
- data/lib/process/daemon.rb +16 -0
- data/lib/process/daemon/controller.rb +4 -0
- data/lib/process/daemon/version.rb +1 -1
- data/process-daemon.gemspec +1 -1
- data/{test → spec/process/daemon}/daemon.rb +2 -2
- data/spec/process/daemon/daemon_spec.rb +145 -0
- metadata +9 -9
- data/test/test_daemon.rb +0 -129
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 576478e27475cd8801ce2ea13053480531c13ea4
|
4
|
+
data.tar.gz: 8ec4d0c286a5d0630c357ec529b54611abf54204
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffba1f40b923721772b95a2544c1e1ef1a19a9a2547fe92f41109cfb9802c4b30759a07382b1619adf5e7ad4746c0af00958c62a642b9f8de8110d1378afec43
|
7
|
+
data.tar.gz: 0eb84df60f7380f8ec498e28dcdd36ffc458e3392819e2ff91d2d2bdc0f35315e1f5175d772bbca9833fa3e4eb9d37803ebf71a1b100eb90db5baab9278439e4
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -28,9 +28,8 @@ Create a file for your daemon, e.g. `daemon.rb`:
|
|
28
28
|
|
29
29
|
# Very simple XMLRPC daemon
|
30
30
|
class XMLRPCDaemon < Process::Daemon
|
31
|
-
def
|
32
|
-
|
33
|
-
File.join(__dir__, "tmp")
|
31
|
+
def working_directory
|
32
|
+
File.expand_path("../tmp", __FILE__)
|
34
33
|
end
|
35
34
|
|
36
35
|
def startup
|
data/Rakefile
CHANGED
data/lib/process/daemon.rb
CHANGED
@@ -133,7 +133,23 @@ module Process
|
|
133
133
|
Process.kill(:INT, 0)
|
134
134
|
end
|
135
135
|
|
136
|
+
attr :title
|
137
|
+
|
138
|
+
# Set the process title - only works after daemon has forked.
|
139
|
+
def title= title
|
140
|
+
@title = title
|
141
|
+
|
142
|
+
if Process.respond_to? :setproctitle
|
143
|
+
Process.setproctitle(@title)
|
144
|
+
else
|
145
|
+
$0 = @title
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
136
149
|
def run
|
150
|
+
|
151
|
+
self.title = self.name
|
152
|
+
|
137
153
|
trap("INT") do
|
138
154
|
shutdown
|
139
155
|
end
|
data/process-daemon.gemspec
CHANGED
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_dependency "rainbow", "~> 2.0"
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
-
spec.add_development_dependency "
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0.0.rc1"
|
26
26
|
spec.add_development_dependency "rake"
|
27
27
|
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2007, 2009, 2011 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'process/daemon'
|
24
|
+
|
25
|
+
require 'webrick'
|
26
|
+
require 'webrick/https'
|
27
|
+
|
28
|
+
require 'xmlrpc/server'
|
29
|
+
require 'xmlrpc/client'
|
30
|
+
|
31
|
+
module Process
|
32
|
+
class Daemon
|
33
|
+
module DaemonSpec
|
34
|
+
# Very simple XMLRPC daemon
|
35
|
+
class XMLRPCDaemon < Process::Daemon
|
36
|
+
def working_directory
|
37
|
+
File.expand_path("../tmp", __FILE__)
|
38
|
+
end
|
39
|
+
|
40
|
+
def startup
|
41
|
+
puts "Starting server..."
|
42
|
+
|
43
|
+
@rpc_server = WEBrick::HTTPServer.new(
|
44
|
+
:Port => 31337,
|
45
|
+
:BindAddress => "0.0.0.0"
|
46
|
+
)
|
47
|
+
|
48
|
+
@listener = XMLRPC::WEBrickServlet.new
|
49
|
+
|
50
|
+
@listener.add_handler("add") do |amount|
|
51
|
+
@count ||= 0
|
52
|
+
@count += amount
|
53
|
+
end
|
54
|
+
|
55
|
+
@listener.add_handler("total") do
|
56
|
+
@count
|
57
|
+
end
|
58
|
+
|
59
|
+
@rpc_server.mount("/RPC2", @listener)
|
60
|
+
|
61
|
+
begin
|
62
|
+
puts "Daemon starting..."
|
63
|
+
@rpc_server.start
|
64
|
+
puts "Daemon stopping..."
|
65
|
+
rescue Interrupt
|
66
|
+
puts "Daemon interrupted..."
|
67
|
+
ensure
|
68
|
+
puts "Daemon shutdown..."
|
69
|
+
@rpc_server.shutdown
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def shutdown
|
74
|
+
puts "Stopping the RPC server..."
|
75
|
+
@rpc_server.stop
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class SleepDaemon < Process::Daemon
|
80
|
+
def working_directory
|
81
|
+
File.expand_path("../tmp", __FILE__)
|
82
|
+
end
|
83
|
+
|
84
|
+
def startup
|
85
|
+
sleep 1 while true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe Daemon do
|
90
|
+
before do
|
91
|
+
XMLRPCDaemon.start
|
92
|
+
end
|
93
|
+
|
94
|
+
after do
|
95
|
+
XMLRPCDaemon.stop
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should be running" do
|
99
|
+
expect(XMLRPCDaemon.status).to be == :running
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should respond to connections" do
|
103
|
+
rpc = XMLRPC::Client.new_from_uri("http://localhost:31337")
|
104
|
+
rpc.call("add", 10)
|
105
|
+
|
106
|
+
total = rpc.call("total")
|
107
|
+
|
108
|
+
expect(total).to be == 10
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should be a unique instance" do
|
112
|
+
expect(XMLRPCDaemon.instance).to_not be == SleepDaemon.instance
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should produce useful output" do
|
116
|
+
output = StringIO.new
|
117
|
+
|
118
|
+
controller = Process::Daemon::Controller.new(XMLRPCDaemon.instance, :output => output)
|
119
|
+
|
120
|
+
expect(controller.status).to be == :running
|
121
|
+
|
122
|
+
expect(output.string).to match /Daemon status: running pid=\d+/
|
123
|
+
|
124
|
+
output.rewind
|
125
|
+
controller.stop
|
126
|
+
|
127
|
+
expect(output.string).to match /Stopping/
|
128
|
+
|
129
|
+
output.rewind
|
130
|
+
controller.start
|
131
|
+
|
132
|
+
expect(output.string).to match /Starting/
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should have correct process title" do
|
136
|
+
pid = XMLRPCDaemon.controller.pid
|
137
|
+
|
138
|
+
title = `ps -p #{pid} -o command=`.strip
|
139
|
+
|
140
|
+
expect(title).to match /XMLRPCDaemon/
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: process-daemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.0.0.rc1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.0.0.rc1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,8 +85,8 @@ files:
|
|
85
85
|
- lib/process/daemon/process_file.rb
|
86
86
|
- lib/process/daemon/version.rb
|
87
87
|
- process-daemon.gemspec
|
88
|
-
-
|
89
|
-
-
|
88
|
+
- spec/process/daemon/daemon.rb
|
89
|
+
- spec/process/daemon/daemon_spec.rb
|
90
90
|
homepage: ''
|
91
91
|
licenses:
|
92
92
|
- MIT
|
@@ -113,5 +113,5 @@ specification_version: 4
|
|
113
113
|
summary: "`Process::Daemon` is a stable and helpful base class for long running tasks
|
114
114
|
and daemons. Provides standard `start`, `stop`, `restart`, `status` operations."
|
115
115
|
test_files:
|
116
|
-
-
|
117
|
-
-
|
116
|
+
- spec/process/daemon/daemon.rb
|
117
|
+
- spec/process/daemon/daemon_spec.rb
|
data/test/test_daemon.rb
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Copyright (c) 2007, 2009, 2011 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
22
|
-
|
23
|
-
require 'minitest/autorun'
|
24
|
-
|
25
|
-
require 'process/daemon'
|
26
|
-
|
27
|
-
require 'webrick'
|
28
|
-
require 'webrick/https'
|
29
|
-
|
30
|
-
require 'xmlrpc/server'
|
31
|
-
require 'xmlrpc/client'
|
32
|
-
|
33
|
-
# Very simple XMLRPC daemon
|
34
|
-
class XMLRPCDaemon < Process::Daemon
|
35
|
-
def working_directory
|
36
|
-
File.join(__dir__, "tmp")
|
37
|
-
end
|
38
|
-
|
39
|
-
def startup
|
40
|
-
puts "Starting server..."
|
41
|
-
|
42
|
-
@rpc_server = WEBrick::HTTPServer.new(
|
43
|
-
:Port => 31337,
|
44
|
-
:BindAddress => "0.0.0.0"
|
45
|
-
)
|
46
|
-
|
47
|
-
@listener = XMLRPC::WEBrickServlet.new
|
48
|
-
|
49
|
-
@listener.add_handler("add") do |amount|
|
50
|
-
@count ||= 0
|
51
|
-
@count += amount
|
52
|
-
end
|
53
|
-
|
54
|
-
@listener.add_handler("total") do
|
55
|
-
@count
|
56
|
-
end
|
57
|
-
|
58
|
-
@rpc_server.mount("/RPC2", @listener)
|
59
|
-
|
60
|
-
begin
|
61
|
-
puts "Daemon starting..."
|
62
|
-
@rpc_server.start
|
63
|
-
puts "Daemon stopping..."
|
64
|
-
rescue Interrupt
|
65
|
-
puts "Daemon interrupted..."
|
66
|
-
ensure
|
67
|
-
puts "Daemon shutdown..."
|
68
|
-
@rpc_server.shutdown
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def shutdown
|
73
|
-
puts "Stopping the RPC server..."
|
74
|
-
@rpc_server.stop
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
class SleepDaemon < Process::Daemon
|
79
|
-
def working_directory
|
80
|
-
File.join(__dir__, "tmp")
|
81
|
-
end
|
82
|
-
|
83
|
-
def startup
|
84
|
-
sleep 1 while true
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
class DaemonTest < MiniTest::Test
|
89
|
-
def setup
|
90
|
-
XMLRPCDaemon.start
|
91
|
-
end
|
92
|
-
|
93
|
-
def teardown
|
94
|
-
XMLRPCDaemon.stop
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_connection
|
98
|
-
rpc = XMLRPC::Client.new_from_uri("http://localhost:31337")
|
99
|
-
rpc.call("add", 10)
|
100
|
-
|
101
|
-
total = rpc.call("total")
|
102
|
-
|
103
|
-
assert_equal 10, total
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_instances
|
107
|
-
refute_equal SleepDaemon.instance, XMLRPCDaemon.instance
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_output
|
111
|
-
output = StringIO.new
|
112
|
-
|
113
|
-
controller = Process::Daemon::Controller.new(XMLRPCDaemon.instance, :output => output)
|
114
|
-
|
115
|
-
assert_equal :running, controller.status
|
116
|
-
|
117
|
-
assert_match /Daemon status: running pid=\d+/, output.string
|
118
|
-
|
119
|
-
output.rewind
|
120
|
-
controller.stop
|
121
|
-
|
122
|
-
assert_match /Stopping daemon/, output.string
|
123
|
-
|
124
|
-
output.rewind
|
125
|
-
controller.start
|
126
|
-
|
127
|
-
assert_match /Starting daemon/, output.string
|
128
|
-
end
|
129
|
-
end
|