Erlang:应用程序行为是否陷阱SIGTERM? [英] Erlang: does the application behavior trap SIGTERM?

查看:160
本文介绍了Erlang:应用程序行为是否陷阱SIGTERM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  start(_StartType,_StartArgs) - > 
...
stop(_State) - >
lager:info(停止接收),
erlang:display(停止接收),
确定。

我的应用程序主管看起来像:

  -behaviour(导师)。 

%% API
-export([start_link / 0])。

%% Supervisor回调
-export([init / 1])。

-define(SERVER,?MODULE)。

%% ==================================== ==========================
%% API函数
%% ======== ================================================== ==========

start_link() - >
主管:start_link({local,?SERVER},?MODULE,[])。

%% ==================================== ==========================
%%主管回调
%% ======== ================================================== ==========

%% Child :: {Id,StartFunc,Restart,Shutdown,Type,Modules}
init([]) - >
{ok,{{one_for_all,0,1},[]}}。

我不认为我修改了该文件。事实上,我如何连接到上面的开始 stop 函数有点神秘。我的问题是,当我发送SIGTERM到我正在运行的应用程序时,我没有看到停止的日志记录功能出现。这似乎不好我需要向应用程序模块或主管模块添加一些东西吗?



(我需要处理SIGTERM并执行清理,因为我的应用程序是Dockerized,SIGTERM被发送在Docker上运行的应用程序在 Docker stop 之后,如果应用程序没有捕获到SIGTERM,则在10秒后发送SIGKILL。)

解决方案

您将需要升级到刚刚发布的Erlang 19.3,之前SIGTERM被忽略。从发行说明:


erts:收到的SIGTERM信号到波束将产生一个'停止'消息给init进程并终止Erlang VM很好这相当于调用init:stop / 0。


http://www.erlang.org/news/110


I have the following stop function in my behavior module:

start(_StartType, _StartArgs) ->
    ...
stop(_State) ->
    lager:info("Stop recieved."),
    erlang:display("Stop recieved."),
    ok.

My application supervisor looks like:

-behaviour(supervisor).

%% API
-export([start_link/0]).

%% Supervisor callbacks
-export([init/1]).

-define(SERVER, ?MODULE).

%%====================================================================
%% API functions
%%====================================================================

start_link() ->
    supervisor:start_link({local, ?SERVER}, ?MODULE, []).

%%====================================================================
%% Supervisor callbacks
%%====================================================================

%% Child :: {Id,StartFunc,Restart,Shutdown,Type,Modules}
init([]) ->
    {ok, { {one_for_all, 0, 1}, []} }.

I don't think I ever modified that file. In fact, it is a bit mystical to me how that connects to the start and stop functions above.

My question is, when I send SIGTERM to my running application, I do not see the logging statements in the stop function appear. That seems bad. Do I need to add something to either the application module or the supervisor module?

(I need to handle SIGTERM and do cleanup, because my application is Dockerized and SIGTERM gets sent to applications running inside of Docker on Docker stop, after which it sends SIGKILL after 10 seconds if the application does not catch SIGTERM.)

解决方案

You'll need to upgrade to the just released Erlang 19.3 as before that SIGTERM was ignored. From the release notes:

erts: A received SIGTERM signal to beam will generate a 'stop' message to the init process and terminate the Erlang VM nicely. This is equivalent to calling init:stop/0.

http://www.erlang.org/news/110

这篇关于Erlang:应用程序行为是否陷阱SIGTERM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆