daemon_controller 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -25,8 +25,20 @@ It provides the following functionality:
25
25
  * Stopping daemons.
26
26
  * Checking whether a daemon is running.
27
27
 
28
+ ## Installation
28
29
 
29
- ## What is it for?
30
+ gem install daemon_controller
31
+
32
+
33
+ ## Resources
34
+
35
+ * [Website](http://github.com/FooBarWidget/daemon_controller)
36
+ * [Git repository](git://github.com/FooBarWidget/daemon_controller.git)
37
+ * [RubyForge project](http://rubyforge.org/projects/daemoncontrol/)
38
+
39
+
40
+ What is it for?
41
+ ===============
30
42
 
31
43
  There is a lot of software (both Rails related and unrelated) which rely on
32
44
  servers or daemons. To name a few, in no particular order:
@@ -1,7 +1,8 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "daemon_controller"
3
- s.version = "0.2.2"
4
- s.date = "2009-11-06"
3
+ # Don't forget to update version.rb too.
4
+ s.version = "0.2.3"
5
+ s.date = "2009-11-13"
5
6
  s.summary = "A library for implementing daemon management capabilities"
6
7
  s.email = "hongli@phusion.nl"
7
8
  s.homepage = "http://github.com/FooBarWidget/daemon_controller/tree/master"
@@ -13,6 +14,7 @@ Gem::Specification.new do |s|
13
14
  "README.markdown", "LICENSE.txt", "daemon_controller.gemspec",
14
15
  "lib/daemon_controller.rb",
15
16
  "lib/daemon_controller/lock_file.rb",
17
+ "lib/daemon_controller/version.rb",
16
18
  "spec/test_helper.rb",
17
19
  "spec/daemon_controller_spec.rb",
18
20
  "spec/echo_server.rb"
@@ -0,0 +1,27 @@
1
+ # daemon_controller, library for robust daemon management
2
+ # Copyright (c) 2009 Phusion
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+
22
+ class DaemonController
23
+ MAJOR = 0
24
+ MINOR = 2
25
+ TINY = 3
26
+ VERSION_STRING = "#{MAJOR}.#{MINOR}.#{TINY}"
27
+ end # class DaemonController
@@ -59,7 +59,11 @@ class DaemonController
59
59
  #
60
60
  # [:start_command]
61
61
  # The command to start the daemon. This must be a a String, e.g.
62
- # "mongrel_rails start -e production".
62
+ # "mongrel_rails start -e production", or a Proc which returns a String.
63
+ #
64
+ # If the value is a Proc, and the +before_start+ option is given too, then
65
+ # the +start_command+ Proc is guaranteed to be called after the +before_start+
66
+ # Proc is called.
63
67
  #
64
68
  # [:ping_command]
65
69
  # The ping command is used to check whether the daemon can be connected to.
@@ -341,7 +345,11 @@ private
341
345
  end
342
346
 
343
347
  def spawn_daemon
344
- run_command(@start_command)
348
+ if @start_command.respond_to?(:call)
349
+ run_command(@start_command.call)
350
+ else
351
+ run_command(@start_command)
352
+ end
345
353
  end
346
354
 
347
355
  def kill_daemon
@@ -158,6 +158,34 @@ describe DaemonController, "#start" do
158
158
  e.message.should =~ /crashing, as instructed/
159
159
  end
160
160
  end
161
+
162
+ specify "the start command may be a Proc" do
163
+ called = true
164
+ new_controller(:start_command => lambda { called = true; @start_command })
165
+ begin
166
+ @controller.start
167
+ ensure
168
+ @controller.stop
169
+ end
170
+ called.should be_true
171
+ end
172
+
173
+ specify "if the start command is a Proc then it is called after before_start" do
174
+ log = []
175
+ new_controller(
176
+ :start_command => lambda {
177
+ log << "start_command"
178
+ @start_command
179
+ },
180
+ :before_start => lambda { log << "before_start" }
181
+ )
182
+ begin
183
+ @controller.start
184
+ ensure
185
+ @controller.stop
186
+ end
187
+ log.should == ["before_start", "start_command"]
188
+ end
161
189
  end
162
190
 
163
191
  describe DaemonController, "#stop" do
data/spec/test_helper.rb CHANGED
@@ -4,22 +4,22 @@ Dir.chdir(root)
4
4
 
5
5
  module TestHelper
6
6
  def new_controller(options = {})
7
- start_command = './spec/echo_server.rb -l spec/echo_server.log -P spec/echo_server.pid'
7
+ @start_command = './spec/echo_server.rb -l spec/echo_server.log -P spec/echo_server.pid'
8
8
  if options[:wait1]
9
- start_command << " --wait1 #{options[:wait1]}"
9
+ @start_command << " --wait1 #{options[:wait1]}"
10
10
  end
11
11
  if options[:wait2]
12
- start_command << " --wait2 #{options[:wait2]}"
12
+ @start_command << " --wait2 #{options[:wait2]}"
13
13
  end
14
14
  if options[:stop_time]
15
- start_command << " --stop-time #{options[:stop_time]}"
15
+ @start_command << " --stop-time #{options[:stop_time]}"
16
16
  end
17
17
  if options[:crash_before_bind]
18
- start_command << " --crash-before-bind"
18
+ @start_command << " --crash-before-bind"
19
19
  end
20
20
  new_options = {
21
21
  :identifier => 'My Test Daemon',
22
- :start_command => start_command,
22
+ :start_command => @start_command,
23
23
  :ping_command => proc do
24
24
  begin
25
25
  TCPSocket.new('127.0.0.1', 3230)
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daemon_controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
- - Hongli Lai
7
+ - Hongli Lai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-06 00:00:00 +01:00
12
+ date: 2009-11-13 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,14 +22,15 @@ extensions: []
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
- - README.markdown
26
- - LICENSE.txt
27
- - daemon_controller.gemspec
28
- - lib/daemon_controller.rb
29
- - lib/daemon_controller/lock_file.rb
30
- - spec/test_helper.rb
31
- - spec/daemon_controller_spec.rb
32
- - spec/echo_server.rb
25
+ - README.markdown
26
+ - LICENSE.txt
27
+ - daemon_controller.gemspec
28
+ - lib/daemon_controller.rb
29
+ - lib/daemon_controller/lock_file.rb
30
+ - lib/daemon_controller/version.rb
31
+ - spec/test_helper.rb
32
+ - spec/daemon_controller_spec.rb
33
+ - spec/echo_server.rb
33
34
  has_rdoc: true
34
35
  homepage: http://github.com/FooBarWidget/daemon_controller/tree/master
35
36
  licenses: []
@@ -38,18 +39,18 @@ post_install_message:
38
39
  rdoc_options: []
39
40
 
40
41
  require_paths:
41
- - lib
42
+ - lib
42
43
  required_ruby_version: !ruby/object:Gem::Requirement
43
44
  requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "0"
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
47
48
  version:
48
49
  required_rubygems_version: !ruby/object:Gem::Requirement
49
50
  requirements:
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: "0"
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
53
54
  version:
54
55
  requirements: []
55
56