From cc2a6b7f87efd436e98d6e14d88163539ff6d2e6 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Tue, 20 May 2025 12:41:34 +0800 Subject: [PATCH] fix --- apps/efka/src/efka_inetd.erl | 2 +- apps/efka/src/efka_service.erl | 7 +++---- apps/efka/src/efka_service_sup.erl | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/efka/src/efka_inetd.erl b/apps/efka/src/efka_inetd.erl index c5ec919..b9b0dfb 100644 --- a/apps/efka/src/efka_inetd.erl +++ b/apps/efka/src/efka_inetd.erl @@ -120,7 +120,7 @@ handle_call({stop_service, ServiceId}, _From, State = #state{}) -> undefined -> {reply, {error, <<"service not running">>}, State}; ServicePid when is_pid(ServicePid) -> - efka_service_sup:delete_service(ServiceId), + efka_service_sup:stop_service(ServiceId), %% 主动停止的服务,需要更新数据库状态, 状态是为了保证下次efka重启的时候,不自动启动服务 ok = service_model:change_status(ServiceId, 0), {reply, ok, State} diff --git a/apps/efka/src/efka_service.erl b/apps/efka/src/efka_service.erl index 6d053fa..04f0b97 100644 --- a/apps/efka/src/efka_service.erl +++ b/apps/efka/src/efka_service.erl @@ -209,18 +209,17 @@ handle_info({channel_reply, Ref, Reply}, State = #state{inflight = Inflight}) -> {noreply, State#state{inflight = NInflight}} 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]), {noreply, State}; %% 处理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]), - try_reboot(), {noreply, State#state{port = undefined, os_pid = undefined}}; %% 处理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]), try_reboot(), {noreply, State#state{port = undefined, os_pid = undefined}}; diff --git a/apps/efka/src/efka_service_sup.erl b/apps/efka/src/efka_service_sup.erl index e83ad95..b7aaae2 100644 --- a/apps/efka/src/efka_service_sup.erl +++ b/apps/efka/src/efka_service_sup.erl @@ -14,7 +14,7 @@ %% API -export([start_link/0]). --export([start_service/1, delete_service/1]). +-export([start_service/1, stop_service/1]). %% Supervisor callbacks -export([init/1]). @@ -62,8 +62,8 @@ start_service(ServiceId) when is_binary(ServiceId) -> {error, Error} end. --spec delete_service(ServiceId :: binary()) -> ok. -delete_service(ServiceId) when is_binary(ServiceId) -> +-spec stop_service(ServiceId :: binary()) -> ok. +stop_service(ServiceId) when is_binary(ServiceId) -> ChildId = efka_service:get_name(ServiceId), supervisor:terminate_child(?MODULE, ChildId), supervisor:delete_child(?MODULE, ChildId).