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

Nuku Ameyibor nayibor@REDACTED
Sun Apr 15 17:06:30 CEST 2018


>     - 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> 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
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180415/05485fe4/attachment.htm>


More information about the erlang-questions mailing list