fix
This commit is contained in:
parent
2aca3fff45
commit
cc2a6b7f87
@ -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}
|
||||
|
||||
@ -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}};
|
||||
|
||||
@ -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).
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user