Class: Daemonite
Constant Summary
Constants included
from Daemonism
Daemonism::DAEMONISM_DEFAULT_OPTS
Instance Method Summary
collapse
Methods included from Daemonism
#daemonism, #exit, #on, #on_exit, #on_startup, #startup, #use
Constructor Details
#initialize(opts = {}, &blk) ⇒ Daemonite
200
201
202
203
|
# File 'lib/daemonite.rb', line 200
def initialize(opts={},&blk)
@opts = DAEMONISM_DEFAULT_OPTS.merge(opts)
daemonism @opts, &blk
end
|
Instance Method Details
#go! ⇒ Object
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/daemonite.rb', line 209
def go!
begin
@at_startup.call(@opts) if @at_startup
@opts[:block].call(@opts)
rescue SystemExit, Interrupt
puts "Server stopped due to interrupt (PID:#{Process.pid})"
rescue => e
puts "Server stopped due to error (PID:#{Process.pid})"
end
end
|
#loop! ⇒ Object
220
221
222
223
224
225
226
227
228
229
230
231
|
# File 'lib/daemonite.rb', line 220
def loop!
begin
@at_startup.call(@opts) if @at_startup
loop do
@opts[:block].call(@opts)
end unless @opts[:block].nil?
rescue SystemExit, Interrupt
puts "Server stopped due to interrupt (PID:#{Process.pid})"
rescue => e
puts "Server stopped due to error (PID:#{Process.pid})"
end
end
|
#run(&block) ⇒ Object
205
206
207
|
# File 'lib/daemonite.rb', line 205
def run(&block)
@opts[:block] = block
end
|