mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Make sure Mnesia dir environment and log file are list, not binary
This is useful for Elixir configuration, as binary is the more natural data type. Closes #514
This commit is contained in:
parent
ea8db9967f
commit
47537aa901
@ -110,6 +110,7 @@ loop() ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
db_init() ->
|
db_init() ->
|
||||||
|
ejabberd_config:env_binary_to_list(mnesia, dir),
|
||||||
MyNode = node(),
|
MyNode = node(),
|
||||||
DbNodes = mnesia:system_info(db_nodes),
|
DbNodes = mnesia:system_info(db_nodes),
|
||||||
case lists:member(MyNode, DbNodes) of
|
case lists:member(MyNode, DbNodes) of
|
||||||
|
@ -35,7 +35,8 @@
|
|||||||
get_version/0, get_myhosts/0, get_mylang/0,
|
get_version/0, get_myhosts/0, get_mylang/0,
|
||||||
prepare_opt_val/4, convert_table_to_binary/5,
|
prepare_opt_val/4, convert_table_to_binary/5,
|
||||||
transform_options/1, collect_options/1,
|
transform_options/1, collect_options/1,
|
||||||
convert_to_yaml/1, convert_to_yaml/2]).
|
convert_to_yaml/1, convert_to_yaml/2,
|
||||||
|
env_binary_to_list/2]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
@ -167,6 +168,22 @@ convert_to_yaml(File, Output) ->
|
|||||||
file:write_file(FileName, Data)
|
file:write_file(FileName, Data)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%% Some Erlang apps expects env parameters to be list and not binary.
|
||||||
|
%% For example, Mnesia is not able to start if mnesia dir is passed as a binary.
|
||||||
|
%% However, binary is most common on Elixir, so it is easy to make a setup mistake.
|
||||||
|
-spec env_binary_to_list(atom(), atom()) -> {ok, any()}|undefined.
|
||||||
|
env_binary_to_list(Application, Parameter) ->
|
||||||
|
%% Application need to be loaded to allow setting parameters
|
||||||
|
application:load(Application),
|
||||||
|
case application:get_env(Application, Parameter) of
|
||||||
|
{ok, Val} when is_binary(Val) ->
|
||||||
|
BVal = binary_to_list(Val),
|
||||||
|
application:set_env(Application, Parameter, BVal),
|
||||||
|
{ok, BVal};
|
||||||
|
Other ->
|
||||||
|
Other
|
||||||
|
end.
|
||||||
|
|
||||||
%% @doc Read an ejabberd configuration file and return the terms.
|
%% @doc Read an ejabberd configuration file and return the terms.
|
||||||
%% Input is an absolute or relative path to an ejabberd config file.
|
%% Input is an absolute or relative path to an ejabberd config file.
|
||||||
%% Returns a list of plain terms,
|
%% Returns a list of plain terms,
|
||||||
|
@ -46,8 +46,10 @@
|
|||||||
%% If not defined it checks the environment variable EJABBERD_LOG_PATH.
|
%% If not defined it checks the environment variable EJABBERD_LOG_PATH.
|
||||||
%% And if that one is neither defined, returns the default value:
|
%% And if that one is neither defined, returns the default value:
|
||||||
%% "ejabberd.log" in current directory.
|
%% "ejabberd.log" in current directory.
|
||||||
|
%% Note: If the directory where to place the ejabberd log file to not exist,
|
||||||
|
%% it is not created and no log file will be generated.
|
||||||
get_log_path() ->
|
get_log_path() ->
|
||||||
case application:get_env(ejabberd, log_path) of
|
case ejabberd_config:env_binary_to_list(ejabberd, log_path) of
|
||||||
{ok, Path} ->
|
{ok, Path} ->
|
||||||
Path;
|
Path;
|
||||||
undefined ->
|
undefined ->
|
||||||
|
Loading…
Reference in New Issue
Block a user