无法从 yaws runmod 启动主管

Can't start supervisor from yaws runmod

我在 yaws.conf 中定义了一个 yaws runmod 为:

runmod = sg_app

该模块包含一个导出函数:

start()->
    io:format("~p start~n", [ sg_sup:start_link() ]).

当我开始偏航时,我看到对 runmod 的调用:

=INFO REPORT==== 29-Oct-2015::16:46:51 === sync call sg_app:start

{ok,<0.61.0>} start

但是主管不存在:

1> whereis(sg_sup).
undefined

如果我手动调用 runmod:start,主管会挂断。

2> sg_app:start(). 
{ok,<0.73.0>} start
ok
3> whereis(sg_sup).
<0.73.0>

我做错了什么?

您的 运行mod 的 start/0 函数正在使用 start_link/0 启动主管,这意味着它正在 linked 到父进程。当该进程终止时,由于 link,它会带走您的 运行mod 进程。 runmod 功能不是为启动监督树而设计的。

您可能会考虑使用 yapp,它允许您的代码 运行 作为与 Yaws 相同的 Erlang 节点中的常规 Erlang 应用程序,并注册为让 Yaws 将请求分派到其中。

另一种选择是使用单独生成的无限进程启动您的应用程序:

start()->
    spawn(fun () ->
                  application:start(my_app, permanent),
                  receive after infinity -> ok end
          end).