Browse files

Added RABBIT_HOST on environment to start with a new rabbit host

  • Loading branch information...
1 parent c24beb7 commit 3c2567b060d6cefa1c58d3bd65b0ba44664830b5 @auser committed with tolbrino Sep 9, 2009
View
3 src/alice/alice_app.erl
@@ -10,4 +10,5 @@ start(Type, Args) ->
% ),
alice_sup:start(Type, Args).
-stop(_State) -> ok.
+stop(State) ->
+ alice_sup:stop(State).
View
6 src/alice/alice_log.erl
@@ -11,7 +11,7 @@
-include ("alice.hrl").
%% API
--export([start_link/0, stop/0, append/1, print/0,
+-export([start_link/0, stop/0, stop/1, append/1, print/0,
error/1,error/2,
info/1,info/2
]).
@@ -35,8 +35,8 @@
start_link() ->
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
-stop() ->
- gen_server:call(?MODULE, stop).
+stop(Args) -> stop().
+stop() -> gen_server:call(?MODULE, stop).
error(Msg) -> error(Msg, []).
error(Msg, Args) -> error_logger:error_msg(lists:flatten(io_lib:format(Msg, Args))).
View
11 src/alice/alice_sup.erl
@@ -2,7 +2,7 @@
-include ("alice.hrl").
-behaviour(supervisor).
--export([start/2]).
+-export([start/2, stop/1]).
-export([init/1]).
start(Type, Args) ->
@@ -17,4 +17,11 @@ init([_Type, Args]) ->
{ok,{_SupFlags = {one_for_one, ?MAXIMUM_RESTARTS, ?MAX_DELAY_TIME},[
LogServerSup,
RestServerSup
- ]}}.
+ ]}}.
+
+stop(Args) ->
+ lists:map(fun(Term) -> Term:stop(Args) end, [
+ alice_log,
+ rest_server_sup
+ ]),
+ ok.
View
1 src/rest/rest_server.erl
@@ -122,6 +122,7 @@ handle_info(_Info, State) ->
%% The return value is ignored.
%%--------------------------------------------------------------------
terminate(_Reason, _State) ->
+ mochiweb_http:stop(),
ok.
%%--------------------------------------------------------------------
View
10 src/rest/rest_server_sup.erl
@@ -1,10 +1,14 @@
-module (rest_server_sup).
-behaviour(supervisor).
--export([start_link/1, init/1]).
+-export([start_link/1, init/1, stop/1]).
start_link(Args) ->
- supervisor:start_link({local, ?MODULE}, ?MODULE, Args).
+ supervisor:start_link({local, ?MODULE}, ?MODULE, Args).
init(Args) ->
- {ok, {{one_for_one, 2, 10}, [{the_rest_server, {rest_server, start_link, [Args]}, permanent, 2000, worker, [rest_server]}]}}.
+ {ok, {{one_for_one, 2, 10}, [{the_rest_server, {rest_server, start_link, [Args]}, permanent, 2000, worker, [rest_server]}]}}.
+
+stop(_Args) ->
+ Pid = whereis(?MODULE),
+ exit(Pid,kill).
View
13 src/utils/rabint.erl
@@ -13,11 +13,17 @@ rpc_call(Mod, Fun, Args) -> rpc:call(rabbit_node(), Mod, Fun, Args, ?RPC_TIMEOU
% Get the rabbit node from the env
rabbit_node() ->
case application:get_env(alice, rabbithost) of
- undefined -> localnode(rabbit);
- {ok, undefined} -> localnode(rabbit);
+ undefined -> get_rabbit_node_from_environment();
+ {ok, undefined} -> get_rabbit_node_from_environment();
{ok, Hostname} -> rabbit_node(Hostname)
end.
-
+
+get_rabbit_node_from_environment() ->
+ case os:getenv("RABBIT_HOST") of
+ false -> localnode(rabbit);
+ Server -> Server
+ end.
+
rabbit_node(Hostname) -> case Hostname of
H when is_atom(H) -> H;
Else -> list_to_atom(Else)
@@ -37,6 +43,7 @@ localnode(Name) ->
stay_connected_to_rabbit_node(Attempts) ->
case Attempts > ?MAX_ATTEMPTS of
true ->
+ alice_app:stop([]),
?ERROR("Lost connect with rabbitmq_server. Check that it's up and try again~n", []);
false ->
timer:sleep(?RABBIT_HEARTBEAT_DELAY),

0 comments on commit 3c2567b

Please sign in to comment.