Unload emqx_alarm_handler before unloading plugins when shuting down (#2316)

emqx_alarm_handler publishes mqtt messages,
having it running while plugins are shutdown triggered some
annoying crashes
This commit is contained in:
spring2maz 2019-03-15 10:11:24 +01:00 committed by turtleDeng
parent b902ff3656
commit f2df92fef2
3 changed files with 7 additions and 1 deletions

View File

@ -159,6 +159,7 @@ shutdown() ->
shutdown(Reason) ->
emqx_logger:error("emqx shutdown for ~s", [Reason]),
emqx_alarm_handler:unload(),
emqx_plugins:unload(),
lists:foreach(fun application:stop/1, [emqx, ekka, cowboy, ranch, esockd, gproc]).

View File

@ -32,6 +32,7 @@
terminate/2]).
-export([load/0,
unload/0,
get_alarms/0]).
-record(common_alarm, {id, desc}).
@ -68,6 +69,10 @@ mnesia(copy) ->
load() ->
gen_event:swap_handler(alarm_handler, {alarm_handler, swap}, {?MODULE, []}).
%% on the way shutting down, give it back to OTP
unload() ->
gen_event:swap_handler(alarm_handler, {?MODULE, swap}, {alarm_handler, []}).
get_alarms() ->
gen_event:call(alarm_handler, ?MODULE, get_alarms).

View File

@ -43,7 +43,7 @@ start(_Type, _Args) ->
emqx_alarm_handler:load(),
emqx_logger_handler:init(),
print_vsn(),
{ok, Sup}.