This commit is contained in:
anlicheng 2025-05-05 22:10:52 +08:00
parent 333d51613e
commit 8d869f5bc0
2 changed files with 6 additions and 5 deletions

View File

@ -94,6 +94,7 @@ init([Service = #micro_service{service_id = ServiceId, work_dir = WorkDir0, stat
case file:read_file(WorkDir ++ "manifest.json") of
{ok, ManifestInfo} ->
Manifest = jiffy:decode(ManifestInfo, [return_maps]),
lager:debug("main: ~p", [Manifest]),
case check_manifest(Manifest) of
ok ->
%% 2
@ -241,9 +242,9 @@ handle_info({'DOWN', _Ref, process, ChannelPid, Reason}, State = #state{channel_
%% with Reason. The return value is ignored.
-spec(terminate(Reason :: (normal | shutdown | {shutdown, term()} | term()),
State :: #state{}) -> term()).
terminate(Reason, _State = #state{port = Port}) ->
terminate(Reason, _State = #state{os_pid = OSPid}) ->
lager:debug("[efka_micro_service] terminate with reason: ~p", [Reason]),
kill_os_pid(Port),
kill_os_pid(OSPid),
ok.
%% @private
@ -265,7 +266,7 @@ check_manifest(Manifest) when is_map(Manifest) ->
check_manifest0(RequiredKeys, Manifest).
check_manifest0([], _Manifest) ->
true;
ok;
check_manifest0([<<"serivce_id">>|T], Manifest) ->
case maps:find(<<"serivce_id">>, Manifest) of
error ->
@ -363,7 +364,7 @@ kill_service(WorkDir0, ExecCmd0, OSPid) when is_binary(WorkDir0) ->
%%
-spec boot_service(WorkDir :: binary(), ExecCmd :: binary() | [binary()]) -> {ok, Port :: port()} | {error, Reason :: binary()}.
boot_service(WorkDir0, ExecCmd0) when is_binary(WorkDir0), is_binary(ExecCmd0) ->
boot_service(WorkDir0, ExecCmd0) when is_binary(WorkDir0), is_binary(ExecCmd0); is_list(ExecCmd0) ->
{RealExecCmd, PortSettings} = make_cmd(WorkDir0, ExecCmd0),
Port = erlang:open_port({spawn_executable, RealExecCmd}, PortSettings),
{ok, Port}.

View File

@ -55,7 +55,7 @@ init([]) ->
service_name = <<"测试服务">>,
from = <<"master">>,
%%
work_dir = <<"/tmp/test/">>,
work_dir = <<"/usr/local/code/tmp/test/">>,
params = <<"">>,
metrics = <<"">>,
%% 0: , 1: