Module: Forker::CLI

Defined in:
lib/forker.rb

Class Method Summary collapse

Class Method Details

.run(argv) ⇒ Object

You can use this if your daemon is simple enough or write your own and use Forker#fork! directly



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/forker.rb', line 22

def self.run(argv)
  require 'optparse'
  options = {}
  opts = OptionParser.new do |opts|
    opts.banner = "Usage: #{File.basename($0)} [start|stop] -p /path/to/pidfile.pid"

    opts.on("-l", "--logfile LOGFILE", "redirect output to this location") do |logfile|
      options[:log] = logfile
    end

    opts.on("-p", "--pidfile PIDFILE", "save pidfile to this location") do |pidfile|
      options[:pid] = pidfile
    end
  end
  opts.parse!(argv)

  if options[:pid].nil?
    puts opts
    exit
  end

  case argv.first
  when "start"
    Forker.fork!(options)
  when "stop"
    Forker.kill(options)
    exit
  else
    puts opts
    exit
  end
end