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

元气小坏坏 提交于 2019-12-06 13:32:11

问题


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 stops 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?


回答1:


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.



来源:https://stackoverflow.com/questions/5332778/how-do-i-start-applications-by-command-line-as-a-daemon

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!