Class: Textbringer::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/textbringer/commands/server.rb

Defined Under Namespace

Classes: ExistError, FrontObject

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Server

Returns a new instance of Server.



34
35
36
# File 'lib/textbringer/commands/server.rb', line 34

def initialize(uri)
  @uri = uri
end

Instance Method Details

#startObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/textbringer/commands/server.rb', line 38

def start
  front = FrontObject.new
  default_options = unix_domain? ? { UNIXFileMode: 0600 } : {}
  options = default_options.merge(CONFIG[:server_options] || {})
  begin
    DRb.start_service(@uri, front, options)
  rescue Errno::EADDRINUSE
    if unix_domain? && !unix_domain_server_alive?
      # Remove the socket file in case another server died unexpectedly before.
      File.unlink(unix_domain_socket_path)
      DRb.start_service(@uri, front, options)
    else
      raise ExistError, "There is an existing Textbringer server"
    end
  end
end