Class: Gflocator::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/gflocator/main.rb

Constant Summary collapse

OPTS =
{:daemonize=>true}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.runObject



10
11
12
# File 'lib/gflocator/main.rb', line 10

def self.run
  new.run OPTS
end

Instance Method Details

#optparse(options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gflocator/main.rb', line 28

def optparse options={}
  optparser = OptionParser.new
  optparser.on('--debug') {$debug = true; STDOUT.sync = true}
  optparser.on('-h', '--bind-host=HOST', 'bind to HOST address') {|a|
    options[:bind_host] = a}
  optparser.on('-p', '--bind-port=PORT', Integer, 'bind to port PORT') {|a|
    options[:bind_port] = a}
  class <<optparser
    attr_accessor :options
  end
  optparser.options = options
  optparser
end

#run(options = {}) ⇒ Object

Raises:

  • (RuntimeError)


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gflocator/main.rb', line 14

def run options={}
  optparser = optparse options
  optparser.parse!
  host = options[:bind_host] || '0.0.0.0'
  port = options[:bind_port] || 7076

  raise RuntimeError, 'must run as root' unless Process.euid.zero?
  handler = Handler.new
  server = MessagePack::RPC::Server.new
  server.listen host, port, handler
  Process.daemon true if options[:daemonize] and !$debug
  server.run
end