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