merge-config.escript 1.0 KB

123456789101112131415161718192021222324252627
  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. {ok, BaseConf} = file:read_file("apps/emqx_conf/etc/emqx_conf.conf"),
  12. Apps = filelib:wildcard("*", "apps/") -- ["emqx_machine", "emqx_conf"],
  13. Conf = lists:foldl(fun(App, Acc) ->
  14. Filename = filename:join([apps, App, "etc", App]) ++ ".conf",
  15. case filelib:is_regular(Filename) of
  16. true ->
  17. {ok, Bin1} = file:read_file(Filename),
  18. [Acc, io_lib:nl(), Bin1];
  19. false -> Acc
  20. end
  21. end, BaseConf, Apps),
  22. ClusterInc = "include \"cluster-override.conf\"\n",
  23. LocalInc = "include \"local-override.conf\"\n",
  24. ok = file:write_file("apps/emqx_conf/etc/emqx.conf.all", [Conf, ClusterInc, LocalInc]).