servolux 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.9.4 / 2010-04-18
2
+
3
+ * Bug Fixes
4
+ * Elminated race condition in logfile watching [Avdi Grimm]
5
+ * Made program exit optionalx [Avdi Grimm]
6
+
1
7
  == 0.9.3 / 2010-03-10
2
8
 
3
9
  * Updated to the latest version of Mr Bones
data/Rakefile CHANGED
@@ -15,9 +15,7 @@ Bones {
15
15
  url 'http://gemcutter.org/gems/servolux'
16
16
  readme_file 'README.rdoc'
17
17
  ignore_file '.gitignore'
18
-
19
18
  spec.opts << '--color'
20
- rubyforge.name 'codeforpeople'
21
19
 
22
20
  use_gmail
23
21
 
@@ -1,3 +1,5 @@
1
+ require 'ostruct'
2
+
1
3
  # == Synopsis
2
4
  # The Daemon takes care of the work of creating and managing daemon
3
5
  # processes from Ruby.
@@ -220,21 +222,26 @@ class Servolux::Daemon
220
222
  @logfile_reader.look_for = val
221
223
  end
222
224
 
223
- # Start the daemon process.
225
+ # Start the daemon process. Passing in +false+ to this method will prevent
226
+ # the parent from exiting after the daemon process starts.
224
227
  #
225
228
  # @return [Daemon] self
226
229
  #
227
- def startup
230
+ def startup( do_exit = true )
228
231
  raise Error, "Fork is not supported in this Ruby environment." unless ::Servolux.fork?
229
232
  return if alive?
230
233
 
231
234
  logger.debug "About to fork ..."
232
235
  @piper = ::Servolux::Piper.daemon(nochdir, noclose)
233
236
 
237
+ # Make sure we have an idea of the state of the log file BEFORE the child
238
+ # gets a chance to write to it.
239
+ @logfile_reader.updated? if @logfile_reader
240
+
234
241
  @piper.parent {
235
242
  @piper.timeout = 0.1
236
243
  wait_for_startup
237
- exit!(0)
244
+ exit!(0) if do_exit
238
245
  }
239
246
 
240
247
  @piper.child { run_startup_command }
@@ -426,7 +433,8 @@ class Servolux::Daemon
426
433
  end
427
434
 
428
435
  def stat
429
- File.stat(@filename) if @filename and test(?f, @filename)
436
+ s = File.stat(@filename) if @filename && test(?f, @filename)
437
+ s || OpenStruct.new(:mtime => Time.at(0), :size => 0)
430
438
  end
431
439
 
432
440
  def updated?
data/spec/daemon_spec.rb CHANGED
@@ -25,7 +25,7 @@ describe Servolux::Daemon do
25
25
  end
26
26
 
27
27
  after(:each) do
28
- @daemon.shutdown if defined? @daemon and @daemon
28
+ @daemon.shutdown if defined? @daemon && @daemon
29
29
  FileUtils.rm_f [log_fn, pid_fn]
30
30
  end
31
31
 
@@ -34,13 +34,8 @@ describe Servolux::Daemon do
34
34
  server.extend TestServer
35
35
  @daemon = Servolux::Daemon.new(:server => server, :log_file => log_fn, :timeout => 8)
36
36
 
37
- piper = Servolux::Piper.new 'r'
38
- piper.child { @daemon.startup }
39
- piper.parent {
40
- Process.wait piper.pid
41
- $?.exitstatus.should == 0
42
- @daemon.should be_alive
43
- }
37
+ @daemon.startup false
38
+ @daemon.should be_alive
44
39
  end
45
40
 
46
41
  it 'waits for a particular line to appear in the log file' do
@@ -48,13 +43,8 @@ describe Servolux::Daemon do
48
43
  server.extend TestServer
49
44
  @daemon = Servolux::Daemon.new(:server => server, :log_file => log_fn, :look_for => 'executing run loop [2]', :timeout => 8)
50
45
 
51
- piper = Servolux::Piper.new 'r'
52
- piper.child { @daemon.startup }
53
- piper.parent {
54
- Process.wait piper.pid
55
- $?.exitstatus.should == 0
56
- @daemon.should be_alive
57
- }
46
+ @daemon.startup false
47
+ @daemon.should be_alive
58
48
  end
59
49
 
60
50
  it 'raises an error if the startup timeout is exceeded' do
data/spec/server_spec.rb CHANGED
@@ -34,20 +34,30 @@ describe Servolux::Server do
34
34
  it 'generates a PID file with mode rw-r----- by default' do
35
35
  t = Thread.new {@server.startup}
36
36
  Thread.pass until @server.running? and t.status == 'sleep'
37
+ test(?e, @server.pid_file).should be_true
37
38
 
38
39
  @log_output.readline.chomp.should == %q(DEBUG Servolux : Server "Test Server" creating pid file "test_server.pid")
39
40
  @log_output.readline.chomp.should == %q(DEBUG Servolux : Starting)
40
41
  (File.stat(@server.pid_file).mode & 0777).should == 0640
42
+
43
+ @server.shutdown
44
+ Thread.pass until t.status == false
45
+ test(?e, @server.pid_file).should be_false
41
46
  end
42
47
 
43
48
  it 'generates PID file with the specified permissions' do
44
49
  @server.pid_file_mode = 0400
45
50
  t = Thread.new {@server.startup}
46
51
  Thread.pass until @server.running? and t.status == 'sleep'
52
+ test(?e, @server.pid_file).should be_true
47
53
 
48
54
  @log_output.readline.chomp.should == %q(DEBUG Servolux : Server "Test Server" creating pid file "test_server.pid")
49
55
  @log_output.readline.chomp.should == %q(DEBUG Servolux : Starting)
50
56
  (File.stat(@server.pid_file).mode & 0777).should == 0400
57
+
58
+ @server.shutdown
59
+ Thread.pass until t.status == false
60
+ test(?e, @server.pid_file).should be_false
51
61
  end
52
62
 
53
63
  it 'shuts down gracefully when signaled' do
data/version.txt CHANGED
@@ -1 +1 @@
1
- 0.9.3
1
+ 0.9.4
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 3
9
- version: 0.9.3
8
+ - 4
9
+ version: 0.9.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tim Pease
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-10 00:00:00 -07:00
17
+ date: 2010-04-18 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -54,9 +54,9 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  segments:
56
56
  - 1
57
- - 3
58
- - 0
59
- version: 1.3.0
57
+ - 4
58
+ - 1
59
+ version: 1.4.1
60
60
  type: :development
61
61
  version_requirements: *id003
62
62
  - !ruby/object:Gem::Dependency
@@ -83,8 +83,8 @@ dependencies:
83
83
  segments:
84
84
  - 3
85
85
  - 4
86
- - 0
87
- version: 3.4.0
86
+ - 1
87
+ version: 3.4.1
88
88
  type: :development
89
89
  version_requirements: *id005
90
90
  description: |-
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  version: "0"
151
151
  requirements: []
152
152
 
153
- rubyforge_project: codeforpeople
153
+ rubyforge_project: servolux
154
154
  rubygems_version: 1.3.6
155
155
  signing_key:
156
156
  specification_version: 3