fix
This commit is contained in:
parent
c6e1056f44
commit
040198e8d5
@ -13,7 +13,7 @@
|
|||||||
service_id :: binary(),
|
service_id :: binary(),
|
||||||
tar_url :: binary(),
|
tar_url :: binary(),
|
||||||
%% 工作目录
|
%% 工作目录
|
||||||
root_dir :: binary(),
|
root_dir :: string(),
|
||||||
params :: binary(),
|
params :: binary(),
|
||||||
metrics :: binary(),
|
metrics :: binary(),
|
||||||
%% 状态: 0: 停止, 1: 运行中
|
%% 状态: 0: 停止, 1: 运行中
|
||||||
|
|||||||
@ -71,6 +71,12 @@ init([]) ->
|
|||||||
handle_call({deploy, TaskId, ServiceId, TarUrl}, _From, State = #state{root_dir = RootDir, task_map = TaskMap}) ->
|
handle_call({deploy, TaskId, ServiceId, TarUrl}, _From, State = #state{root_dir = RootDir, task_map = TaskMap}) ->
|
||||||
%% 创建目录
|
%% 创建目录
|
||||||
{ok, ServiceRootDir} = ensure_dirs(RootDir, ServiceId),
|
{ok, ServiceRootDir} = ensure_dirs(RootDir, ServiceId),
|
||||||
|
|
||||||
|
ServicePid = efka_service:get_pid(ServiceId),
|
||||||
|
case is_pid(ServicePid) andalso efka_service:is_running(ServicePid) of
|
||||||
|
true ->
|
||||||
|
{reply, {error, <<"the service is running, stop first">>}, State};
|
||||||
|
false ->
|
||||||
case check_download_url(TarUrl) of
|
case check_download_url(TarUrl) of
|
||||||
ok ->
|
ok ->
|
||||||
{ok, TaskPid} = efka_inetd_task:start_link(TaskId, ServiceRootDir, ServiceId, TarUrl),
|
{ok, TaskPid} = efka_inetd_task:start_link(TaskId, ServiceRootDir, ServiceId, TarUrl),
|
||||||
@ -81,6 +87,7 @@ handle_call({deploy, TaskId, ServiceId, TarUrl}, _From, State = #state{root_dir
|
|||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
lager:debug("[efka_inetd] check_download_url: ~p, get error: ~p", [TarUrl, Reason]),
|
lager:debug("[efka_inetd] check_download_url: ~p, get error: ~p", [TarUrl, Reason]),
|
||||||
{reply, {error, <<"download url error">>}, State}
|
{reply, {error, <<"download url error">>}, State}
|
||||||
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
handle_call(_Request, _From, State = #state{}) ->
|
handle_call(_Request, _From, State = #state{}) ->
|
||||||
|
|||||||
@ -24,9 +24,8 @@
|
|||||||
%% API
|
%% API
|
||||||
-export([new/1, startup/1]).
|
-export([new/1, startup/1]).
|
||||||
|
|
||||||
-spec new(WorkDir0 :: binary()) -> {ok, #manifest{}} | {error, Reason :: binary()}.
|
-spec new(WorkDir :: string()) -> {ok, #manifest{}} | {error, Reason :: binary()}.
|
||||||
new(WorkDir0) when is_binary(WorkDir0) ->
|
new(WorkDir) when is_list(WorkDir) ->
|
||||||
WorkDir = binary_to_list(WorkDir0),
|
|
||||||
case file:read_file(WorkDir ++ "manifest.json") of
|
case file:read_file(WorkDir ++ "manifest.json") of
|
||||||
{ok, ManifestInfo} ->
|
{ok, ManifestInfo} ->
|
||||||
Settings = catch jiffy:decode(ManifestInfo, [return_maps]),
|
Settings = catch jiffy:decode(ManifestInfo, [return_maps]),
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
%% API
|
%% API
|
||||||
-export([start_link/2]).
|
-export([start_link/2]).
|
||||||
-export([get_name/1, get_pid/1, start_service/1, stop_service/1, attach_channel/2]).
|
-export([get_name/1, get_pid/1, start_service/1, stop_service/1, attach_channel/2]).
|
||||||
-export([push_config/3, request_config/1, invoke/3]).
|
-export([push_config/3, request_config/1, invoke/3, is_running/1]).
|
||||||
-export([metric_data/3, send_event/3]).
|
-export([metric_data/3, send_event/3]).
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
@ -59,6 +59,10 @@ push_config(Pid, Ref, ConfigJson) when is_pid(Pid), is_binary(ConfigJson) ->
|
|||||||
invoke(Pid, Ref, Payload) when is_pid(Pid), is_reference(Ref), is_binary(Payload) ->
|
invoke(Pid, Ref, Payload) when is_pid(Pid), is_reference(Ref), is_binary(Payload) ->
|
||||||
gen_server:cast(Pid, {invoke, Ref, self(), Payload}).
|
gen_server:cast(Pid, {invoke, Ref, self(), Payload}).
|
||||||
|
|
||||||
|
-spec is_running(Pid :: pid()) -> boolean().
|
||||||
|
is_running(Pid) when is_pid(Pid) ->
|
||||||
|
gen_server:call(Pid, is_running).
|
||||||
|
|
||||||
request_config(Pid) when is_pid(Pid) ->
|
request_config(Pid) when is_pid(Pid) ->
|
||||||
gen_server:call(Pid, request_config).
|
gen_server:call(Pid, request_config).
|
||||||
|
|
||||||
@ -148,6 +152,10 @@ handle_call({attach_channel, ChannelPid}, _From, State = #state{channel_pid = Ol
|
|||||||
{reply, {error, <<"serivce stopped">>}, State}
|
{reply, {error, <<"serivce stopped">>}, State}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
%% 获取服务的运行状态
|
||||||
|
handle_call(is_running, _From, State = #state{running_status = RunningStatus}) ->
|
||||||
|
{reply, RunningStatus, State};
|
||||||
|
|
||||||
%% 请求参数项 done
|
%% 请求参数项 done
|
||||||
handle_call(request_config, _From, State = #state{service_id = ServiceId, running_status = ?STATUS_RUNNING}) ->
|
handle_call(request_config, _From, State = #state{service_id = ServiceId, running_status = ?STATUS_RUNNING}) ->
|
||||||
Params = service_model:get_params(ServiceId),
|
Params = service_model:get_params(ServiceId),
|
||||||
|
|||||||
@ -46,18 +46,6 @@ start_link() ->
|
|||||||
| ignore | {error, Reason :: term()}).
|
| ignore | {error, Reason :: term()}).
|
||||||
init([]) ->
|
init([]) ->
|
||||||
SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600},
|
SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600},
|
||||||
|
|
||||||
service_model:insert(#service{
|
|
||||||
service_id = <<"test1234">>,
|
|
||||||
tar_url = <<"http://118.178.229.213:3000/anlicheng/ekfa/archive1/main.tar.gz">>,
|
|
||||||
%% 工作目录
|
|
||||||
root_dir = <<"/usr/local/code/tmp/test/">>,
|
|
||||||
params = <<"">>,
|
|
||||||
metrics = <<"">>,
|
|
||||||
%% 状态: 0: 停止, 1: 运行中
|
|
||||||
status = 1
|
|
||||||
}),
|
|
||||||
|
|
||||||
MicroServiceIds = service_model:get_all_service_ids(),
|
MicroServiceIds = service_model:get_all_service_ids(),
|
||||||
Specs = lists:map(fun(ServiceId) -> child_spec(ServiceId) end, MicroServiceIds),
|
Specs = lists:map(fun(ServiceId) -> child_spec(ServiceId) end, MicroServiceIds),
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[
|
[
|
||||||
{efka, [
|
{efka, [
|
||||||
{root_dir, "/usr/local/code/efka/"},
|
{root_dir, "/usr/local/code/efka"},
|
||||||
|
|
||||||
{tcp_server, [
|
{tcp_server, [
|
||||||
{port, 18088}
|
{port, 18088}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user