summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2014-10-27 13:38:57 +0000
committerSimon MacMullen <simon@rabbitmq.com>2014-10-27 13:38:57 +0000
commita6499ee71ec42b73961a52a32b03358e97ce3d37 (patch)
tree6961784a9f74abac2f3610942350973e101fcfef /src
parentddeaab14b63dc983192f643a13e3784c578afb50 (diff)
downloadrabbitmq-server-git-a6499ee71ec42b73961a52a32b03358e97ce3d37.tar.gz
Check in with epmd periodically, if it hasn't heard of us then re-register (and restart it if needed).
Diffstat (limited to 'src')
-rw-r--r--src/rabbit.erl7
-rw-r--r--src/rabbit_epmd_monitor.erl89
2 files changed, 96 insertions, 0 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index 664da20688..fdf1e12e2d 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -118,6 +118,13 @@
{requires, [rabbit_alarm, guid_generator]},
{enables, core_initialized}]}).
+-rabbit_boot_step({rabbit_epmd_monitor,
+ [{description, "epmd monitor"},
+ {mfa, {rabbit_sup, start_restartable_child,
+ [rabbit_epmd_monitor]}},
+ {requires, kernel_ready},
+ {enables, core_initialized}]}).
+
-rabbit_boot_step({core_initialized,
[{description, "core initialized"},
{requires, kernel_ready}]}).
diff --git a/src/rabbit_epmd_monitor.erl b/src/rabbit_epmd_monitor.erl
new file mode 100644
index 0000000000..d5e9cfc94d
--- /dev/null
+++ b/src/rabbit_epmd_monitor.erl
@@ -0,0 +1,89 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License
+%% at http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and
+%% limitations under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developer of the Original Code is GoPivotal, Inc.
+%% Copyright (c) 2007-2014 GoPivotal, Inc. All rights reserved.
+%%
+
+-module(rabbit_epmd_monitor).
+
+-behaviour(gen_server).
+
+-export([start_link/0]).
+
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
+ code_change/3]).
+
+-record(state, {timer, mod, me, host, port}).
+
+-define(SERVER, ?MODULE).
+-define(CHECK_FREQUENCY, 60000).
+
+%%----------------------------------------------------------------------------
+
+-ifdef(use_specs).
+
+-spec(start_link/0 :: () -> rabbit_types:ok_pid_or_error()).
+
+-endif.
+
+%%----------------------------------------------------------------------------
+
+start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
+
+%%----------------------------------------------------------------------------
+
+init([]) ->
+ {Me, Host} = rabbit_nodes:parts(node()),
+ Mod = net_kernel:epmd_module(),
+ {port, Port, _Version} = Mod:port_please(Me, Host),
+ {ok, ensure_timer(#state{mod = Mod,
+ me = Me,
+ host = Host,
+ port = Port})}.
+
+handle_call(_Request, _From, State) ->
+ {noreply, State}.
+
+handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+handle_info(check, State) ->
+ check_epmd(State),
+ {noreply, ensure_timer(State#state{timer = undefined})};
+
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+terminate(_Reason, _State) ->
+ ok.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+%%----------------------------------------------------------------------------
+
+ensure_timer(State) ->
+ rabbit_misc:ensure_timer(State, #state.timer, ?CHECK_FREQUENCY, check).
+
+check_epmd(#state{mod = Mod,
+ me = Me,
+ host = Host,
+ port = Port}) ->
+ case Mod:port_please(Me, Host) of
+ noport -> rabbit_log:warning(
+ "epmd does not know us, re-registering ~s at port ~b~n",
+ [Me, Port]),
+ rabbit_nodes:ensure_epmd(),
+ erl_epmd:register_node(Me, Port);
+ _ -> ok
+ end.