【问题标题】:Erlang: how can I automatically start all necessary applications to app?Erlang:如何自动启动所有必要的应用程序到应用程序?
【发布时间】:2011-09-15 06:49:29
【问题描述】:

我在 st_db.app 文件中有必要的应用程序,如下所示:

{application, st_db,
 [
  {description, ""},
  {vsn, "1.0.0"},
  {registered, []},
  {modules, [st_db_app, st_db_sup, st_db]},
  {applications, [
                  kernel,
                  stdlib,
          sasl,
          crypto,
          ibrowse,
          couchbeam
                 ]},
  {mod, { st_db_app, []}},
  {env, []}
 ]}.

我需要自动启动它们(加密、sasl 等)以运行和调试主应用程序。 我发现的唯一解决方案是使用这样的参数启动 erl:

erl -pa ./ebin -pa ./deps/*/ebin -boot start_sasl -s couchbeam -s crypto -s ibrowse 

这是唯一的方法吗?

PS:顺便说一句,couchbeam 不会在节点上启动。它只是启动了 couchbeam 的主管,所以我必须手动在 shell 中运行它

=PROGRESS REPORT==== 15-Jun-2011::10:22:43 ===
          supervisor: {local,couchbeam_sup}
             started: [{pid,<0.62.0>},
                       {name,couchbeam},
                       {mfargs,{couchbeam,start_link,[]}},
                       {restart_type,permanent},
                       {shutdown,2000},
                       {child_type,worker}]

2> application:start(couchbeam).
ok
3> 
=PROGRESS REPORT==== 15-Jun-2011::10:23:25 ===
          supervisor: {local,couchbeam_sup}
             started: [{pid,<0.69.0>},
                       {name,couchbeam},
                       {mfargs,{couchbeam,start_link,[]}},
                       {restart_type,permanent},
                       {shutdown,2000},
                       {child_type,worker}]

=PROGRESS REPORT==== 15-Jun-2011::10:23:25 ===
         application: couchbeam
          started_at: nonode@nohost

有办法解决吗?

【问题讨论】:

    标签: erlang


    【解决方案1】:

    您可以向erl 发出一系列-eval "application:start(coucnbeam)" 命令,或者以正确的OTP 方式执行并使用reltool 为您生成新的启动文件。

    请参阅 reltool 上的 info,rebar 在为您完成大部分繁重工作方面做得非常出色,因此您可能需要查看 rebar3

    还有来自 LYSE 的 great chapter 正在发布版本。

    【讨论】:

      【解决方案2】:

      如果您只是在控制台中乱搞,并且不想输入所有这些“应用程序:启动(...)”。行,只需将这些内容放在当前工作目录的 .erlang 文件中即可。这是我现在正在做的一个例子:

      $ cat .erlang 
      application:start(crypto).
      application:start(public_key).
      application:start(ssl).
      application:start(ibrowse).
      application:start(foo).
      

      这会启动我所有的依赖项,然后是我现在正在开发的应用程序,foo。


      如果您想使用 rebar 生成 reltool 版本,此链接可能会有所帮助:

      When to use erlang application:start or included_applications and a supervisor?

      具体来说,这个要点:

      https://gist.github.com/3728780

      -托德

      【讨论】:

        【解决方案3】:

        有一种方法可以启动所有相关的应用程序。 请通过 application:ensure_all_started API http://erlang.org/doc/apps/kernel/application.html#ensure_all_started-1

        【讨论】:

          【解决方案4】:

          在你的应用回调模块中,只需写:

          -module(st_db_app).
          -behaviour(application).
          -export([start/2, stop/1]).
          
          start(_StartType, _StartArg) ->
              %% Get application name
              {ok, AppName} = application:get_application(),
              %% Start all dependencies that are not yet started for application name
              {ok, _StartedApps} = application:ensure_all_started(AppName),
              %% start application's root supervisor or do other initialization here
              %% and return root supervisor's pid.
          

          【讨论】:

            猜你喜欢
            • 2011-03-04
            • 1970-01-01
            • 1970-01-01
            • 2012-10-11
            • 2012-11-10
            • 1970-01-01
            • 2011-12-04
            • 1970-01-01
            相关资源
            最近更新 更多