[erlang-questions] Where to configure & start mnesia in a release?

Igor Clark igor.clark@REDACTED
Sun Apr 15 17:50:05 CEST 2018


Thanks Nuku,

- It's definitely crashing due to the mnesia configuration - it shows a 
{badmatch,undefined} error on the line where I call { ok, MnesiaDir } = 
application:get_env( mnesia, dir ), and I've tried io:format()'ing the 
result of application:get_env( mnesia, dir ), which shows 'undefined' 
when running as a release

- relx section of rebar.config is set up exactly like that - I used 
rebar3 to generate the release

- sys.config has exactly that mnesia entry

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 'undefined' from 
application:get_env( mnesia, dir ).

 From your sys.config example I realise I could say for example [ { 
my_app, [ { mnesia_dir, "/tmp/my_db_dir" } ] } ], and use 
application:get_env( my_app, mnesia_dir ) to initialise; this works and 
returns { ok, "/tmp/my_db_dir" }, which is great, but then ok = 
application:ensure_started( mnesia ) fails with {{badmatch, {error,{"no 
such file or directory","mnesia.app"}}}. I have no idea where mnesia.app 
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.

So still pretty unclear how to proceed, pointers welcome!

Thanks,
Igor

On 15/04/2018 16:06, Nuku Ameyibor wrote:
>
>     - under_build/<profile>/rel/<release>/bin/<release> console it
>     fails (returns undefined), so the app crashes on start, regardless
>     of whether <profile> is prod or default
>
> it may or may not be crashing due the mnesia configuration .
> you may have to check the the erl_crash.dump to see the cause of the 
> crash .
>
>
>     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?)
>
> in the relx section of your rebar.config you can set a sys_config to 
> be used
> {relx,
> [
> {sys_config,"config/sys.config"}
>        ]
> in that sys.config you can setup environmental variables to be used by 
> your applications including an entry for mnesia.
> [
> {mnesia,
> [{dir,"/tmp/my_db_dir"}]
> },
> {app1,[{a,1},{b,2}],
> {app2,[{a,3},{b,4}]
> }
> ]
> this will be used by your release system when the release is created .
> check out http://www.rebar3.org/docs/releases .
>
>
>
> On Sat, Apr 14, 2018 at 3:17 PM, Igor Clark <igor.clark@REDACTED 
> <mailto:igor.clark@REDACTED>> wrote:
>
>     Hi list,
>
>     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:
>
>     - 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
>
>     - If I set { mnesia, [ { dir, "/tmp/my_db_dir" } ] } in
>     <release>/config/sys.config, then:
>
>         - under rebar3 shell --name=myapp@REDACTED, calling
>     application:get_env( mnesia, dir ) succeeds (returns
>     /tmp/my_db_dir) , and the app uses reads/writes mnesia tables
>     successfully
>
>         - under_build/<profile>/rel/<release>/bin/<release> console it
>     fails (returns undefined), so the app crashes on start, regardless
>     of whether <profile> is prod or default
>
>     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?)
>
>     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?
>
>     Bit puzzled, appreciate any advice!
>
>     Cheers,
>     Igor
>     _______________________________________________
>     erlang-questions mailing list
>     erlang-questions@REDACTED <mailto:erlang-questions@REDACTED>
>     http://erlang.org/mailman/listinfo/erlang-questions
>     <http://erlang.org/mailman/listinfo/erlang-questions>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180415/c718efbb/attachment.htm>


More information about the erlang-questions mailing list