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.
188 189 190 191 |
# File 'lib/daemonite.rb', line 188 def initialize(opts={},&blk) @opts = DAEMONISM_DEFAULT_OPTS.merge(opts) daemonism @opts, &blk end |
Instance Method Details
#go! ⇒ Object
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/daemonite.rb', line 197 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
208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/daemonite.rb', line 208 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
193 194 195 |
# File 'lib/daemonite.rb', line 193 def run(&block) @opts[:block] = block end |