process-daemon 0.5.4 → 0.5.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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ece8e79345bfaabb606ac9b0b2be85dc176ff1d
|
4
|
+
data.tar.gz: f199756be6f1625ee83a19795a111f67e8672406
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 718589f9efa869b8256c065f74b8e6b234722a8e6862060f0fa1faf4f6b46fd92d3952f702e160d4ad9d1a3f0778c75d19e8609bb98ba7685af180b90d44eae2
|
7
|
+
data.tar.gz: c5063b89bda0d750da4298b318d91cdd914cb6c225e06562a4ca6b3975f7fa5c507a6b81812ae2f4788119fc1c562075e5286caf6fb8ddd944e5944e756bca59
|
@@ -39,7 +39,7 @@ module Process
|
|
39
39
|
|
40
40
|
# This function is called from the daemon executable. It processes ARGV and checks whether the user is asking for `start`, `stop`, `restart`, `status`.
|
41
41
|
def daemonize(argv = ARGV)
|
42
|
-
case argv.shift.to_sym
|
42
|
+
case (argv.shift || :default).to_sym
|
43
43
|
when :start
|
44
44
|
start
|
45
45
|
status
|
@@ -55,7 +55,7 @@ module Process
|
|
55
55
|
when :status
|
56
56
|
status
|
57
57
|
else
|
58
|
-
@
|
58
|
+
@output.puts Rainbow("Invalid command. Please specify start, restart, stop or status.").red
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -28,118 +28,114 @@ require 'webrick/https'
|
|
28
28
|
require 'xmlrpc/server'
|
29
29
|
require 'xmlrpc/client'
|
30
30
|
|
31
|
-
module Process
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
31
|
+
module Process::Daemon::DaemonSpec
|
32
|
+
# Very simple XMLRPC daemon
|
33
|
+
class XMLRPCDaemon < Process::Daemon
|
34
|
+
def working_directory
|
35
|
+
File.expand_path("../tmp", __FILE__)
|
36
|
+
end
|
37
|
+
|
38
|
+
def startup
|
39
|
+
puts "Starting server..."
|
78
40
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
41
|
+
@rpc_server = WEBrick::HTTPServer.new(
|
42
|
+
:Port => 31337,
|
43
|
+
:BindAddress => "0.0.0.0"
|
44
|
+
)
|
45
|
+
|
46
|
+
@listener = XMLRPC::WEBrickServlet.new
|
47
|
+
|
48
|
+
@listener.add_handler("add") do |amount|
|
49
|
+
@count ||= 0
|
50
|
+
@count += amount
|
51
|
+
end
|
83
52
|
|
84
|
-
|
85
|
-
|
86
|
-
end
|
53
|
+
@listener.add_handler("total") do
|
54
|
+
@count
|
87
55
|
end
|
88
56
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
57
|
+
@rpc_server.mount("/RPC2", @listener)
|
58
|
+
|
59
|
+
begin
|
60
|
+
puts "Daemon starting..."
|
61
|
+
@rpc_server.start
|
62
|
+
puts "Daemon stopping..."
|
63
|
+
rescue Interrupt
|
64
|
+
puts "Daemon interrupted..."
|
65
|
+
ensure
|
66
|
+
puts "Daemon shutdown..."
|
67
|
+
@rpc_server.shutdown
|
142
68
|
end
|
143
69
|
end
|
70
|
+
|
71
|
+
def shutdown
|
72
|
+
puts "Stopping the RPC server..."
|
73
|
+
@rpc_server.stop
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class SleepDaemon < Process::Daemon
|
78
|
+
def working_directory
|
79
|
+
File.expand_path("../tmp", __FILE__)
|
80
|
+
end
|
81
|
+
|
82
|
+
def startup
|
83
|
+
sleep 1 while true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe Process::Daemon do
|
88
|
+
before do
|
89
|
+
XMLRPCDaemon.start
|
90
|
+
end
|
91
|
+
|
92
|
+
after do
|
93
|
+
XMLRPCDaemon.stop
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should be running" do
|
97
|
+
expect(XMLRPCDaemon.status).to be == :running
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should respond to connections" do
|
101
|
+
rpc = XMLRPC::Client.new_from_uri("http://localhost:31337")
|
102
|
+
rpc.call("add", 10)
|
103
|
+
|
104
|
+
total = rpc.call("total")
|
105
|
+
|
106
|
+
expect(total).to be == 10
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should be a unique instance" do
|
110
|
+
expect(XMLRPCDaemon.instance).to_not be == SleepDaemon.instance
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should produce useful output" do
|
114
|
+
output = StringIO.new
|
115
|
+
|
116
|
+
controller = Process::Daemon::Controller.new(XMLRPCDaemon.instance, :output => output)
|
117
|
+
|
118
|
+
expect(controller.status).to be == :running
|
119
|
+
|
120
|
+
expect(output.string).to match /Daemon status: running pid=\d+/
|
121
|
+
|
122
|
+
output.rewind
|
123
|
+
controller.stop
|
124
|
+
|
125
|
+
expect(output.string).to match /Stopping/
|
126
|
+
|
127
|
+
output.rewind
|
128
|
+
controller.start
|
129
|
+
|
130
|
+
expect(output.string).to match /Starting/
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should have correct process title" do
|
134
|
+
pid = XMLRPCDaemon.controller.pid
|
135
|
+
|
136
|
+
title = `ps -p #{pid} -o command=`.strip
|
137
|
+
|
138
|
+
expect(title).to match /XMLRPCDaemon/
|
139
|
+
end
|
144
140
|
end
|
145
141
|
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.5
|
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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|
@@ -81,7 +81,7 @@ files:
|
|
81
81
|
- lib/process/daemon.rb
|
82
82
|
- lib/process/daemon/controller.rb
|
83
83
|
- lib/process/daemon/log_file.rb
|
84
|
-
- lib/process/daemon/
|
84
|
+
- lib/process/daemon/privileges.rb
|
85
85
|
- lib/process/daemon/process_file.rb
|
86
86
|
- lib/process/daemon/version.rb
|
87
87
|
- process-daemon.gemspec
|