7

How do I specify a working directory for mnesia without resorting to passing the "dir" parameter on the command-line?

In other words, can I specify a "working directory" for mnesia just before calling `mnesia:start()' ?

jldupont
  • 93,734
  • 56
  • 203
  • 318

2 Answers2

14

application:set_env(mnesia, dir, Dir).

Zed
  • 57,028
  • 9
  • 76
  • 100
  • 2
    There is an application_controller process started in Erlang VM. `application_controller:set_env` is the "API" to this process. `application:set_env` is a more abstract call, that just deals with applications. No wonder though that currently it only calls into that API. – Zed Dec 03 '09 at 20:14
  • 1
    To answer the question :), I believe that the existence of application_controller server and module should be regarded as "implementation detail", and thus the proper way is to use the application module. – Zed Dec 03 '09 at 20:20
3

Besides the method call mentioned in other responses here you can also specify this in a system configuration file or .app file specified with the -config parameter. See http://erlang.org/doc/design_principles/applications.html#id2270704 for more information. This allows you keep the configuration seperate from the code and avoid a lot of command line flags.

Jeremy Wall
  • 23,907
  • 5
  • 55
  • 73
  • I have a similar situation ... and I don't want to set mnesia dir from inside the code ... Can you please elaborate how .app file of an application should be used to set env variable for other application. I understand how this can be done using .config file though. e.g. My application file is test.app and it had mnesia listed in "applications" section, so mnesia is started automatically when I start "test". How can I pass "dir" value to mnesia using test.app? – spkhaira Sep 27 '10 at 18:47
  • the relevant documentation for that is here: http://www.erlang.org/doc/man/app.html specifically the env tuple in the application file spec. anything you can set with set_env() can also be set there or on the commandline. – Jeremy Wall Oct 08 '10 at 04:20