【问题标题】:Database is not created while release Erlang application发布 Erlang 应用程序时未创建数据库
【发布时间】:2016-05-15 04:56:58
【问题描述】:

我创建了一个 Erlang 应用程序,一个小的 calendar_server。其中插入事件,检索它们并编辑和删除事件。在提示符下运行(使用 erl)时它可以正常工作。我插入了事件(生日、会议等),然后在目录上创建了数据库(Mnesia.nonode@nohost)。并且可以检索事件。但是当使用 rebar/rebar3 创建相同的应用程序时,不会创建数据库。我真的很想知道我遇到了什么问题,或者我犯了什么错误。

reltool.config 和 calendarApp.app.src 如下..

reltool.config

{sys, [
   {lib_dirs, ["../apps"]},
   {erts, [{mod_cond, derived}, {app_file, strip}]},
   {app_file, strip},
   {rel, "calendarApp", "1",
    [
     kernel,
     stdlib,
     sasl,
     mnesia,
     calendarApp
    ]},
   {rel, "start_clean", "",
    [
     kernel,
     stdlib
    ]},
   {boot_rel, "calendarApp"},
   {profile, embedded},
   {incl_cond, exclude},
   {excl_archive_filters, [".*"]}, %% Do not archive built libs
   {excl_sys_filters, ["^bin/.*", "^erts.*/bin/(dialyzer|typer)",
                       "^erts.*/(doc|info|include|lib|man|src)"]},
   {excl_app_filters, ["\.gitignore"]},
   {app, sasl,   [{incl_cond, include}]},
   {app, stdlib, [{incl_cond, include}]},
   {app, kernel, [{incl_cond, include}]},
   {app, mnesia, [{incl_cond, include}]},
   {app, calendarApp, [{incl_cond, include}]}
  ]}.

  {target_dir, "calendarApp"}.

  {overlay, [
          {mkdir, "log/sasl"},
          {copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"},
          {copy, "files/nodetool", "\{\{erts_vsn\}\}/bin/nodetool"},
          {copy, "files/calendarApp", "bin/calendarApp"},
           {copy, "files/calendarApp.cmd", "bin/calendarApp.cmd"},
           {copy, "files/start_erl.cmd", "bin/start_erl.cmd"},
           {copy, "files/install_upgrade.escript",     "bin/install_upgrade.escript"},
           {copy, "files/sys.config", "releases/\{\{rel_vsn\}\}/sys.config"},
           {copy, "files/vm.args", "releases/\{\{rel_vsn\}\}/vm.args"}
      ]}.

calendarApp.app.src

{application, calendarApp,
 [
  {description, ""},
  {vsn, "1"},
  {registered, []},
  {applications, [
              kernel,
              stdlib,
              mnesia
             ]},
  {mod, { calendarApp_app, []}},
  {env, []}
 ]}.

如果有人知道为什么没有创建数据库,请帮我找出我的错误。

【问题讨论】:

    标签: erlang rebar


    【解决方案1】:

    是的,我首先启动了 myApp (dumperl_sync):

    {relx, [{release, { dumperl_sync, "0.1.0" },
         [dumperl_sync,
          sasl,
          mnesia
         ]},
         ...
     }.
    

    然后,在应用程序行为中:

    start(_Application, _Type) ->
        application:set_env(mnesia, dir,"/path/to/Mnesia.node"),
        mnesia:create_schema([node()])
        ...
    end.
    

    然后,在 gen_server 中的 handle_info 行为:

    handle_info(_, State) ->
        mnesia:start(),
        mnesia:create_table(dates,
            [
                {disc_only_copies, [node()]},
                {attributes,record_info(fields, dates)} 
            ]
        )
        ....
     {noreply, State}.
    

    日期是一个记录:

    -record(dates,{}).
    

    一切都应该正确!

    【讨论】:

      【解决方案2】:

      要创建基于光盘的 Mnesia,您可以使用 mnesia:create_schema/1 函数(我认为您在代码中的某处使用了该函数)。此功能需要停止

      在您的reltool.config 中,您在calendarApp 应用程序之前指定了mnesia 应用程序,这可能是您创建基于磁盘的mnesia 模式的地方。表示mnesia在创建schema之前就启动了,所以schema无法创建。

      如果您在reltool.config 文件中更改rel 键下mnesiacalendarApp 的顺序,则一切都应该正确。

      {sys, [
         {lib_dirs, ["../apps"]},
         {erts, [{mod_cond, derived}, {app_file, strip}]},
         {app_file, strip},
         {rel, "calendarApp", "1",
          [
           kernel,
           stdlib,
           sasl,
           calendarApp,
           mnesia
          ]},
          ...
      

      【讨论】:

      • 谢谢,让我试试,很快就会回复你。再次感谢您
      猜你喜欢
      • 2019-09-17
      • 1970-01-01
      • 2014-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-28
      • 2019-09-02
      相关资源
      最近更新 更多