【问题标题】:What is the "application configuration file" in a rebar3 app?rebar3 应用程序中的“应用程序配置文件”是什么?
【发布时间】:2020-06-20 23:06:27
【问题描述】:

inets httpd server docs 说,

以下是要放到Erlang节点应用 配置文件 在应用程序启动时启动 HTTP 服务器:

  [{inets, [{services, [{httpd, [{proplist_file,
         "/var/tmp/server_root/conf/8888_props.conf"}]},
        {httpd, [{proplist_file,
         "/var/tmp/server_root/conf/8080_props.conf"}]}]}]}].

在由 rebar3 创建的应用程序中,它在哪里?

OTP Application docs 说,

7.8 配置应用程序

可以使用配置参数来配置应用程序。这些 是由 .app 中的键 env 指定的 {Par,Val} 元组列表 文件:

{application, ch_app,
 [{description, "Channel allocator"},
  {vsn, "1"},
  {modules, [ch_app, ch_sup, ch3]},
  {registered, [ch3]},
  {applications, [kernel, stdlib, sasl]},
  {mod, {ch_app,[]}},
  {env, [{file, "/usr/local/log"}]}
 ]}.

Par 是一个原子。 Val 是任何术语。

这似乎建议您使用{Name, Value} 元组创建环境变量。但是,httpd 服务器文档中指定的所需代码似乎不是那种格式。

【问题讨论】:

标签: erlang


【解决方案1】:

只需将其放入您发布的 config 文件夹中的 sys.config 文件中。如果您已经有任何东西,它将采用以下格式:

[
 {some_app, [{env_var, value},{...}]},
 {another_app, [{env_var, value},{...}]},
 % add here without outer[]...,
 {kernel,
  [{distributed, [{app_name, 5000,
  ['node@10.0.211.153', 'node_failover@10.8.222.15']}]}, 
  {sync_nodes_mandatory, []},
  {sync_nodes_optional, ['node_failover@10.8.222.15']},
  {sync_nodes_timeout, 5000}]}
]

【讨论】:

  • 应用程序的 config 文件夹中的 sys.config 文件 -- rebar3 没有为我创建配置目录,我也没有看到任何地方提到的配置目录“第 9 章:应用程序”在“使用 Erlang/OTP 进行可扩展性设计(Cesarini,Vinoski)”一书中。我尝试创建一个配置目录和一个 sys.config 文件,但是当我执行 $ rebar3 shell 然后尝试向 inets httpd 服务器发送请求时,我收到“连接被拒绝”错误。
  • rebar3 仅在您使用 rebar3 新版本 release_name 时创建文件夹。如果你使用 rebar3 new app app_name 它不会生成配置文件夹和文件。
  • 或者,您可以将其直接放在应用程序配置文件中,通常在 src 文件夹 your_app.app.src 中。添加 {env, [{Key, Val}]} 见 learnyousomeerlang.com/building-otp-applications .
  • 当你使用 application:get_env(AppName, Key)。它将从两个文件中获取它们,因此 rebar3 可能会将其写入同一个位置。
猜你喜欢
  • 1970-01-01
  • 2011-06-06
  • 1970-01-01
  • 2011-03-22
  • 1970-01-01
  • 2010-10-31
  • 2012-01-24
  • 2016-08-23
相关资源
最近更新 更多