<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Got it. Thanks Nuku.<br>
<br>
<div class="moz-cite-prefix">On 15/04/2018 22:39, Nuku Ameyibor
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAOo93=8G9erwDLwZnS_ycFJw5sSnhhXFOOXJq0cMwXzNuxMkwQ@mail.gmail.com">
<div dir="ltr">you are welcome iggor but i think we may be talking
about two different things
<div>the relx section like below</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="white-space:pre"> </span>{release,
{"app_release", "0.3.3"},[app_name,mnesia]},</blockquote>
<div>would be one way to include mnesia and to have libs added
as part of the release and mnesia started when your
application is started . </div>
<div>another way which is what i was talking about would be to
add it in the .app.src file like this</div>
<div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
{applications,[kernel,stdlib,mnesia ]}</blockquote>
<div>you may want mnesia to be started only when specific
applications are started not when the whole release is
started .</div>
</div>
<div><br>
</div>
<div>cheers!!</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Sun, Apr 15, 2018 at 9:01 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:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF"> Thanks very much
Nuku, that's the piece of the puzzle I was missing. I
hadn't understood properly about the release packaging - I
thought that if I added mnesia into the relx config, it
would automatically start the mnesia app too, and I wanted
to do that manually in my app. But after reading your
email I added it into the relx/release section, and as you
said, the mnesia package is now included in the release,
but I can still start it manually, and the console boots
correctly and accesses the mnesia data. <br>
<br>
Thank you!<br>
<br>
Best,<br>
Igor
<div>
<div class="h5"><br>
<br>
<div class="m_4933564755850586988moz-cite-prefix">On
15/04/2018 21:01, Nuku Ameyibor wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr"> mnesia is not included as part of
the release .
<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;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">when
rebar3 shell command is run the path to
mnesia is added automatically to the code
paths .</span></div>
<div>in a release environment however its not
copied over <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">into
the release libs</span> unless specified in
one of your .app.src files.</div>
<div>in your app.src file check to see if mnesia
is one of the applications which has to be
started before the main application is started.</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Sun, Apr 15, 2018 at
3:50 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:0
0 0 .8ex;border-left:1px #ccc
solid;padding-left:1ex">
<div 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
<div>
<div class="m_4933564755850586988h5"><br>
<br>
<div
class="m_4933564755850586988m_1109125637984098877moz-cite-prefix">On
15/04/2018 16:06, Nuku Ameyibor wrote:<br>
</div>
<blockquote type="cite">
<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><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"><wbr>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-wrap"> </span>[</div>
<div><span style="white-space:pre-wrap"> </span>{sys_config,"config/sys.config<wbr>"}</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-wrap"> </span>{mnesia, </div>
<div><span style="white-space:pre-wrap"> </span>[{dir,"/tmp/my_db_dir"}]</div>
<div><span style="white-space:pre-wrap"> </span>},</div>
<div><span style="white-space:pre-wrap"> </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-wrap"> </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-wrap"> </span><br>
</div>
<div><span style="white-space:pre-wrap"> </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"
target="_blank"
moz-do-not-send="true">http://www.rebar3.org/docs<wbr>/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>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</body>
</html>