diff --git a/apps/efka/src/efka_manifest.erl b/apps/efka/src/efka_manifest.erl index b311840..d7869ec 100644 --- a/apps/efka/src/efka_manifest.erl +++ b/apps/efka/src/efka_manifest.erl @@ -26,7 +26,7 @@ -spec new(ServiceRootDir :: string()) -> {ok, #manifest{}} | {error, Reason :: binary()}. new(ServiceRootDir) when is_list(ServiceRootDir) -> - WorkDir = ServiceRootDir + "/work_dir/", + WorkDir = ServiceRootDir ++ "/work_dir/", case file:read_file(WorkDir ++ "manifest.json") of {ok, ManifestInfo} -> Settings = catch jiffy:decode(ManifestInfo, [return_maps]), diff --git a/apps/efka/src/efka_service.erl b/apps/efka/src/efka_service.erl index 4588ab7..55591bd 100644 --- a/apps/efka/src/efka_service.erl +++ b/apps/efka/src/efka_service.erl @@ -126,7 +126,7 @@ init0(#service{service_id = ServiceId, status = 1}, Manifest) -> {ok, #state{service_id = ServiceId, manifest = Manifest, running_status = ?STATUS_STOPPED, port = undefined, os_pid = undefined}} end; init0(#service{service_id = ServiceId, status = 0}, Manifest) -> - lager:debug("[efka_service] service: ~p current status is 0, not boot"), + lager:debug("[efka_service] service: ~p current status is 0, not boot", [ServiceId]), {ok, #state{service_id = ServiceId, manifest = Manifest, running_status = ?STATUS_STOPPED, port = undefined, os_pid = undefined}}. %% @private @@ -169,7 +169,7 @@ handle_call(start_service, _From, State = #state{running_status = ?STATUS_STOPPE case efka_manifest:startup(Manifest) of {ok, Port} -> {os_pid, OSPid} = erlang:port_info(Port, os_pid), - lager:debug("start_service port: ~p, os_pid: ~p", [Port, OSPid]), + lager:debug("[efka_service] service_id: ~p, start_service port: ~p, os_pid: ~p", [ServiceId, Port, OSPid]), %% 更新数据库状态 ok = service_model:change_status(ServiceId, 1), {reply, ok, State#state{running_status = ?STATUS_RUNNING, port = Port, os_pid = OSPid}}; @@ -179,8 +179,8 @@ handle_call(start_service, _From, State = #state{running_status = ?STATUS_STOPPE end; %% 停止服务, 主动停止的时候会改变服务配置的status字段 -handle_call(stop_service, _From, State = #state{running_status = ?STATUS_STOPPED, port = Port, os_pid = OSPid}) -> - lager:debug("stop service port: ~p, os_pid: ~p", [Port, OSPid]), +handle_call(stop_service, _From, State = #state{running_status = ?STATUS_STOPPED, service_id = ServiceId, port = Port, os_pid = OSPid}) -> + lager:debug("[efka_service] service_id: ~p, stop service port: ~p, os_pid: ~p", [ServiceId, Port, OSPid]), {reply, {error, <<"service not running">>}, State}; handle_call(stop_service, _From, State = #state{running_status = ?STATUS_RUNNING, port = Port, os_pid = OSPid, service_id = ServiceId}) when is_port(Port) -> @@ -188,7 +188,7 @@ handle_call(stop_service, _From, State = #state{running_status = ?STATUS_RUNNING kill_os_pid(OSPid), erlang:is_port(Port) andalso erlang:port_close(Port), - lager:debug("port: ~p, os_pid: ~p, will closed", [Port, OSPid]), + lager:debug("[efka_service] service_id: ~p, port: ~p, os_pid: ~p, will closed", [ServiceId, Port, OSPid]), ok = service_model:change_status(ServiceId, 0), {reply, ok, State#state{port = undefined, os_pid = undefined, running_status = ?STATUS_STOPPED}}; @@ -251,10 +251,10 @@ handle_info({timeout, _, reboot_service}, State = #state{service_id = ServiceId, case efka_manifest:startup(Manifest) of {ok, Port} -> {os_pid, OSPid} = erlang:port_info(Port, os_pid), - lager:debug("[efka_service] reboot service success: ~p, port: ~p, os_pid: ~p", [ServiceId, Port, OSPid]), + lager:debug("[efka_service] service_id: ~p, reboot success: ~p, port: ~p, os_pid: ~p", [ServiceId, Port, OSPid]), {noreply, State#state{running_status = ?STATUS_RUNNING, port = Port, os_pid = OSPid}}; {error, Reason} -> - lager:debug("[efka_service] service: ~p, boot_service get error: ~p", [ServiceId, Reason]), + lager:debug("[efka_service] service_id: ~p, boot_service get error: ~p", [ServiceId, Reason]), {noreply, State#state{running_status = ?STATUS_STOPPED}} end end; @@ -281,7 +281,7 @@ handle_info({Port, {exit_status, Code}}, State = #state{service_id = ServiceId}) %% 处理channel进程的退出 handle_info({'DOWN', _Ref, process, ChannelPid, Reason}, State = #state{channel_pid = ChannelPid, service_id = ServiceId}) -> - lager:debug("[efka_service] service: ~p, channel exited: ~p", [ServiceId, Reason]), + lager:debug("[efka_service] service_id: ~p, channel exited: ~p", [ServiceId, Reason]), {noreply, State#state{channel_pid = undefined, inflight = #{}}}. %% @private @@ -291,12 +291,12 @@ 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{os_pid = OSPid}) -> - lager:debug("[efka_service] terminate with reason: ~p", [Reason]), +terminate(Reason, _State = #state{service_id = ServiceId, os_pid = OSPid}) -> + lager:debug("[efka_service] service_id: ~p, terminate with reason: ~p", [ServiceId, Reason]), kill_os_pid(OSPid), ok; -terminate(Reason, _State) -> - lager:debug("[efka_service] terminate with reason: ~p", [Reason]), +terminate(Reason, #state{service_id = ServiceId}) -> + lager:debug("[efka_service] service_id: ~p, terminate with reason: ~p", [ServiceId, Reason]), ok. %% @private