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_startup, #startup, #use
Constructor Details
#initialize(opts = {}, &blk) ⇒ Daemonite
Returns a new instance of Daemonite.
197 198 199 200 |
# File 'lib/daemonite.rb', line 197 def initialize(opts={},&blk) @opts = DAEMONISM_DEFAULT_OPTS.merge(opts) daemonism @opts, &blk end |
Instance Method Details
#go! ⇒ Object
206 207 208 209 210 211 212 213 214 215 |
# File 'lib/daemonite.rb', line 206 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
217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/daemonite.rb', line 217 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
202 203 204 |
# File 'lib/daemonite.rb', line 202 def run(&block) @opts[:block] = block end |