serverengine 1.5.7 → 1.5.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWJjNGIwYzAzZWFiOWYzNjMzODhiZGMyOTI0YzgwMzQ0MjRlMWFjMA==
5
+ data.tar.gz: !binary |-
6
+ YTI2MGEzN2E3Yjc5NzUxZTY2YjYwMWZkYmIyN2VkOTM5OTA4MGQ0MA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTI3ZDNiN2I2MGQxYTBmZWQwZWU2ZGFmNDRkYTE5MGZjMWY1YzZkMDJlYTM5
10
+ M2JiZTBhZWI1MGQwMTlhNGM2MzQwMjNkODEyYmY3ODk3ZTIxNTY3NWQxZGQ5
11
+ MGQzNTIxYjA4NGZhYTI1Y2Y4OWI4MzhkNWY2ZjY1NTg2NGMwNWE=
12
+ data.tar.gz: !binary |-
13
+ MzkxNmJiZTU1ZmRlNzgyYzZhMmRmOGVmOTI0MWI2NDU4MjlkMjE1OWIxM2M5
14
+ MGYyMjNmYmZhOGJlNDcwNmI1NDZiNTQ1MzcyYTljMGZhMzVkMzkxYWU0ZjYz
15
+ MTU4YTAyYTdlMjYwM2QwMTE0OTIxMTMyNmQ3Mzg1MjU3MTE1ODY=
data/.travis.yml CHANGED
@@ -3,6 +3,7 @@ language: ruby
3
3
  rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
+ - 2.1.2
6
7
 
7
8
  branches:
8
9
  only:
data/Changelog CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ 2014-06-27 version 1.5.8:
3
+
4
+ * Use standard LogDevice on Ruby >= 2.1.0 imporoved at https://github.com/ruby/ruby/pull/428
5
+
6
+
2
7
  2013-10-31 version 1.5.7:
3
8
 
4
9
  * Fixed :log parameter handling
@@ -21,11 +21,16 @@ module ServerEngine
21
21
 
22
22
  class DaemonLogger < Logger
23
23
  def initialize(logdev, config={})
24
- rotate_age = config[:log_rotate_age] || 5
25
- rotate_size = config[:log_rotate_size] || 1048576
24
+ @rotate_age = config[:log_rotate_age] || 5
25
+ @rotate_size = config[:log_rotate_size] || 1048576
26
26
 
27
- @file_dev = MultiprocessFileLogDevice.new(nil,
28
- shift_age: rotate_age, shift_size: rotate_size)
27
+ if RUBY_VERSION < "2.1.0"
28
+ # Ruby < 2.1.0 has a problem around log rotation with multiprocess:
29
+ # https://github.com/ruby/ruby/pull/428
30
+ @logdev_class = MultiprocessFileLogDevice
31
+ else
32
+ @logdev_class = LogDevice
33
+ end
29
34
 
30
35
  super(nil)
31
36
 
@@ -39,10 +44,16 @@ module ServerEngine
39
44
  # IO
40
45
  @logdev = logdev
41
46
  @logdev.sync = true if @logdev.respond_to?(:sync=)
42
- @file_dev.path = nil
43
- else
44
- # path string
45
- @file_dev.path = logdev
47
+ if @file_dev
48
+ old_file_dev = @file_dev
49
+ @file_dev = nil
50
+ old_file_dev.close
51
+ end
52
+ elsif !@file_dev || @file_dev.filename != logdev
53
+ # update path string
54
+ old_file_dev = @file_dev
55
+ @file_dev = @logdev_class.new(logdev, shift_age: @rotate_age, shift_size: @rotate_size)
56
+ old_file_dev.close if old_file_dev
46
57
  @logdev = @file_dev
47
58
  end
48
59
  logdev
@@ -98,7 +109,7 @@ module ServerEngine
98
109
  def trace?; @level <= TRACE; end
99
110
 
100
111
  def reopen!
101
- @file_dev.reopen!
112
+ @file_dev.reopen! if @file_dev
102
113
  nil
103
114
  end
104
115
 
@@ -113,7 +124,7 @@ module ServerEngine
113
124
  end
114
125
 
115
126
  def close
116
- @file_dev.close
127
+ @file_dev.close if @file_dev
117
128
  nil
118
129
  end
119
130
 
@@ -162,8 +173,6 @@ module ServerEngine
162
173
  nil
163
174
  end
164
175
 
165
- attr_reader :path
166
-
167
176
  def reopen!
168
177
  @mutex.synchronize do
169
178
  if @file
@@ -210,13 +219,14 @@ module ServerEngine
210
219
  begin
211
220
  lock.flock(File::LOCK_EX)
212
221
  ino = lock.stat.ino
213
- if ino == File.stat(@path).ino
222
+ if ino == File.stat(@path).ino and ino == stat.ino
214
223
  # 3)
215
224
  log_rotate
216
225
  else
217
- reopen!
226
+ @file.reopen(@path, 'a')
227
+ @file.sync = true
218
228
  end
219
- rescue
229
+ ensure
220
230
  lock.close
221
231
  end
222
232
  rescue Errno::ENOENT => e
@@ -1,3 +1,3 @@
1
1
  module ServerEngine
2
- VERSION = "1.5.7"
2
+ VERSION = "1.5.8"
3
3
  end
@@ -109,23 +109,25 @@ describe ServerEngine::DaemonLogger do
109
109
  end
110
110
 
111
111
  it 'rotation' do
112
- log = DaemonLogger.new("tmp/se1.log", level: 'trace', log_rotate_age: 3, log_rotate_size: 10)
113
- log.warn "test1"
112
+ log = DaemonLogger.new("tmp/se1.log", level: 'trace', log_rotate_age: 3, log_rotate_size: 10000)
113
+ # 100 bytes
114
+ log.warn "test1"*20
114
115
  File.exist?("tmp/se1.log").should == true
115
116
  File.exist?("tmp/se1.log.0").should == false
116
117
 
117
- log.warn "test2"
118
+ # 10000 bytes
119
+ 100.times { log.warn "test2"*20 }
118
120
  File.exist?("tmp/se1.log").should == true
119
121
  File.exist?("tmp/se1.log.0").should == true
120
122
  File.read("tmp/se1.log.0") =~ /test2$/
121
123
 
122
- log.warn "test3"
123
- log.warn "test4"
124
+ # 10000 bytes
125
+ 100.times { log.warn "test3"*20 }
124
126
  File.exist?("tmp/se1.log").should == true
125
- File.exist?("tmp/se1.log.2").should == true
126
- File.exist?("tmp/se1.log.3").should == false
127
+ File.exist?("tmp/se1.log.1").should == true
128
+ File.exist?("tmp/se1.log.2").should == false
127
129
 
128
- log.warn "test5"
130
+ log.warn "test4"*20
129
131
  File.read("tmp/se1.log.0") =~ /test5$/
130
132
  end
131
133
 
@@ -138,4 +140,27 @@ describe ServerEngine::DaemonLogger do
138
140
  log.debug "stdout logging test"
139
141
  log.reopen!
140
142
  end
143
+
144
+ it 'inter-process locking on rotation' do
145
+ log = DaemonLogger.new("tmp/se1.log", level: 'trace', log_rotate_age: 3, log_rotate_size: 10)
146
+ r, w = IO.pipe
147
+ $stderr = w # To capture #warn output in DaemonLogger
148
+ pid1 = Process.fork do
149
+ 10.times do
150
+ log.info '0' * 15
151
+ end
152
+ end
153
+ pid2 = Process.fork do
154
+ 10.times do
155
+ log.info '0' * 15
156
+ end
157
+ end
158
+ Process.waitpid pid1
159
+ Process.waitpid pid2
160
+ w.close
161
+ stderr = r.read
162
+ r.close
163
+ $stderr = STDERR
164
+ stderr.should_not =~ /(log shifting failed|log writing failed|log rotation inter-process lock failed)/
165
+ end
141
166
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverengine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.7
5
- prerelease:
4
+ version: 1.5.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sadayuki Furuhashi
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-01 00:00:00.000000000 Z
11
+ date: 2014-06-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: sigdump
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -103,30 +96,26 @@ files:
103
96
  homepage: https://github.com/frsyuki/serverengine
104
97
  licenses:
105
98
  - Apache 2.0
99
+ metadata: {}
106
100
  post_install_message:
107
101
  rdoc_options: []
108
102
  require_paths:
109
103
  - lib
110
104
  required_ruby_version: !ruby/object:Gem::Requirement
111
- none: false
112
105
  requirements:
113
106
  - - ! '>='
114
107
  - !ruby/object:Gem::Version
115
108
  version: 1.9.3
116
109
  required_rubygems_version: !ruby/object:Gem::Requirement
117
- none: false
118
110
  requirements:
119
111
  - - ! '>='
120
112
  - !ruby/object:Gem::Version
121
113
  version: '0'
122
- segments:
123
- - 0
124
- hash: 1992105160493860645
125
114
  requirements: []
126
115
  rubyforge_project:
127
- rubygems_version: 1.8.23
116
+ rubygems_version: 2.2.2
128
117
  signing_key:
129
- specification_version: 3
118
+ specification_version: 4
130
119
  summary: ServerEngine - multiprocess server framework
131
120
  test_files:
132
121
  - spec/blocking_flag_spec.rb