]> granicus.if.org Git - ejabberd/commitdiff
When module start fails during server start, stop erlang (EJAB-1446)
authorBadlop <badlop@process-one.net>
Mon, 16 May 2011 20:33:08 +0000 (22:33 +0200)
committerBadlop <badlop@process-one.net>
Mon, 16 May 2011 20:33:51 +0000 (22:33 +0200)
src/gen_mod.erl

index 57b6ea8f70fad5e84a74caa1efe585886eb1d9f3..6289d9783d90229782c2af717a18a3f4cdb45ed4 100644 (file)
@@ -85,11 +85,24 @@ start_module2(Host, Module, Opts) ->
     catch Class:Reason ->
            del_module_mnesia(Host, Module),
            ets:delete(ejabberd_modules, {Module, Host}),
-           ?ERROR_MSG("Problem starting the module ~p for host ~p with options:~n  ~p~n  ~p: ~p",
+           ErrorText = io_lib:format("Problem starting the module ~p for host ~p ~n options: ~p~n ~p: ~p",
                    [Module, Host, Opts, Class, Reason]),
-           erlang:raise(Class, Reason, erlang:get_stacktrace())
+           ?CRITICAL_MSG(ErrorText, []),
+           case is_app_running(ejabberd) of
+               true ->
+                   erlang:raise(Class, Reason, erlang:get_stacktrace());
+               false ->
+                   ?CRITICAL_MSG("ejabberd initialization was aborted because a module start failed.", []),
+                   timer:sleep(3000),
+                   erlang:halt(lists:flatten(ErrorText))
+           end
     end.
 
+is_app_running(AppName) ->
+    %% Use a high timeout to prevent a false positive in a high load system
+    Timeout = 15000,
+    lists:keymember(AppName, 1, application:which_applications(Timeout)).
+
 %% @doc Stop the module in a host, and forget its configuration.
 stop_module(Host, Module) ->
     case stop_module_keep_config(Host, Module) of