Search code examples
erlangyaws

Can't start supervisor from yaws runmod


I have a yaws runmod defined in yaws.conf as:

runmod = sg_app

the module contains an exported function:

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

When I start yaws I see a call to the runmod:

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

{ok,<0.61.0>} start

But the supervisor is nonexistent:

1> whereis(sg_sup).
undefined

If I call the runmod:start manually, the supervisor hangs around.

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

What have I done wrong?


Solution

  • Your runmod's start/0 function is starting the supervisor with start_link/0, which means it's getting linked to the parent process. When that process dies, it takes your runmod process down with it, due to the link. The runmod feature isn't designed for starting a supervision tree.

    You might instead consider using a yapp, which allows your code to run as a regular Erlang application in the same Erlang node as Yaws and be registered to have Yaws dispatch requests into it.