Plugins configuration insert to ets table
This commit is contained in:
parent
d3f52898ee
commit
7260b17cb5
|
@ -22,15 +22,43 @@
|
||||||
set_usage/0,
|
set_usage/0,
|
||||||
all_cfgs/0,
|
all_cfgs/0,
|
||||||
get_cfg/2,
|
get_cfg/2,
|
||||||
get_cfg/3]).
|
get_cfg/3,
|
||||||
|
read_config/1,
|
||||||
|
write_config/2]).
|
||||||
|
|
||||||
-define(APP, emqttd).
|
-define(APP, emqttd).
|
||||||
|
-define(TAB, emqttd_config).
|
||||||
|
|
||||||
register_config() ->
|
register_config() ->
|
||||||
application:start(clique),
|
application:start(clique),
|
||||||
F = fun() -> ekka_mnesia:running_nodes() end,
|
F = fun() -> ekka_mnesia:running_nodes() end,
|
||||||
clique:register_node_finder(F),
|
clique:register_node_finder(F),
|
||||||
register_config_cli().
|
register_config_cli(),
|
||||||
|
create_config_tab().
|
||||||
|
|
||||||
|
create_config_tab() ->
|
||||||
|
case ets:info(?TAB, name) of
|
||||||
|
undefined ->
|
||||||
|
ets:new(?TAB, [named_table, public]),
|
||||||
|
{ok, PluginsEtcDir} = emqttd:env(plugins_etc_dir),
|
||||||
|
Files = filelib:wildcard("*.conf", PluginsEtcDir),
|
||||||
|
lists:foreach(fun(File) ->
|
||||||
|
[FileName, _] = string:split(File, "."),
|
||||||
|
Configs = cuttlefish_conf:file(lists:concat([PluginsEtcDir, File])),
|
||||||
|
ets:insert(?TAB, {list_to_atom(FileName), Configs})
|
||||||
|
end, Files);
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
|
read_config(App) ->
|
||||||
|
case ets:lookup(?TAB, App) of
|
||||||
|
[] -> [];
|
||||||
|
[{_, Value}] -> Value
|
||||||
|
end.
|
||||||
|
|
||||||
|
write_config(App, Terms) ->
|
||||||
|
ets:insert(?TAB, {App, Terms}).
|
||||||
|
|
||||||
run(Cmd) ->
|
run(Cmd) ->
|
||||||
clique:run(Cmd).
|
clique:run(Cmd).
|
||||||
|
|
|
@ -57,6 +57,7 @@ write(App, Terms) ->
|
||||||
Schema = cuttlefish_schema:files([Path]),
|
Schema = cuttlefish_schema:files([Path]),
|
||||||
case cuttlefish_generator:map(Schema, Configs) of
|
case cuttlefish_generator:map(Schema, Configs) of
|
||||||
[{App, Configs1}] ->
|
[{App, Configs1}] ->
|
||||||
|
emqttd_cli_config:write_config(App, Configs),
|
||||||
lists:foreach(fun({Key, Val}) -> application:set_env(App, Key, Val) end, Configs1);
|
lists:foreach(fun({Key, Val}) -> application:set_env(App, Key, Val) end, Configs1);
|
||||||
_ ->
|
_ ->
|
||||||
error
|
error
|
||||||
|
@ -87,9 +88,8 @@ get(App, Par, Def) ->
|
||||||
|
|
||||||
|
|
||||||
read_(App) ->
|
read_(App) ->
|
||||||
{ok, PluginsEtcDir} = emqttd:env(plugins_etc_dir),
|
Configs = emqttd_cli_config:read_config(App),
|
||||||
Configs = cuttlefish_conf:file(lists:concat([PluginsEtcDir, App, ".conf"])),
|
Path = lists:concat([code:priv_dir(App), "/", App, ".schema"]),
|
||||||
Path= lists:concat([code:priv_dir(App), "/", App, ".schema"]),
|
|
||||||
{_, Mappings, _} = cuttlefish_schema:files([Path]),
|
{_, Mappings, _} = cuttlefish_schema:files([Path]),
|
||||||
OptionalCfg = lists:foldl(fun(Map, Acc) ->
|
OptionalCfg = lists:foldl(fun(Map, Acc) ->
|
||||||
Key = cuttlefish_mapping:variable(Map),
|
Key = cuttlefish_mapping:variable(Map),
|
||||||
|
|
Loading…
Reference in New Issue