如何通过命令行启动应用程序作为守护进程? [英] How do I start applications by command line as a daemon?

查看:399
本文介绍了如何通过命令行启动应用程序作为守护进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我目前的例程

  sudo nohup erl -sname foo -pa ./ebin -run foo_supervisor shell -noshell - 无输入

其中shell函数看起来像这样

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

如果我不从shell取消链接,因为某些原因立即停止。有没有办法,我可以像我一般正在开始我的应用程序,即应用程序:start(foo)。另外如果我也想开始sasl呢?还可以在哪里可以了解更多关于使用钢筋制作自包装包?

解决方案

序言。关于您的取消链接



此处其他SO线程 @filippo解释了为什么在从shell中测试主管时需要 unlink



首先。您需要的是 Erlang应用程序



从文档读取:


在OTP中,应用程序表示实现一个
组件一些具体的
功能,可以启动,
作为一个单元停止,并且可以在其他系统中重新使用




有关如何实现Erlang应用程序的详细信息可用此处。您需要做的三件事是:





  • 编写应用程序回调模块实现Erlang应用程序行为。那就是你要开始你的根管理员。

  • 提供应用程序资源文件。这是你告诉系统的地方 - 其中包括哪里可以找到您的应用程序回调模块(看看 mod 参数)。



    • 第二。启动SASL。



      在上述应用程序资源文件中,您可以指定要在应用程序之前启动的应用程序列表。您将添加如下内容:

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

      告诉它启动SASL。



      第三。 Rebar。



      有一个Rebar简介这里,其中说明了如何使用Rebar来帮助您执行上述步骤,将您的全新应用程序打包成一个 Erlang release 以及如何启动。


      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?

      解决方案

      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:

      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.

      这篇关于如何通过命令行启动应用程序作为守护进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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