2003-02-01 21:21:28 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : ejabberd_app.erl
|
|
|
|
%%% Author : Alexey Shchepin <alexey@sevcom.net>
|
|
|
|
%%% Purpose :
|
|
|
|
%%% Created : 31 Jan 2003 by Alexey Shchepin <alexey@sevcom.net>
|
|
|
|
%%% Id : $Id$
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(ejabberd_app).
|
|
|
|
-author('alexey@sevcom.net').
|
|
|
|
-vsn('$Revision$ ').
|
|
|
|
|
|
|
|
-behaviour(application).
|
|
|
|
|
|
|
|
-export([start/2, stop/1, init/0]).
|
|
|
|
|
2003-05-09 21:32:59 +02:00
|
|
|
-export([dump_ports/0]).
|
|
|
|
|
2003-02-01 21:21:28 +01:00
|
|
|
-include("ejabberd.hrl").
|
|
|
|
|
2003-10-18 21:15:12 +02:00
|
|
|
start(normal, _Args) ->
|
2003-07-20 22:35:35 +02:00
|
|
|
application:start(sasl),
|
2003-02-01 21:21:28 +01:00
|
|
|
randoms:start(),
|
|
|
|
db_init(),
|
|
|
|
sha:start(),
|
2003-02-10 13:55:05 +01:00
|
|
|
catch ssl:start(),
|
2003-02-01 21:21:28 +01:00
|
|
|
translate:start(),
|
|
|
|
acl:start(),
|
|
|
|
gen_mod:start(),
|
|
|
|
ejabberd_config:start(),
|
|
|
|
ejabberd_auth:start(),
|
2003-03-09 21:46:47 +01:00
|
|
|
cyrsasl:start(),
|
2003-07-20 22:35:35 +02:00
|
|
|
% Profiling
|
|
|
|
%eprof:start(),
|
|
|
|
%eprof:profile([self()]),
|
2003-10-18 21:15:12 +02:00
|
|
|
%fprof:trace(start, "/tmp/fprof"),
|
2003-02-01 21:21:28 +01:00
|
|
|
Sup = ejabberd_sup:start_link(),
|
|
|
|
start(),
|
|
|
|
load_modules(),
|
|
|
|
Sup;
|
|
|
|
start(_, _) ->
|
|
|
|
{error, badarg}.
|
|
|
|
|
2003-10-18 21:15:12 +02:00
|
|
|
stop(_StartArgs) ->
|
2003-02-01 21:21:28 +01:00
|
|
|
ok.
|
|
|
|
|
|
|
|
start() ->
|
2003-07-20 22:35:35 +02:00
|
|
|
spawn_link(?MODULE, init, []).
|
2003-02-01 21:21:28 +01:00
|
|
|
|
|
|
|
init() ->
|
|
|
|
register(ejabberd, self()),
|
|
|
|
%erlang:system_flag(fullsweep_after, 0),
|
2003-10-23 21:20:56 +02:00
|
|
|
%error_logger:logfile({open, ?LOG_PATH}),
|
2004-04-15 21:55:38 +02:00
|
|
|
LogPath =
|
|
|
|
case application:get_env(log_path) of
|
|
|
|
{ok, Path} ->
|
|
|
|
Path;
|
|
|
|
undefined ->
|
|
|
|
case os:getenv("EJABBERD_LOG_PATH") of
|
|
|
|
false ->
|
|
|
|
?LOG_PATH;
|
|
|
|
Path ->
|
|
|
|
Path
|
|
|
|
end
|
|
|
|
end,
|
2003-12-28 21:59:21 +01:00
|
|
|
error_logger:add_report_handler(ejabberd_logger_h, LogPath),
|
2003-10-10 21:01:11 +02:00
|
|
|
%timer:apply_interval(3600000, ?MODULE, dump_ports, []),
|
2003-12-28 21:59:21 +01:00
|
|
|
ok = erl_ddll:load_driver(ejabberd:get_so_path(), expat_erl),
|
2003-02-01 21:21:28 +01:00
|
|
|
Port = open_port({spawn, expat_erl}, [binary]),
|
|
|
|
loop(Port).
|
|
|
|
|
|
|
|
|
|
|
|
loop(Port) ->
|
|
|
|
receive
|
|
|
|
_ ->
|
|
|
|
loop(Port)
|
|
|
|
end.
|
|
|
|
|
|
|
|
db_init() ->
|
|
|
|
case mnesia:system_info(extra_db_nodes) of
|
|
|
|
[] ->
|
|
|
|
mnesia:create_schema([node()]);
|
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end,
|
|
|
|
mnesia:start(),
|
|
|
|
mnesia:wait_for_tables(mnesia:system_info(local_tables), infinity).
|
|
|
|
|
|
|
|
load_modules() ->
|
|
|
|
case ejabberd_config:get_local_option(modules) of
|
|
|
|
undefined ->
|
|
|
|
ok;
|
|
|
|
Modules ->
|
|
|
|
lists:foreach(fun({Module, Args}) ->
|
|
|
|
gen_mod:start_module(Module, Args)
|
|
|
|
end, Modules)
|
|
|
|
end.
|
|
|
|
|
2003-05-09 21:32:59 +02:00
|
|
|
|
|
|
|
dump_ports() ->
|
|
|
|
?INFO_MSG("ports:~n ~p",
|
|
|
|
[lists:map(fun(P) -> erlang:port_info(P) end, erlang:ports())]).
|
|
|
|
|