process-daemon 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21fd4815d28972123439e807a1e57df28f451f90
4
- data.tar.gz: 50b53976e7f7e5800092b7e0b5c612863d718c1b
3
+ metadata.gz: 576478e27475cd8801ce2ea13053480531c13ea4
4
+ data.tar.gz: 8ec4d0c286a5d0630c357ec529b54611abf54204
5
5
  SHA512:
6
- metadata.gz: fb95d20032105ecde239c38b303deab08312fe3fb9c572b64a4d663942ed9f077044da8415157c965e41d4dc69e17fdf20df982c7331f259f423c98b7610f89d
7
- data.tar.gz: 6fb6c323210283f063d74032157d1f9c4399963eba4e209063c1c828e255205e5cb8f9725439d7d9f43fe72e0a18ac4f89645f497e69325d1cdfa4dcf60212d2
6
+ metadata.gz: ffba1f40b923721772b95a2544c1e1ef1a19a9a2547fe92f41109cfb9802c4b30759a07382b1619adf5e7ad4746c0af00958c62a642b9f8de8110d1378afec43
7
+ data.tar.gz: 0eb84df60f7380f8ec498e28dcdd36ffc458e3392819e2ff91d2d2bdc0f35315e1f5175d772bbca9833fa3e4eb9d37803ebf71a1b100eb90db5baab9278439e4
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "2.0"
4
- - "2.1"
3
+ - 1.9
4
+ - 2.0
5
+ - 2.1
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 base_directory
32
- # Should be an absolute path:
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
@@ -1,9 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
- require "rake/testtask"
2
+ require "rspec/core/rake_task"
3
3
 
4
- Rake::TestTask.new do |t|
5
- t.libs << 'test'
6
- end
4
+ RSpec::Core::RakeTask.new(:spec)
7
5
 
8
- desc "Run tests"
9
- task :default => :test
6
+ task :default => :spec
@@ -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
@@ -154,6 +154,10 @@ module Process
154
154
  return daemon_state
155
155
  end
156
156
 
157
+ def pid
158
+ ProcessFile.recall(@daemon)
159
+ end
160
+
157
161
  # How long to wait between checking the daemon process when shutting down:
158
162
  STOP_PERIOD = 0.1
159
163
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Process
22
22
  class Daemon
23
- VERSION = "0.5.3"
23
+ VERSION = "0.5.4"
24
24
  end
25
25
  end
@@ -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 "minitest", "~> 5.3.2"
25
+ spec.add_development_dependency "rspec", "~> 3.0.0.rc1"
26
26
  spec.add_development_dependency "rake"
27
27
  end
@@ -9,8 +9,8 @@ require 'xmlrpc/server'
9
9
 
10
10
  # Very simple XMLRPC daemon
11
11
  class XMLRPCDaemon < Process::Daemon
12
- def base_directory
13
- File.join(__dir__, "tmp")
12
+ def working_directory
13
+ File.expand_path("../tmp", __FILE__)
14
14
  end
15
15
 
16
16
  def startup
@@ -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.3
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-16 00:00:00.000000000 Z
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: minitest
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 5.3.2
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: 5.3.2
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
- - test/daemon.rb
89
- - test/test_daemon.rb
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
- - test/daemon.rb
117
- - test/test_daemon.rb
116
+ - spec/process/daemon/daemon.rb
117
+ - spec/process/daemon/daemon_spec.rb
@@ -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