This commit is contained in:
anlicheng 2025-05-20 12:41:34 +08:00
parent 2aca3fff45
commit cc2a6b7f87
3 changed files with 7 additions and 8 deletions

View File

@ -120,7 +120,7 @@ handle_call({stop_service, ServiceId}, _From, State = #state{}) ->
undefined -> undefined ->
{reply, {error, <<"service not running">>}, State}; {reply, {error, <<"service not running">>}, State};
ServicePid when is_pid(ServicePid) -> ServicePid when is_pid(ServicePid) ->
efka_service_sup:delete_service(ServiceId), efka_service_sup:stop_service(ServiceId),
%% , efka重启的时候 %% , efka重启的时候
ok = service_model:change_status(ServiceId, 0), ok = service_model:change_status(ServiceId, 0),
{reply, ok, State} {reply, ok, State}

View File

@ -209,18 +209,17 @@ handle_info({channel_reply, Ref, Reply}, State = #state{inflight = Inflight}) ->
{noreply, State#state{inflight = NInflight}} {noreply, State#state{inflight = NInflight}}
end; end;
handle_info({Port, {data, Data}}, State = #state{port = Port, service_id = ServiceId}) -> handle_info({Port, {data, Data}}, State = #state{service_id = ServiceId}) when is_port(Port) ->
lager:debug("[efka_service] service_id: ~p, port data: ~p", [ServiceId, Data]), lager:debug("[efka_service] service_id: ~p, port data: ~p", [ServiceId, Data]),
{noreply, State}; {noreply, State};
%% port的消息, Port的被动关闭会触发Port和State.port的值是相等的 %% port的消息, Port的被动关闭会触发Port和State.port的值是相等的
handle_info({Port, {exit_status, Code}}, State = #state{service_id = ServiceId}) -> handle_info({Port, {exit_status, Code}}, State = #state{service_id = ServiceId}) when is_port(Port) ->
lager:debug("[efka_service] service_id: ~p, port: ~p, exit with code: ~p", [ServiceId, Port, Code]), lager:debug("[efka_service] service_id: ~p, port: ~p, exit with code: ~p", [ServiceId, Port, Code]),
try_reboot(),
{noreply, State#state{port = undefined, os_pid = undefined}}; {noreply, State#state{port = undefined, os_pid = undefined}};
%% port的退出消息 %% port的退出消息
handle_info({'EXIT', Port, Reason}, State = #state{port = Port, service_id = ServiceId}) -> handle_info({'EXIT', Port, Reason}, State = #state{service_id = ServiceId}) when is_port(Port) ->
lager:debug("[efka_service] service_id: ~p, port: ~p, exit with reason: ~p", [ServiceId, Port, Reason]), lager:debug("[efka_service] service_id: ~p, port: ~p, exit with reason: ~p", [ServiceId, Port, Reason]),
try_reboot(), try_reboot(),
{noreply, State#state{port = undefined, os_pid = undefined}}; {noreply, State#state{port = undefined, os_pid = undefined}};

View File

@ -14,7 +14,7 @@
%% API %% API
-export([start_link/0]). -export([start_link/0]).
-export([start_service/1, delete_service/1]). -export([start_service/1, stop_service/1]).
%% Supervisor callbacks %% Supervisor callbacks
-export([init/1]). -export([init/1]).
@ -62,8 +62,8 @@ start_service(ServiceId) when is_binary(ServiceId) ->
{error, Error} {error, Error}
end. end.
-spec delete_service(ServiceId :: binary()) -> ok. -spec stop_service(ServiceId :: binary()) -> ok.
delete_service(ServiceId) when is_binary(ServiceId) -> stop_service(ServiceId) when is_binary(ServiceId) ->
ChildId = efka_service:get_name(ServiceId), ChildId = efka_service:get_name(ServiceId),
supervisor:terminate_child(?MODULE, ChildId), supervisor:terminate_child(?MODULE, ChildId),
supervisor:delete_child(?MODULE, ChildId). supervisor:delete_child(?MODULE, ChildId).