fix
This commit is contained in:
parent
32868d3444
commit
0bb521f6a0
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
test() ->
|
test() ->
|
||||||
Pid = get_pid(<<"test1234">>),
|
Pid = get_pid(<<"test1234">>),
|
||||||
|
stop_service(Pid),
|
||||||
start_service(Pid).
|
start_service(Pid).
|
||||||
|
|
||||||
-spec get_name(ServiceId :: binary()) -> atom().
|
-spec get_name(ServiceId :: binary()) -> atom().
|
||||||
@ -133,15 +134,13 @@ handle_call(start_service, _From, State = #state{running_status = ?STATUS_STOPPE
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
%% 停止服务, 主动停止的时候会改变服务配置的status字段
|
%% 停止服务, 主动停止的时候会改变服务配置的status字段
|
||||||
handle_call(stop_service, _From, State = #state{running_status = RunningStatus, port = Port, service = Service = #micro_service{service_id = ServiceId}}) ->
|
handle_call(stop_service, _From, State = #state{running_status = ?STATUS_STOPPED}) ->
|
||||||
case RunningStatus of
|
|
||||||
?STATUS_STOPPED ->
|
|
||||||
{reply, {error, <<"service not running">>}, State};
|
{reply, {error, <<"service not running">>}, State};
|
||||||
?STATUS_RUNNING ->
|
|
||||||
ok = micro_service_model:stop_service(ServiceId),
|
handle_call(stop_service, _From, State = #state{running_status = ?STATUS_RUNNING, port = Port, service = Service = #micro_service{service_id = ServiceId}}) when is_port(Port) ->
|
||||||
|
micro_service_model:stop_service(ServiceId),
|
||||||
kill_os_pid(Port),
|
kill_os_pid(Port),
|
||||||
{reply, ok, State#state{port = undefined, service = Service#micro_service{status = 0}}}
|
{reply, ok, State#state{port = undefined, running_status = ?STATUS_STOPPED, service = Service#micro_service{status = 0}}};
|
||||||
end;
|
|
||||||
|
|
||||||
handle_call(_Request, _From, State = #state{}) ->
|
handle_call(_Request, _From, State = #state{}) ->
|
||||||
{reply, ok, State}.
|
{reply, ok, State}.
|
||||||
@ -180,7 +179,7 @@ handle_info({Port, {data, Data}}, State = #state{port = Port, service = Service}
|
|||||||
%% 处理port的消息, Port的被动关闭会触发;因此这个时候的Port和State.port的值是相等的
|
%% 处理port的消息, Port的被动关闭会触发;因此这个时候的Port和State.port的值是相等的
|
||||||
handle_info({Port, {exit_status, Code}}, State = #state{port = Port, service = Service}) ->
|
handle_info({Port, {exit_status, Code}}, State = #state{port = Port, service = Service}) ->
|
||||||
lager:debug("[efka_micro_service] service_id: ~p, port exit with code: ~p", [Service#micro_service.service_id, Code]),
|
lager:debug("[efka_micro_service] service_id: ~p, port exit with code: ~p", [Service#micro_service.service_id, Code]),
|
||||||
erlang:start_timer(5000, self(), reboot_service),
|
% erlang:start_timer(5000, self(), reboot_service),
|
||||||
|
|
||||||
{noreply, State#state{port = undefined}};
|
{noreply, State#state{port = undefined}};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user