Class: Daemonite
Constant Summary
Constants included from Daemonism
Daemonism::DAEMONISM_DEFAULT_OPTS
Instance Method Summary collapse
- #go! ⇒ Object
-
#initialize(opts = {}, &blk) ⇒ Daemonite
constructor
A new instance of Daemonite.
- #loop! ⇒ Object
- #run(&block) ⇒ Object
Methods included from Daemonism
#daemonism, #exit, #on, #on_exit, #on_setup, #on_startup, #setup, #startup, #use
Constructor Details
#initialize(opts = {}, &blk) ⇒ Daemonite
Returns a new instance of Daemonite.
214 215 216 217 |
# File 'lib/daemonite.rb', line 214 def initialize(opts={},&blk) @opts = DAEMONISM_DEFAULT_OPTS.merge(opts) daemonism @opts, &blk end |
Instance Method Details
#go! ⇒ Object
223 224 225 226 227 228 229 230 231 232 |
# File 'lib/daemonite.rb', line 223 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
234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/daemonite.rb', line 234 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
219 220 221 |
# File 'lib/daemonite.rb', line 219 def run(&block) @opts[:block] = block end |