servolux 0.6.0 → 0.6.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 +5 -0
- data/lib/servolux/server.rb +44 -3
- data/lib/servolux.rb +1 -1
- metadata +2 -2
data/History.txt
CHANGED
data/lib/servolux/server.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
|
2
|
+
require 'thread'
|
3
|
+
|
2
4
|
# == Synopsis
|
3
5
|
# The Server class makes it simple to create a server-type application in
|
4
6
|
# Ruby. A server in this context is any process that should run for a long
|
@@ -147,6 +149,8 @@ class Servolux::Server
|
|
147
149
|
@name = name
|
148
150
|
@activity_thread = nil
|
149
151
|
@activity_thread_running = false
|
152
|
+
@mutex = Mutex.new
|
153
|
+
@shutdown = nil
|
150
154
|
|
151
155
|
self.logger = opts.getopt :logger
|
152
156
|
self.pid_file = opts.getopt :pid_file
|
@@ -172,6 +176,10 @@ class Servolux::Server
|
|
172
176
|
#
|
173
177
|
def startup
|
174
178
|
return self if running?
|
179
|
+
@mutex.synchronize {
|
180
|
+
@shutdown = ConditionVariable.new
|
181
|
+
}
|
182
|
+
|
175
183
|
begin
|
176
184
|
create_pid_file
|
177
185
|
trap_signals
|
@@ -183,9 +191,42 @@ class Servolux::Server
|
|
183
191
|
return self
|
184
192
|
end
|
185
193
|
|
186
|
-
|
187
|
-
|
188
|
-
|
194
|
+
# Stop the server if it is running. This method will return after three
|
195
|
+
# things have occurred:
|
196
|
+
#
|
197
|
+
# 1) The 'before_stopping' method has returned.
|
198
|
+
# 2) The server's activity thread has stopped.
|
199
|
+
# 3) The 'after_stopping' method has returned.
|
200
|
+
#
|
201
|
+
# It is entirely possible that the activity thread will stop before either
|
202
|
+
# the +before_stopping+ or +after_stopping+ methods return. To make sure
|
203
|
+
# the server is completely stopped, use the +wait_for_shutdown+ method to
|
204
|
+
# be notified when the this +shutdown+ method is finished executing.
|
205
|
+
#
|
206
|
+
def shutdown
|
207
|
+
return self unless running?
|
208
|
+
stop
|
209
|
+
|
210
|
+
@mutex.synchronize {
|
211
|
+
@shutdown.signal
|
212
|
+
@shutdown = nil
|
213
|
+
}
|
214
|
+
self
|
215
|
+
end
|
216
|
+
|
217
|
+
# If the server has been started, this method waits till the +shutdown+
|
218
|
+
# method has been called and has completed. The current thread will be
|
219
|
+
# blocked until the server has been safely stopped.
|
220
|
+
#
|
221
|
+
def wait_for_shutdown
|
222
|
+
@mutex.synchronize {
|
223
|
+
@shutdown.wait(@mutex) unless @shutdown.nil?
|
224
|
+
}
|
225
|
+
self
|
226
|
+
end
|
227
|
+
|
228
|
+
alias :int :shutdown # handles the INT signal
|
229
|
+
alias :term :shutdown # handles the TERM signal
|
189
230
|
private :start, :stop
|
190
231
|
|
191
232
|
# Returns the PID file name used by the server. If none was given, then
|
data/lib/servolux.rb
CHANGED
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.6.
|
4
|
+
version: 0.6.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-07-
|
12
|
+
date: 2009-07-13 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|