diff --git a/apps/emqx/src/emqx_config_handler.erl b/apps/emqx/src/emqx_config_handler.erl index 792ede35b..664855be8 100644 --- a/apps/emqx/src/emqx_config_handler.erl +++ b/apps/emqx/src/emqx_config_handler.erl @@ -23,7 +23,7 @@ -export([ start_link/0 , start_handler/3 , update_config/2 - , child_spec/2 + , child_spec/3 ]). %% emqx_config_handler callbacks @@ -40,7 +40,7 @@ -type config() :: term(). -type config_map() :: #{atom() => config()} | [config_map()]. --type handler_name() :: module(). +-type handler_name() :: module() | top. -type key_path() :: [atom()]. -optional_callbacks([handle_update_config/2]). @@ -61,10 +61,10 @@ start_link() -> start_handler(HandlerName, Parent, ConfKeyPath) -> gen_server:start_link({local, HandlerName}, ?MODULE, {HandlerName, Parent, ConfKeyPath}, []). --spec child_spec(module(), key_path()) -> supervisor:child_spec(). -child_spec(Mod, KeyPath) -> +-spec child_spec(module(), handler_name(), key_path()) -> supervisor:child_spec(). +child_spec(Mod, Parent, KeyPath) -> #{id => Mod, - start => {?MODULE, start_handler, [Mod, ?MODULE, KeyPath]}, + start => {?MODULE, start_handler, [Mod, Parent, KeyPath]}, restart => permanent, type => worker, modules => [?MODULE]}. diff --git a/apps/emqx/src/emqx_kernel_sup.erl b/apps/emqx/src/emqx_kernel_sup.erl index 042416a40..4e29431e2 100644 --- a/apps/emqx/src/emqx_kernel_sup.erl +++ b/apps/emqx/src/emqx_kernel_sup.erl @@ -33,7 +33,9 @@ init([]) -> child_spec(emqx_stats, worker), child_spec(emqx_metrics, worker), child_spec(emqx_ctl, worker), - child_spec(emqx_zone, worker)]}}. + child_spec(emqx_zone, worker), + child_spec(emqx_config_handler, worker) + ]}}. child_spec(M, Type) -> child_spec(M, Type, []). diff --git a/apps/emqx_data_bridge/src/emqx_data_bridge_sup.erl b/apps/emqx_data_bridge/src/emqx_data_bridge_sup.erl index 20a447bf0..3ac1af7b2 100644 --- a/apps/emqx_data_bridge/src/emqx_data_bridge_sup.erl +++ b/apps/emqx_data_bridge/src/emqx_data_bridge_sup.erl @@ -36,7 +36,8 @@ init([]) -> restart => permanent, type => worker, modules => [emqx_data_bridge_monitor]}, - emqx_config_handler:child_spec(emqx_data_bridge_config_handler, config_key_path()) + emqx_config_handler:child_spec(emqx_data_bridge_config_handler, emqx_config_handler, + config_key_path()) ], {ok, {SupFlags, ChildSpecs}}. diff --git a/apps/emqx_resource/src/emqx_resource_instance.erl b/apps/emqx_resource/src/emqx_resource_instance.erl index 1e924e249..710deff0c 100644 --- a/apps/emqx_resource/src/emqx_resource_instance.erl +++ b/apps/emqx_resource/src/emqx_resource_instance.erl @@ -90,16 +90,6 @@ create_local(InstId, ResourceType, InstConf) -> Error -> Error end. -save_config_to_disk(InstId, ResourceType, Config) -> - %% TODO: send an event to the config handler, and the hander (single process) - %% will dump configs for all instances (from an ETS table) to a file. - file:write_file(filename:join([emqx_data_dir(), binary_to_list(InstId) ++ ".conf"]), - jsx:encode(#{id => InstId, resource_type => ResourceType, - config => emqx_resource:call_jsonify(ResourceType, Config)})). - -emqx_data_dir() -> - "data". - %%------------------------------------------------------------------------------ %% gen_server callbacks %%------------------------------------------------------------------------------ @@ -180,13 +170,7 @@ do_create(InstId, ResourceType, Config) -> #{mod => ResourceType, config => Config, state => ResourceState, status => stopped}}), _ = do_health_check(InstId), - case save_config_to_disk(InstId, ResourceType, Config) of - ok -> {ok, force_lookup(InstId)}; - {error, Reason} -> - logger:error("save config for ~p resource ~p to disk failed: ~p", - [ResourceType, InstId, Reason]), - {error, Reason} - end; + {ok, force_lookup(InstId)}; {error, Reason} -> logger:error("start ~s resource ~s failed: ~p", [ResourceType, InstId, Reason]), {error, Reason}