Navigation Menu

Skip to content

Commit

Permalink
Load port number for serf from a status file
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jun 26, 2014
1 parent b4cf50e commit 7df161f
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion lib/droonga/serf.rb
Expand Up @@ -27,6 +27,22 @@ class << self
def path
Droonga::Path.base + "serf"
end

def port_file
Droonga::Path.state + "serf_port"
end

def default_port
7373
end

def dump_source_port
7374
end

def dump_destination_port
7375
end
end

include Loggable
Expand All @@ -41,6 +57,8 @@ def start
logger.trace("start: start")
ensure_serf
ENV["SERF"] = @serf
@port = port
ENV["SERF_PORT"] = @port
ENV["SERF_RPC_ADDRESS"] = rpc_address
retry_joins = []
detect_other_hosts.each do |other_host|
Expand Down Expand Up @@ -113,7 +131,19 @@ def log_level
end

def rpc_address
"#{extract_host(@name)}:7373"
"#{extract_host(@name)}:#{@port}"
end

def port
port_file = self.class.port_file
if port_file.exist?
contents = port_file.read
unless contents.empty?
return contents.to_i
end
end

self.class.default_port
end

def detect_other_hosts
Expand Down

0 comments on commit 7df161f

Please sign in to comment.