merge-config.escript 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env escript
  2. %% This script reads up emqx.conf and split the sections
  3. %% and dump sections to separate files.
  4. %% Sections are grouped between CONFIG_SECTION_BGN and
  5. %% CONFIG_SECTION_END pairs
  6. %%
  7. %% NOTE: this feature is so far not used in opensource
  8. %% edition due to backward-compatibility reasons.
  9. -mode(compile).
  10. main(_) ->
  11. BaseConf = "apps/emqx/etc/emqx.conf",
  12. {ok, Bin} = file:read_file(BaseConf),
  13. Apps = filelib:wildcard("emqx_*", "apps/"),
  14. Conf = lists:foldl(fun(App, Acc) ->
  15. case lists:member(App, ["emqx_exhook",
  16. "emqx_exproto",
  17. "emqx_lwm2m",
  18. "emqx_sn",
  19. "emqx_coap",
  20. "emqx_stomp",
  21. "emqx_dashboard"]) of
  22. true -> Acc;
  23. false ->
  24. Filename = filename:join([apps, App, "etc", App]) ++ ".conf",
  25. case filelib:is_regular(Filename) of
  26. true ->
  27. {ok, Bin1} = file:read_file(Filename),
  28. [Acc, io_lib:nl(), Bin1];
  29. false -> Acc
  30. end
  31. end
  32. end, Bin, Apps),
  33. ok = file:write_file("apps/emqx/etc/emqx.conf.all", Conf).