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

Igor Clark igor.clark@REDACTED
Sat Apr 14 17:17:09 CEST 2018


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



More information about the erlang-questions mailing list