summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rel/overlay/etc/vm.args2
-rw-r--r--src/couch_dist/src/couch_dist.erl43
2 files changed, 44 insertions, 1 deletions
diff --git a/rel/overlay/etc/vm.args b/rel/overlay/etc/vm.args
index 805e9ec22..8da600bc3 100644
--- a/rel/overlay/etc/vm.args
+++ b/rel/overlay/etc/vm.args
@@ -91,5 +91,5 @@
## Don't forget to override the paths to point to your certificate(s) and key(s)!
##
#-proto_dist couch
-#-couch_dist no_tls \"clouseau@127.0.0.1\"
+#-couch_dist no_tls '"clouseau@127.0.0.1"'
#-ssl_dist_optfile <path/to/couch_ssl_dist.conf>
diff --git a/src/couch_dist/src/couch_dist.erl b/src/couch_dist/src/couch_dist.erl
index 9a6b26d07..a0922ebc5 100644
--- a/src/couch_dist/src/couch_dist.erl
+++ b/src/couch_dist/src/couch_dist.erl
@@ -14,6 +14,7 @@
-export([
childspecs/0,
+ listen/1,
listen/2,
accept/1,
accept_connection/5,
@@ -33,6 +34,16 @@ childspecs() ->
]}
]}.
+listen(Name) ->
+ NodeName =
+ case is_atom(Name) of
+ true -> atom_to_list(Name);
+ false -> Name
+ end,
+ Host = get_node_host(),
+ Mod = inet_dist(NodeName ++ "@" ++ Host),
+ Mod:listen(NodeName).
+
listen(Name, Host) ->
NodeName =
case is_atom(Name) of
@@ -66,6 +77,38 @@ is_node_name(Node) ->
get_init_args() ->
init:get_argument(couch_dist).
+get_node_host() ->
+ % Cannot use `node()` since distribution hasn't started yet. Use
+ % similar logic as erl_distribition and net_kernel to parse it
+ % from the arguments list
+ case {init:get_argument(sname), init:get_argument(name)} of
+ {{ok, [[SName]]}, _} ->
+ case split_host(SName) of
+ [$@ | Host] when length(Host) > 0 ->
+ Host;
+ _ ->
+ inet_db:gethostname()
+ end;
+ {error, {ok, [[Name]]}} ->
+ case split_host(Name) of
+ [$@ | Host] when length(Host) > 0 ->
+ Host;
+ _ ->
+ OwnHost = inet_db:gethostname(),
+ case inet_db:res_option(domain) of
+ Domain when is_list(Domain), length(Domain) > 0 ->
+ OwnHost ++ "." ++ Domain;
+ _ ->
+ OwnHost
+ end
+ end
+ end.
+
+split_host(Name) ->
+ % Copied from net_kernel. Modifed to return Host only
+ {_, Host} = lists:splitwith(fun(C) -> C =/= $@ end, Name),
+ Host.
+
inet_dist(Node) ->
case no_tls(Node) of
true -> inet_tcp_dist;