Class: Tootsie::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/tootsie/runner.rb

Overview

Runs the daemon from the command line.

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



6
7
8
9
10
# File 'lib/tootsie/runner.rb', line 6

def initialize
  @run_as_daemon = false
  @config_path = '/etc/tootsie/tootsie.conf'
  @app = Application.new
end

Instance Method Details

#run!(arguments = []) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tootsie/runner.rb', line 12

def run!(arguments = [])
  OptionParser.new do |opts|
    opts.banner = "Usage: #{File.basename($0)} [OPTIONS]"
    opts.separator ""
    opts.on("-d", "--daemon", 'Run as daemon') do
      @run_as_daemon = true
    end
    opts.on("-p PATH", "--pid", "Store pid in PATH (defaults to #{@pid_path})") do |value|
      @pid_path = File.expand_path(value)
    end
    opts.on("-c FILE", "--config FILE", "Read configuration from FILE (defaults to #{@config_path})") do |value|
      @config_path = File.expand_path(value)
    end
    opts.on("-h", "--help", "Show this help.") do
      puts opts
      exit
    end
    opts.parse!(arguments)
  end

  @app.configure!(@config_path)

  if @run_as_daemon
    daemonize!
  else
    execute!
  end
end