Class: Daemonite

Inherits:
Object
  • Object
show all
Includes:
Daemonism
Defined in:
lib/daemonite.rb

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

Returns a new instance of Daemonite.



196
197
198
199
# File 'lib/daemonite.rb', line 196

def initialize(opts={},&blk)
  @opts = DAEMONISM_DEFAULT_OPTS.merge(opts)
  daemonism @opts, &blk
end

Instance Method Details

#go!Object



205
206
207
208
209
210
211
212
213
214
# File 'lib/daemonite.rb', line 205

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



216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/daemonite.rb', line 216

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



201
202
203
# File 'lib/daemonite.rb', line 201

def run(&block)
  @opts[:block] = block
end