serverengine 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Changelog +5 -0
- data/Gemfile +0 -1
- data/README.md +44 -9
- data/lib/serverengine/config_loader.rb +2 -0
- data/lib/serverengine/daemon.rb +3 -5
- data/lib/serverengine/multi_process_server.rb +3 -3
- data/lib/serverengine/multi_thread_server.rb +1 -2
- data/lib/serverengine/process_manager.rb +5 -5
- data/lib/serverengine/server.rb +1 -6
- data/lib/serverengine/supervisor.rb +1 -4
- data/lib/serverengine/version.rb +1 -1
- data/lib/serverengine/worker.rb +1 -3
- data/lib/serverengine.rb +2 -2
- data/serverengine.gemspec +3 -3
- data/spec/server_worker_context.rb +4 -4
- data/spec/supervisor_spec.rb +5 -5
- metadata +4 -3
data/.gitignore
ADDED
data/Changelog
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -155,17 +155,17 @@ You can restart a server process without waiting for completion of shutdown proc
|
|
155
155
|
This feature is useful to minimize downtime where workers take long time to complete tasks.
|
156
156
|
|
157
157
|
```
|
158
|
-
# 1.
|
158
|
+
# 1. starts server
|
159
159
|
+------------+ +----------+ +-----------+
|
160
160
|
| Supervisor |----| Server |----| Worker(s) |
|
161
161
|
+------------+ +----------+ +-----------+
|
162
162
|
|
163
|
-
# 2.
|
163
|
+
# 2. receives SIGINT and waits for shutdown of the server for server_detach_wait
|
164
164
|
+------------+ +----------+ +-----------+
|
165
165
|
| Supervisor | | Server |----| Worker(s) |
|
166
166
|
+------------+ +----------+ +-----------+
|
167
167
|
|
168
|
-
# 3.
|
168
|
+
# 3. starts new server if the server doesn't exit in server_detach_wait time
|
169
169
|
+------------+ +----------+ +-----------+
|
170
170
|
| Supervisor |\ | Server |----| Worker(s) |
|
171
171
|
+------------+ | +----------+ +-----------+
|
@@ -174,7 +174,7 @@ This feature is useful to minimize downtime where workers take long time to comp
|
|
174
174
|
\--| Server |----| Worker(s) |
|
175
175
|
+----------+ +-----------+
|
176
176
|
|
177
|
-
# 4. old server exits
|
177
|
+
# 4. old server exits eventually
|
178
178
|
+------------+
|
179
179
|
| Supervisor |\
|
180
180
|
+------------+ |
|
@@ -230,7 +230,7 @@ Send `USR2` signal to reload configuration file.
|
|
230
230
|
|
231
231
|
### BlockingFlag
|
232
232
|
|
233
|
-
`ServerEngine::BlockingFlag` is recommended to stop workers because `stop`
|
233
|
+
`ServerEngine::BlockingFlag` is recommended to stop workers because `stop` method is called by a different thread from the `run` thread.
|
234
234
|
|
235
235
|
```ruby
|
236
236
|
module MyWorker
|
@@ -259,12 +259,46 @@ se.run
|
|
259
259
|
```
|
260
260
|
|
261
261
|
|
262
|
+
## Module methods
|
263
|
+
|
264
|
+
### Worker module
|
265
|
+
|
266
|
+
- interface
|
267
|
+
- `initialize` is called in the parent process (or thread) in contrast to the other methods
|
268
|
+
- `before_fork` is called before fork for each worker process (available only if `worker_type` is "process")
|
269
|
+
- `run` is the required method
|
270
|
+
- `stop` is called when TERM signal is received
|
271
|
+
- `reload` is called when USR2 signal is received
|
272
|
+
- `after_start` is called after starting the worker process in the parent process (or thread) (available only if `worker_type` is "process" or "thread")
|
273
|
+
- api
|
274
|
+
- `server` server instance
|
275
|
+
- `config` configuration
|
276
|
+
- `logger` logger
|
277
|
+
- `worker_id` serial id of workers beginning from 0
|
278
|
+
|
279
|
+
|
280
|
+
### Server module
|
281
|
+
|
282
|
+
- interface
|
283
|
+
- `initialize` is called in the parent process in contrast to the other methods
|
284
|
+
- `before_run` is called before starting workers
|
285
|
+
- `after_run` is called before shutting down
|
286
|
+
- `after_start` is called after starting the server process in the parent process (available only if `supervisor` parameter is true)
|
287
|
+
- hook points (call `super` in these methods)
|
288
|
+
- `reload_config`
|
289
|
+
- `stop(stop_graceful)`
|
290
|
+
- `restart(stop_graceful)`
|
291
|
+
- api
|
292
|
+
- `config` configuration
|
293
|
+
- `logger` logger
|
294
|
+
|
295
|
+
|
262
296
|
## Worker types
|
263
297
|
|
264
298
|
ServerEngine supports 3 worker types:
|
265
299
|
|
266
|
-
- **embedded**: uses a thread to run worker module (default). This type doesn't support immediate shutdown
|
267
|
-
- **thread**: uses threads to run worker modules. This type doesn't support immediate shutdown
|
300
|
+
- **embedded**: uses a thread to run worker module (default). This type doesn't support immediate shutdown or immediate restart.
|
301
|
+
- **thread**: uses threads to run worker modules. This type doesn't support immediate shutdown or immediate restart.
|
268
302
|
- **process**: uses processes to run worker modules. This type doesn't work on Win32 platform.
|
269
303
|
|
270
304
|
|
@@ -278,7 +312,7 @@ ServerEngine supports 3 worker types:
|
|
278
312
|
- **INT:** detach process for live restarting (available only when `supervisor` and `enable_detach` parameters are true. otherwise graceful shutdown)
|
279
313
|
- **CONT:** dump stacktrace and memory information to /tmp/sigdump-<pid>.log file
|
280
314
|
|
281
|
-
Immediate shutdown and restart send SIGQUIT signal to worker processes which
|
315
|
+
Immediate shutdown and restart send SIGQUIT signal to worker processes which kills the processes.
|
282
316
|
Graceful shutdown and restart call `Worker#stop` method and wait for completion of `Worker#run` method.
|
283
317
|
|
284
318
|
|
@@ -298,13 +332,14 @@ Graceful shutdown and restart call `Worker#stop` method and wait for completion
|
|
298
332
|
- **enable_detach** enables INT signal (default: true) (not dynamic reloadable)
|
299
333
|
- **exit_on_detach** exits supervisor after detaching server process instead of restarting it (default: false) (not dynamic reloadable)
|
300
334
|
- **disable_reload** disables USR2 signal (default: false) (not dynamic reloadable)
|
301
|
-
- **
|
335
|
+
- **server_restart_wait** sets wait time before restarting server after last restarting (default: 1.0)
|
302
336
|
- **server_detach_wait** sets wait time before starting live restart (default: 10.0)
|
303
337
|
- Multithread server and multiprocess server: available only when `worker_type` is thread or process
|
304
338
|
- **workers** sets number of workers (default: 1)
|
305
339
|
- **start_worker_delay** sets wait time before starting a new worker (default: 0)
|
306
340
|
- **start_worker_delay_rand** randomizes start_worker_delay at this ratio (default: 0.2)
|
307
341
|
- Multiprocess server: available only when `worker_type` is "process"
|
342
|
+
- **worker_process_name** changes process name ($0) of workers
|
308
343
|
- **worker_heartbeat_interval**
|
309
344
|
- **worker_heartbeat_timeout**
|
310
345
|
- **worker_graceful_kill_interval**
|
data/lib/serverengine/daemon.rb
CHANGED
@@ -28,8 +28,6 @@ module ServerEngine
|
|
28
28
|
|
29
29
|
super(load_config_proc, &block)
|
30
30
|
|
31
|
-
reload_config
|
32
|
-
|
33
31
|
@daemonize = @config.fetch(:daemonize, false)
|
34
32
|
|
35
33
|
if @config.fetch(:supervisor, false)
|
@@ -121,9 +119,9 @@ module ServerEngine
|
|
121
119
|
|
122
120
|
s = create_server(create_logger)
|
123
121
|
|
124
|
-
STDIN.reopen(
|
125
|
-
STDOUT.reopen(
|
126
|
-
STDERR.reopen(
|
122
|
+
STDIN.reopen(File::NULL)
|
123
|
+
STDOUT.reopen(File::NULL, "wb")
|
124
|
+
STDERR.reopen(File::NULL, "wb")
|
127
125
|
|
128
126
|
s.install_signal_handlers
|
129
127
|
|
@@ -23,9 +23,9 @@ module ServerEngine
|
|
23
23
|
auto_tick: false,
|
24
24
|
graceful_kill_signal: Daemon::Signals::GRACEFUL_STOP,
|
25
25
|
auto_heartbeat: true,
|
26
|
-
|
26
|
+
on_heartbeat_error: Proc.new do
|
27
27
|
@logger.fatal "parent process unexpectedly terminated"
|
28
|
-
exit
|
28
|
+
exit 1
|
29
29
|
end
|
30
30
|
)
|
31
31
|
|
@@ -78,7 +78,7 @@ module ServerEngine
|
|
78
78
|
end
|
79
79
|
|
80
80
|
ensure
|
81
|
-
w.
|
81
|
+
w.after_start
|
82
82
|
end
|
83
83
|
|
84
84
|
return WorkerMonitor.new(w, wid, pmon)
|
@@ -35,15 +35,15 @@ module ServerEngine
|
|
35
35
|
|
36
36
|
@auto_heartbeat = config.fetch(:auto_heartbeat, true)
|
37
37
|
|
38
|
-
case op = config
|
38
|
+
case op = config[:on_heartbeat_error]
|
39
|
+
when nil
|
40
|
+
@heartbeat_error_proc = lambda {|t| }
|
39
41
|
when Proc
|
40
42
|
@heartbeat_error_proc = op
|
41
|
-
when
|
43
|
+
when :abort
|
42
44
|
@heartbeat_error_proc = lambda {|t| exit 1 }
|
43
|
-
when false
|
44
|
-
@heartbeat_error_proc = lambda {|t| }
|
45
45
|
else
|
46
|
-
raise ArgumentError, "unexpected :
|
46
|
+
raise ArgumentError, "unexpected :on_heartbeat_error option (expected Proc, true or false but got #{op.class})"
|
47
47
|
end
|
48
48
|
|
49
49
|
configure(config)
|
data/lib/serverengine/server.rb
CHANGED
@@ -26,8 +26,6 @@ module ServerEngine
|
|
26
26
|
@stop = false
|
27
27
|
|
28
28
|
super(load_config_proc, &block)
|
29
|
-
|
30
|
-
reload_config
|
31
29
|
end
|
32
30
|
|
33
31
|
def before_run
|
@@ -41,7 +39,7 @@ module ServerEngine
|
|
41
39
|
nil
|
42
40
|
end
|
43
41
|
|
44
|
-
def
|
42
|
+
def after_start
|
45
43
|
end
|
46
44
|
|
47
45
|
def restart(stop_graceful)
|
@@ -79,9 +77,6 @@ module ServerEngine
|
|
79
77
|
ensure
|
80
78
|
after_run
|
81
79
|
end
|
82
|
-
|
83
|
-
ensure
|
84
|
-
close
|
85
80
|
end
|
86
81
|
|
87
82
|
module WorkerInitializer
|
@@ -32,13 +32,10 @@ module ServerEngine
|
|
32
32
|
graceful_kill_signal: Daemon::Signals::GRACEFUL_STOP,
|
33
33
|
immediate_kill_signal: Daemon::Signals::IMMEDIATE_STOP,
|
34
34
|
auto_heartbeat: true,
|
35
|
-
abort_on_heartbeat_error: false,
|
36
35
|
)
|
37
36
|
|
38
37
|
super(load_config_proc, &block)
|
39
38
|
|
40
|
-
reload_config
|
41
|
-
|
42
39
|
@create_server_proc = Supervisor.create_server_proc(server_module, worker_module, @config)
|
43
40
|
@server_process_name = @config[:server_process_name]
|
44
41
|
|
@@ -204,7 +201,7 @@ module ServerEngine
|
|
204
201
|
|
205
202
|
return m
|
206
203
|
ensure
|
207
|
-
s.
|
204
|
+
s.after_start
|
208
205
|
end
|
209
206
|
end
|
210
207
|
|
data/lib/serverengine/version.rb
CHANGED
data/lib/serverengine/worker.rb
CHANGED
data/lib/serverengine.rb
CHANGED
@@ -46,7 +46,7 @@ module ServerEngine
|
|
46
46
|
require File.join(here, v)
|
47
47
|
}
|
48
48
|
|
49
|
-
def self.create(server_module, worker_module, &
|
50
|
-
Daemon.new(server_module, worker_module, &
|
49
|
+
def self.create(server_module, worker_module, load_config_proc={}, &block)
|
50
|
+
Daemon.new(server_module, worker_module, load_config_proc={}, &block)
|
51
51
|
end
|
52
52
|
end
|
data/serverengine.gemspec
CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |gem|
|
|
18
18
|
|
19
19
|
gem.required_ruby_version = ">= 1.9.3"
|
20
20
|
|
21
|
-
gem.add_dependency
|
21
|
+
gem.add_dependency "sigdump", ["~> 0.2.2"]
|
22
22
|
|
23
|
-
gem.add_development_dependency
|
24
|
-
gem.add_development_dependency
|
23
|
+
gem.add_development_dependency "rake", [">= 0.9.2"]
|
24
|
+
gem.add_development_dependency "rspec", ["~> 2.13.0"]
|
25
25
|
end
|
@@ -50,8 +50,8 @@ shared_context 'test server and worker' do
|
|
50
50
|
incr_test_state :server_after_run
|
51
51
|
end
|
52
52
|
|
53
|
-
def
|
54
|
-
incr_test_state :
|
53
|
+
def after_start
|
54
|
+
incr_test_state :server_after_start
|
55
55
|
end
|
56
56
|
|
57
57
|
def stop(stop_graceful)
|
@@ -110,8 +110,8 @@ shared_context 'test server and worker' do
|
|
110
110
|
incr_test_state :worker_reload
|
111
111
|
end
|
112
112
|
|
113
|
-
def
|
114
|
-
incr_test_state :
|
113
|
+
def after_start
|
114
|
+
incr_test_state :worker_after_start
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
data/spec/supervisor_spec.rb
CHANGED
@@ -16,7 +16,7 @@ describe ServerEngine::Supervisor do
|
|
16
16
|
wait_for_fork
|
17
17
|
|
18
18
|
test_state(:server_before_run).should == 1
|
19
|
-
test_state(:
|
19
|
+
test_state(:server_after_start).should == 1 # parent
|
20
20
|
ensure
|
21
21
|
sv.stop(true)
|
22
22
|
t.join
|
@@ -27,7 +27,7 @@ describe ServerEngine::Supervisor do
|
|
27
27
|
test_state(:server_restart).should == 0
|
28
28
|
|
29
29
|
test_state(:server_after_run).should == 1
|
30
|
-
test_state(:
|
30
|
+
test_state(:server_after_start).should == 1
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'immediate stop' do
|
@@ -43,7 +43,7 @@ describe ServerEngine::Supervisor do
|
|
43
43
|
test_state(:server_stop).should == 1
|
44
44
|
test_state(:server_stop_immediate).should == 1
|
45
45
|
test_state(:server_after_run).should == 1
|
46
|
-
test_state(:
|
46
|
+
test_state(:server_after_start).should == 1
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'graceful restart' do
|
@@ -64,7 +64,7 @@ describe ServerEngine::Supervisor do
|
|
64
64
|
|
65
65
|
test_state(:server_before_run).should == 1
|
66
66
|
test_state(:server_after_run).should == 1
|
67
|
-
test_state(:
|
67
|
+
test_state(:server_after_start).should == 1
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'immediate restart' do
|
@@ -85,7 +85,7 @@ describe ServerEngine::Supervisor do
|
|
85
85
|
|
86
86
|
test_state(:server_before_run).should == 1
|
87
87
|
test_state(:server_after_run).should == 1
|
88
|
-
test_state(:
|
88
|
+
test_state(:server_after_start).should == 1
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'reload' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serverengine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sigdump
|
@@ -66,6 +66,7 @@ executables: []
|
|
66
66
|
extensions: []
|
67
67
|
extra_rdoc_files: []
|
68
68
|
files:
|
69
|
+
- .gitignore
|
69
70
|
- COPYING
|
70
71
|
- Changelog
|
71
72
|
- Gemfile
|
@@ -116,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
117
|
version: '0'
|
117
118
|
segments:
|
118
119
|
- 0
|
119
|
-
hash:
|
120
|
+
hash: 2571011204453974309
|
120
121
|
requirements: []
|
121
122
|
rubyforge_project:
|
122
123
|
rubygems_version: 1.8.23
|