Sha256: c4b4f8e1b3472a86b314d635acc828ec76ba6d22192bb7e025005e28a4e05842

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

#!/usr/bin/env ruby

require 'drb'
require 'optparse'

require 'mega/synchash'
require 'nitro/session'

# A distributes session store implemented as
# a simple DRb server.
#--
# TODO: add daemonize support.
#++

address = '127.0.0.1'
port = 9069
debug = false
daemon = false

parser = OptionParser.new do |opts|

  opts.banner = 'Usage: drbserver.rb [options]'
  opts.separator ''
  opts.separator 'Specific options:'

  opts.on('-a A', '--address A', 'Listening address.') do |a|
    address = a
  end

  opts.on('-p P', '--port P', Integer, 'Listening port.') do |p|
    port = p
  end

  opts.on('-D', '--debug', 'Run in debug mode.') do |p|
    debug = true
  end

  opts.on('-d', '--daemon', 'Run as daemon.') do |p|
    daemon = true
  end

  opts.on_tail('-h', '--help', 'Show this message.') do
    puts opts
    exit
  end
  
end

begin
  parser.parse!(ARGV)
rescue OptionParser::InvalidOption
  puts 'Invalid option, pass the --help parameter to get help!' 
  exit
end

sessions = Nitro::MemorySessionStore.new 

if debug

  class << sessions
    def []=(k, v)
      puts "WRITE: #{k} = #{v}"
      super
    end
    
    def [](k)
      puts "READ: #{k}"
      super
    end
  end
  
end

puts "Drb session server listening at druby://#{address}:#{port}."

if daemon
  require 'daemons/daemonize'
  Daemonize.daemonize()
end

DRb.start_service("druby://#{address}:#{port}", sessions)
DRb.thread.join

# * George Moschovitis  <gm@navel.gr>

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nitro-0.26.0 lib/nitro/session/drbserver.rb
nitro-0.27.0 lib/nitro/session/drbserver.rb