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

Igor Clark igor.clark@REDACTED
Tue Apr 17 00:30:44 CEST 2018


Got it. Thanks Nuku.

On 15/04/2018 22:39, Nuku Ameyibor wrote:
> you are welcome iggor but i think we may be talking about two 
> different things
> the relx section like below
>
>     {release, {"app_release", "0.3.3"},[app_name,mnesia]},
>
> 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 .
> another way which is  what i was talking about would be to add it in 
> the .app.src file like this
>
>     {applications,[kernel,stdlib,mnesia ]}
>
> you may want mnesia to be started only when specific applications are 
> started not when the whole release is started .
>
> cheers!!
>
>
> On Sun, Apr 15, 2018 at 9:01 PM, Igor Clark <igor.clark@REDACTED 
> <mailto:igor.clark@REDACTED>> wrote:
>
>     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.
>
>     Thank you!
>
>     Best,
>     Igor
>
>
>     On 15/04/2018 21:01, Nuku Ameyibor wrote:
>>      mnesia is not  included as part of the release .
>>     when rebar3 shell command is run  the path to mnesia is added
>>     automatically to the code paths .
>>     in  a release environment however its not copied  over into the
>>     release libs unless specified in one of your .app.src files.
>>     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.
>>
>>
>>     On Sun, Apr 15, 2018 at 3:50 PM, Igor Clark <igor.clark@REDACTED
>>     <mailto:igor.clark@REDACTED>> wrote:
>>
>>         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
>>>         <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/20180416/4e35ac2e/attachment.htm>


More information about the erlang-questions mailing list