mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
* src/ejabberd_check.erl: Separate config loading from configuration sanity checks (EJAB-533)
* src/src/ejabberd_app.erl: Likewise * src/ejabberd_app.erl: Likewise SVN Revision: 1210
This commit is contained in:
parent
f4f3d06120
commit
868182d1c8
@ -1,3 +1,10 @@
|
|||||||
|
2008-02-27 Mickael Remond <mremond@process-one.net>
|
||||||
|
|
||||||
|
* src/ejabberd_check.erl: Separate config loading from
|
||||||
|
configuration sanity checks (EJAB-533)
|
||||||
|
* src/src/ejabberd_app.erl: Likewise
|
||||||
|
* src/ejabberd_app.erl: Likewise
|
||||||
|
|
||||||
2008-02-26 Badlop <badlop@process-one.net>
|
2008-02-26 Badlop <badlop@process-one.net>
|
||||||
|
|
||||||
* src/msgs/it.msg: Updated (thanks to Smart2128)
|
* src/msgs/it.msg: Updated (thanks to Smart2128)
|
||||||
|
@ -46,6 +46,7 @@ start(normal, _Args) ->
|
|||||||
ejabberd_ctl:init(),
|
ejabberd_ctl:init(),
|
||||||
gen_mod:start(),
|
gen_mod:start(),
|
||||||
ejabberd_config:start(),
|
ejabberd_config:start(),
|
||||||
|
ejabberd_check:config(),
|
||||||
start(),
|
start(),
|
||||||
connect_nodes(),
|
connect_nodes(),
|
||||||
Sup = ejabberd_sup:start_link(),
|
Sup = ejabberd_sup:start_link(),
|
||||||
|
100
src/ejabberd_check.erl
Normal file
100
src/ejabberd_check.erl
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
%%%----------------------------------------------------------------------
|
||||||
|
%%% File : ejabberd_check.erl
|
||||||
|
%%% Author : Mickael Remond <mremond@process-one.net>
|
||||||
|
%%% Purpose : Check ejabberd configuration and
|
||||||
|
%%% Created : 27 Feb 2008 by Mickael Remond <mremond@process-one.net>
|
||||||
|
%%%
|
||||||
|
%%%
|
||||||
|
%%% ejabberd, Copyright (C) 2002-2008 Process-one
|
||||||
|
%%%
|
||||||
|
%%% This program is free software; you can redistribute it and/or
|
||||||
|
%%% modify it under the terms of the GNU General Public License as
|
||||||
|
%%% published by the Free Software Foundation; either version 2 of the
|
||||||
|
%%% License, or (at your option) any later version.
|
||||||
|
%%%
|
||||||
|
%%% This program is distributed in the hope that it will be useful,
|
||||||
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
%%% General Public License for more details.
|
||||||
|
%%%
|
||||||
|
%%% You should have received a copy of the GNU General Public License
|
||||||
|
%%% along with this program; if not, write to the Free Software
|
||||||
|
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
%%% 02111-1307 USA
|
||||||
|
%%%
|
||||||
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
|
-module(ejabberd_check).
|
||||||
|
|
||||||
|
-export([libs/0, config/0]).
|
||||||
|
|
||||||
|
-include("ejabberd.hrl").
|
||||||
|
-include("ejabberd_config.hrl").
|
||||||
|
|
||||||
|
-compile([export_all]).
|
||||||
|
|
||||||
|
%% TODO:
|
||||||
|
%% We want to implement library checking at launch time to issue
|
||||||
|
%% human readable user messages.
|
||||||
|
libs() ->
|
||||||
|
ok.
|
||||||
|
|
||||||
|
%% Consistency check on ejabberd configuration
|
||||||
|
config() ->
|
||||||
|
check_database_modules().
|
||||||
|
|
||||||
|
check_database_modules() ->
|
||||||
|
[check_database_module(M)||M<-get_db_used()].
|
||||||
|
|
||||||
|
check_database_module(mysql) ->
|
||||||
|
check_modules(mysql, [mysql, mysql_auth, mysql_conn, mysql_recv]);
|
||||||
|
check_database_module(pgsql) ->
|
||||||
|
check_modules(pgsql, [pgsql, pgsql_proto, pgsql_tcp, pgsql_util]).
|
||||||
|
|
||||||
|
%% Issue a critical error and throw an exit if needing module is
|
||||||
|
%% missing.
|
||||||
|
check_modules(DB, Modules) ->
|
||||||
|
case get_missing_modules(Modules) of
|
||||||
|
[] ->
|
||||||
|
ok;
|
||||||
|
MissingModules when is_list(MissingModules) ->
|
||||||
|
?CRITICAL_MSG("ejabberd is configured to use '~p', but the following Erlang modules are not installed: '~p'", [DB, MissingModules]),
|
||||||
|
exit(database_module_missing)
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
%% Return the list of undefined modules
|
||||||
|
get_missing_modules(Modules) ->
|
||||||
|
lists:filter(fun(Module) ->
|
||||||
|
case catch Module:module_info() of
|
||||||
|
{'EXIT', {undef, _}} ->
|
||||||
|
true;
|
||||||
|
_ -> false
|
||||||
|
end
|
||||||
|
end, Modules).
|
||||||
|
|
||||||
|
%% Return the list of databases used
|
||||||
|
get_db_used() ->
|
||||||
|
%% Retrieve domains with a database configured:
|
||||||
|
Domains =
|
||||||
|
ets:match(local_config, #local_config{key={odbc_server, '$1'},
|
||||||
|
value='$2'}),
|
||||||
|
%% Check that odbc is the auth method used for those domains:
|
||||||
|
%% and return the database name
|
||||||
|
DBs = lists:foldr(
|
||||||
|
fun([Domain, DB], Acc) ->
|
||||||
|
case check_odbc_option(
|
||||||
|
ejabberd_config:get_local_option(
|
||||||
|
{auth_method, Domain})) of
|
||||||
|
true -> [element(1, DB)|Acc];
|
||||||
|
_ -> Acc
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
[], Domains),
|
||||||
|
lists:usort(DBs).
|
||||||
|
|
||||||
|
%% Return true if odbc option is used
|
||||||
|
check_odbc_option(odbc) ->
|
||||||
|
true;
|
||||||
|
check_odbc_option(AuthMethods) when is_list(AuthMethods) ->
|
||||||
|
lists:member(odbc, AuthMethods).
|
@ -182,7 +182,6 @@ process_host_term(Term, Host, State) ->
|
|||||||
{hosts, _Hosts} ->
|
{hosts, _Hosts} ->
|
||||||
State;
|
State;
|
||||||
{odbc_server, ODBC_server} ->
|
{odbc_server, ODBC_server} ->
|
||||||
odbc_modules_found = check_odbc_modules(ODBC_server),
|
|
||||||
add_option({odbc_server, Host}, ODBC_server, State);
|
add_option({odbc_server, Host}, ODBC_server, State);
|
||||||
{Opt, Val} ->
|
{Opt, Val} ->
|
||||||
add_option({Opt, Host}, Val, State)
|
add_option({Opt, Host}, Val, State)
|
||||||
@ -309,33 +308,3 @@ get_vh_by_auth_method(AuthMethod) ->
|
|||||||
mnesia:dirty_select(local_config,
|
mnesia:dirty_select(local_config,
|
||||||
[{#local_config{key = {auth_method, '$1'},
|
[{#local_config{key = {auth_method, '$1'},
|
||||||
value=AuthMethod},[],['$1']}]).
|
value=AuthMethod},[],['$1']}]).
|
||||||
|
|
||||||
check_odbc_modules(ODBC_server) ->
|
|
||||||
case catch check_odbc_modules2(ODBC_server) of
|
|
||||||
{'EXIT', {undef, [{Module, module_info, []} | _]}} ->
|
|
||||||
?CRITICAL_MSG("ejabberd is configured to use ODBC, but the Erlang module '~p' is not installed.", [Module]),
|
|
||||||
odbc_module_not_found;
|
|
||||||
_ -> odbc_modules_found
|
|
||||||
end.
|
|
||||||
|
|
||||||
check_odbc_modules2(ODBC_server) ->
|
|
||||||
check_modules_exists([ejabberd_odbc, ejabberd_odbc_sup, odbc_queries]),
|
|
||||||
case ODBC_server of
|
|
||||||
{mysql, _Server, _DB, _Username, _Password} ->
|
|
||||||
check_modules_exists([mysql, mysql_auth, mysql_conn, mysql_recv]);
|
|
||||||
|
|
||||||
{mysql, _Server, _Port, _DB, _Username, _Password} ->
|
|
||||||
check_modules_exists([mysql, mysql_auth, mysql_conn, mysql_recv]);
|
|
||||||
|
|
||||||
{pgsql, _Server, _DB, _Username, _Password} ->
|
|
||||||
check_modules_exists([pgsql, pgsql_proto, pgsql_tcp, pgsql_util]);
|
|
||||||
|
|
||||||
{pgsql, _Server, _Port, _DB, _Username, _Password} ->
|
|
||||||
check_modules_exists([pgsql, pgsql_proto, pgsql_tcp, pgsql_util]);
|
|
||||||
|
|
||||||
Server when is_list(Server) ->
|
|
||||||
ok
|
|
||||||
end.
|
|
||||||
|
|
||||||
check_modules_exists(Modules) ->
|
|
||||||
[true = is_list(Module:module_info()) || Module <- Modules].
|
|
||||||
|
Loading…
Reference in New Issue
Block a user