Class: Gflocator::Main
- Inherits:
-
Object
- Object
- Gflocator::Main
- Defined in:
- lib/gflocator/main.rb
Constant Summary collapse
- OPTS =
{:daemonize=>true}
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.run ⇒ Object
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 ={} optparser = OptionParser.new optparser.on('--debug') {$debug = true; STDOUT.sync = true} optparser.on('-h', '--bind-host=HOST', 'bind to HOST address') {|a| [:bind_host] = a} optparser.on('-p', '--bind-port=PORT', Integer, 'bind to port PORT') {|a| [:bind_port] = a} class <<optparser attr_accessor :options end optparser. = optparser end |
#run(options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gflocator/main.rb', line 14 def run ={} optparser = optparse optparser.parse! host = [:bind_host] || '0.0.0.0' port = [: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 [:daemonize] and !$debug server.run end |