module Daemonic

Stolen from RubyTapas by Avdi Grimm, episode 145.

Constants

VERSION

Public Class Methods

restart(options, &worker_proc) click to toggle source
# File lib/daemonic.rb, line 43
def self.restart(options, &worker_proc)
  daemon = Daemon.new(options.merge(daemonize: true))
  daemon.restart do
    worker = worker_proc.call
    Producer.new(worker, options).run
  end
end
run(default_options = {}, &worker_proc) click to toggle source
# File lib/daemonic.rb, line 17
def self.run(default_options = {}, &worker_proc)
  command, options = CLI.new(ARGV, default_options).run
  case command
  when :start   then start(options, &worker_proc)
  when :stop    then stop(options)
  when :status  then status(options)
  when :restart then restart(options, &worker_proc)
  end
end
start(options, &worker_proc) click to toggle source
# File lib/daemonic.rb, line 27
def self.start(options, &worker_proc)
  daemon = Daemon.new(options)
  daemon.start do
    worker = worker_proc.call
    Producer.new(worker, options).run
  end
end
status(options) click to toggle source
# File lib/daemonic.rb, line 39
def self.status(options)
  Daemon.new(options).status
end
stop(options) click to toggle source
# File lib/daemonic.rb, line 35
def self.stop(options)
  Daemon.new(options).stop
end