<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Thanks Nuku,<br>
    <br>
    - It's definitely crashing due to the mnesia configuration - it
    shows a <tt>{badmatch,undefined}</tt> error on the line where I
    call <tt>{ ok, MnesiaDir } = application:get_env( mnesia, dir )</tt>,
    and I've tried <tt>io:format()</tt>'ing the result of <tt>application:get_env(
      mnesia, dir )</tt>, which shows '<tt>undefined</tt>' when running
    as a release<br>
    <br>
    - relx section of rebar.config is set up exactly like that - I used
    rebar3 to generate the release<br>
    <br>
    - sys.config has exactly that mnesia entry<br>
    <br>
    It all works as expected with 'rebar3 shell', environment variable
    is found, mnesia starts, it all works fine - but when I run 'rebar3
    release' and try to run the generated startup script, either with
    'console' or with 'start' and looking in the log file, the OTP
    application included in the release gets '<tt>undefined</tt>' from <tt>application:get_env(
      mnesia, dir )</tt>.<br>
    <br>
    From your sys.config example I realise I could say for example <tt>[
      { my_app, [ { mnesia_dir, "/tmp/my_db_dir" } ] } ]</tt>, and use
    application:get_env( my_app, mnesia_dir ) to initialise; this works
    and returns <tt>{ ok, "/tmp/my_db_dir" }</tt>, which is great, but
    then <tt>ok = application:ensure_started( mnesia )</tt> fails with
    <tt>{{badmatch, {error,{"no such file or directory","mnesia.app"}}}</tt>.
    I have no idea where <tt>mnesia.app</tt> should go, and I haven't
    been able to find any references to this file in docs or online that
    explain where it should go or what should be in it, except that it
    exists in the mnesia package under the OTP source tree.<br>
    <br>
    So still pretty unclear how to proceed, pointers welcome!<br>
    <br>
    Thanks,<br>
    Igor<br>
    <br>
    <div class="moz-cite-prefix">On 15/04/2018 16:06, Nuku Ameyibor
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAOo93=9C_+YVpREoecMWrs4HwkDxMRf8EP76mGGiYegwoZC3ag@mail.gmail.com">
      <div dir="ltr">
        <div>
          <div><br>
          </div>
          <blockquote class="gmail_quote"
style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;margin:0px
            0px 0px 0.8ex;border-left:1px solid
            rgb(204,204,204);padding-left:1ex"><span
style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   
              - under_build/<profile>/rel/<rel</span><wbr
style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span
style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">ease>/bin/<release>
              console it fails (returns undefined), so the app crashes
              on start, regardless of whether <profile> is prod or
              default</span></blockquote>
          <span
style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);float:none;display:inline">it
            may or may not be crashing due the mnesia configuration .</span>
          <div
style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">you
            may have to check the the erl_crash.dump to see the cause of
            the crash . </div>
          <div
style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br>
          </div>
          <div
style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br>
          </div>
          <div
style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
              0.8ex;border-left:1px solid
              rgb(204,204,204);padding-left:1ex"><span
style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">How
                do I set mnesia application environment variables in the
                release project? (Or, maybe, how do I get the OTP
                application to be able to access the release project's
                application environment variables?)</span></blockquote>
            <div> </div>
            <div>in the relx section of your rebar.config you can set a
              sys_config to be used</div>
            <div>
              <div>{relx, </div>
              <div><span style="white-space:pre"> </span>[</div>
              <div><span style="white-space:pre">         </span>{sys_config,"config/sys.config"}</div>
            </div>
            <div>       ]</div>
            <div> </div>
            in that sys.config you can setup environmental variables to
            be used by your applications including an entry for mnesia.</div>
          <div
style="text-align:start;text-indent:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">
            <div>[</div>
            <div><span style="white-space:pre">           </span>{mnesia, </div>
            <div><span style="white-space:pre">                   </span>[{dir,"/tmp/my_db_dir"}]</div>
            <div><span style="white-space:pre">           </span>},</div>
            <div><span style="white-space:pre">           </span>{app1,[{a,1},{b,2}],</div>
            <div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;white-space:pre">               </span><span
style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">{app2,[{a,3},{b,4}]</span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;white-space:pre">        </span><br>
            </div>
            <div><span style="white-space:pre">           </span>}</div>
            <div>]</div>
          </div>
          <div
style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">this
            will be used by your release system when the release is
            created .</div>
          <div
style="text-align:start;text-indent:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">check
            out <a href="http://www.rebar3.org/docs/releases"
              moz-do-not-send="true">http://www.rebar3.org/docs/releases</a> .<br>
          </div>
          <div
style="text-align:start;text-indent:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br>
          </div>
          <div
style="text-align:start;text-indent:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br>
          </div>
        </div>
        <div
style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br>
        </div>
        <div> </div>
        <div class="gmail_extra">
          <div class="gmail_quote">On Sat, Apr 14, 2018 at 3:17 PM, Igor
            Clark <span dir="ltr"><<a
                href="mailto:igor.clark@gmail.com" target="_blank"
                moz-do-not-send="true">igor.clark@gmail.com</a>></span>
            wrote:<br>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
              0.8ex;border-left:1px solid
              rgb(204,204,204);padding-left:1ex">Hi list,<br>
              <br>
              I have an OTP application which uses mnesia. It
              checks/ensures the schema and table files exist and then
              calls application:ensure_started( mnesia ) in its
              application:start/2 callback. It works fine when I run the
              application on its own under rebar3 shell, but it doesn't
              work when I try to run it from an OTP release:<br>
              <br>
              - When I run the OTP app under rebar3 shell in its own
              separate directory, with { mnesia, [ { dir,
              "/tmp/my_db_dir" } ] } in priv/sys.config, it works fine
              and application:get_env( mnesia, dir ) returns
              /tmp/my_db_dir as normal/expected<br>
              <br>
              - If I set { mnesia, [ { dir, "/tmp/my_db_dir" } ] } in
              <release>/config/sys.config, then:<br>
              <br>
                  - under rebar3 shell --name=myapp@mynode, calling
              application:get_env( mnesia, dir ) succeeds (returns
              /tmp/my_db_dir) , and the app uses reads/writes mnesia
              tables successfully<br>
              <br>
                  - under_build/<profile>/rel/<rel<wbr>ease>/bin/<release>
              console it fails (returns undefined), so the app crashes
              on start, regardless of whether <profile> is prod or
              default<br>
              <br>
              How do I set mnesia application environment variables in
              the release project? (Or, maybe, how do I get the OTP
              application to be able to access the release project's
              application environment variables?)<br>
              <br>
              Also, I realise I could be going about this the wrong way
              - maybe mnesia should be configured inside the specific
              OTP app, even under a release? Apart from the fact that
              that doesn't seem to work (as I have it set up, anyway),
              I'm aware I should steer clear of "included applications"
              - not least because I want to be able to use the OTP app
              in other projects - so I guess there's a broader question
              of how to configure mnesia in general, in how & when
              to create schema and tables, if it could be used by
              multiple OTP apps in a release?<br>
              <br>
              Bit puzzled, appreciate any advice!<br>
              <br>
              Cheers,<br>
              Igor<br>
              ______________________________<wbr>_________________<br>
              erlang-questions mailing list<br>
              <a href="mailto:erlang-questions@erlang.org"
                target="_blank" moz-do-not-send="true">erlang-questions@erlang.org</a><br>
              <a
                href="http://erlang.org/mailman/listinfo/erlang-questions"
                rel="noreferrer" target="_blank" moz-do-not-send="true">http://erlang.org/mailman/list<wbr>info/erlang-questions</a><br>
            </blockquote>
          </div>
          <br>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>