servolux 0.9.0 → 0.9.1

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.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.9.1 / 2010-01-21
2
+
3
+ * Bug Fixes
4
+ * Addressing daemon startup issues
5
+ * Calling a non-existent piper method from the daemon class
6
+
1
7
  == 0.9.0 / 2009-11-30
2
8
 
3
9
  * Minor Enhancements
data/lib/servolux.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  module Servolux
3
3
 
4
4
  # :stopdoc:
5
- VERSION = '0.9.0'
5
+ VERSION = '0.9.1'
6
6
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
7
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
8
  # :startdoc:
@@ -232,7 +232,7 @@ class Servolux::Daemon
232
232
  @piper = ::Servolux::Piper.daemon(nochdir, noclose)
233
233
 
234
234
  @piper.parent {
235
- @piper.timeout = 0
235
+ @piper.timeout = 0.1
236
236
  wait_for_startup
237
237
  exit!(0)
238
238
  }
@@ -340,7 +340,7 @@ class Servolux::Daemon
340
340
  def exec( *args )
341
341
  logger.debug "Calling: exec(*#{args.inspect})"
342
342
  skip = [STDIN, STDOUT, STDERR]
343
- skip << @piper.write_io if @piper
343
+ skip << @piper.socket if @piper
344
344
  ObjectSpace.each_object(IO) { |obj|
345
345
  next if skip.include? obj
346
346
  obj.close rescue nil
@@ -409,6 +409,11 @@ class Servolux::Daemon
409
409
  attr_accessor :filename
410
410
  attr_reader :look_for
411
411
 
412
+ def initialize
413
+ @filename = nil
414
+ @look_for = nil
415
+ end
416
+
412
417
  def look_for=( val )
413
418
  case val
414
419
  when nil; @look_for = nil
@@ -421,9 +426,7 @@ class Servolux::Daemon
421
426
  end
422
427
 
423
428
  def stat
424
- if @filename and test(?f, @filename)
425
- File.stat @filename
426
- end
429
+ File.stat(@filename) if @filename and test(?f, @filename)
427
430
  end
428
431
 
429
432
  def updated?
@@ -93,6 +93,9 @@ class Servolux::Piper
93
93
  # The timeout in seconds to wait for puts / gets commands.
94
94
  attr_accessor :timeout
95
95
 
96
+ # The underlying socket the piper is using for communication.
97
+ attr_reader :socket
98
+
96
99
  # @overload Piper.new( mode = 'r', opts = {} )
97
100
  # Creates a new Piper instance with the communication pipe configured
98
101
  # using the provided _mode_. The default mode is read-only (from the
@@ -0,0 +1,71 @@
1
+
2
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
3
+ require 'logger'
4
+ require 'fileutils'
5
+
6
+ if Servolux.fork?
7
+
8
+ describe Servolux::Daemon do
9
+
10
+ TestServer = Module.new {
11
+ def before_starting() @counter = 0; end
12
+ def after_stopping() exit!(0); end
13
+ def run
14
+ @counter += 1
15
+ logger.info "executing run loop [#@counter]"
16
+ end
17
+ }
18
+
19
+ log_fn = File.join(Dir.pwd, 'tmp.log')
20
+ pid_fn = File.join(Dir.pwd, 'tmp.pid')
21
+
22
+ before(:each) do
23
+ FileUtils.rm_f [log_fn, pid_fn]
24
+ @logger = Logger.new log_fn
25
+ end
26
+
27
+ after(:each) do
28
+ @daemon.shutdown if defined? @daemon and @daemon
29
+ FileUtils.rm_f [log_fn, pid_fn]
30
+ end
31
+
32
+ it 'waits for an updated logfile when starting' do
33
+ server = Servolux::Server.new('Hey You', :logger => @logger, :interval => 2, :pid_file => pid_fn)
34
+ server.extend TestServer
35
+ @daemon = Servolux::Daemon.new(:server => server, :log_file => log_fn, :timeout => 8)
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
+ }
44
+ end
45
+
46
+ it 'waits for a particular line to appear in the log file' do
47
+ server = Servolux::Server.new('Hey You', :logger => @logger, :interval => 1, :pid_file => pid_fn)
48
+ server.extend TestServer
49
+ @daemon = Servolux::Daemon.new(:server => server, :log_file => log_fn, :look_for => 'executing run loop [2]', :timeout => 8)
50
+
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
+ }
58
+ end
59
+
60
+ it 'raises an error if the startup timeout is exceeded' do
61
+ server = Servolux::Server.new('Hey You', :logger => @logger, :interval => 3600, :pid_file => pid_fn)
62
+ server.extend TestServer
63
+ @daemon = Servolux::Daemon.new(:server => server, :log_file => log_fn, :look_for => 'executing run loop [42]', :timeout => 4)
64
+
65
+ lambda { @daemon.startup }.should raise_error(Servolux::Daemon::Timeout)
66
+ end
67
+
68
+ end
69
+
70
+ end # if Servolux.fork?
71
+
data/spec/piper_spec.rb CHANGED
@@ -60,7 +60,7 @@ describe Servolux::Piper do
60
60
  @piper.gets.should == 2
61
61
  @piper.gets.should == 3
62
62
 
63
- @piper.timeout = 0
63
+ @piper.timeout = 0.1
64
64
  @piper.readable?.should be_false
65
65
  }
66
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servolux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Pease
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-30 00:00:00 -07:00
12
+ date: 2010-01-21 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.2.0
23
+ version: 1.2.2
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bones-git
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 1.2.2
43
+ version: 1.3.0
44
44
  version:
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: rspec
@@ -60,7 +60,7 @@ dependencies:
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 3.1.0
63
+ version: 3.2.0
64
64
  version:
65
65
  description: |-
66
66
  Serv-O-Lux is a collection of Ruby classes that are useful for daemon and
@@ -90,6 +90,7 @@ files:
90
90
  - lib/servolux/server.rb
91
91
  - lib/servolux/threaded.rb
92
92
  - spec/child_spec.rb
93
+ - spec/daemon_spec.rb
93
94
  - spec/piper_spec.rb
94
95
  - spec/prefork_spec.rb
95
96
  - spec/server_spec.rb