开发者

How do I start applications by command line as a daemon?

开发者 https://www.devze.com 2023-02-17 12:24 出处:网络
This has been my current routine sudo nohup erl -sname foo -pa ./ebin -run foo_supervisor shell -noshell -noinput &

This has been my current routine

sudo nohup erl -sname foo -pa ./ebin -run foo_supervisor shell -noshell -noinput &

where the shell function looks something like this

shell() ->
    {ok, Pid} = supervisor:start_link({local,?MODULE}, ?MODULE, _Arg = []),
    unlink(Pid).

If I don't unlink from shell it immediately 开发者_如何学Gostops for some reason. Is there a way I can just start my application like I would normally ie application:start(foo). Also what if I want to start sasl too? Also where could I learn more about making a self contained package using rebar?


Preface. About your unlink

In this other SO thread @filippo explains why you need the unlink when testing supervisors from the shell.

First. What you need is an Erlang application.

Reading from the doc:

In OTP, application denotes a component implementing some specific functionality, that can be started and stopped as a unit, and which can be re-used in other systems as well.

Details on how to implement an Erlang application are available here. The three main things you will need to do are:

  • Have a proper directory structure for your application
  • Write an application callback module implementing the Erlang application behaviour. That's where you will start your root supervisor
  • Provide an application resource file. This is where you tell the system - among other things - where to find your application callback module (look at the mod parameter).

Second. Starting SASL.

In the above application resource file, you can specify a list of applications you want to start before your application. You will add something like:

...
{applications, [kernel, stdlib, sasl]},
...

To tell it to start SASL.

Third. Rebar.

There's an introduction to Rebar here, which explains you how to use Rebar to help you in the above steps, to pack your brand new application into an Erlang release and how to start it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号