emqx_modules_app.erl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2021-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. -module(emqx_modules_app).
  17. -behaviour(application).
  18. -export([
  19. start/2,
  20. stop/1
  21. ]).
  22. start(_Type, _Args) ->
  23. ok = mria:wait_for_tables(emqx_delayed:create_tables()),
  24. {ok, Sup} = emqx_modules_sup:start_link(),
  25. maybe_enable_modules(),
  26. {ok, Sup}.
  27. stop(_State) ->
  28. maybe_disable_modules(),
  29. ok.
  30. maybe_enable_modules() ->
  31. emqx_conf:get([delayed, enable], true) andalso emqx_delayed:load(),
  32. emqx_observer_cli:enable(),
  33. emqx_conf_cli:load(),
  34. ok = emqx_rewrite:enable(),
  35. emqx_topic_metrics:enable(),
  36. emqx_modules_conf:load().
  37. maybe_disable_modules() ->
  38. emqx_conf:get([delayed, enable], true) andalso emqx_delayed:unload(),
  39. emqx_conf:get([observer_cli, enable], true) andalso emqx_observer_cli:disable(),
  40. emqx_rewrite:disable(),
  41. emqx_conf_cli:unload(),
  42. emqx_topic_metrics:disable(),
  43. emqx_modules_conf:unload().