Reputation: 59
I created a Erlang application, a small calendar_server. Which insert events, retrieve them and also edit and delete the events. It works correctly when run on the prompt(using erl). I inserted events(birthdays, meetings etc), then the database(Mnesia.nonode@nohost) is created on the directory. And it possible to retrieve the events. But when created the same application using rebar/rebar3, no database is created. I really like to know what the problem i have faced, or what mistake i did.
The reltool.config and calendarApp.app.src are given below..
reltool.config
{sys, [
{lib_dirs, ["../apps"]},
{erts, [{mod_cond, derived}, {app_file, strip}]},
{app_file, strip},
{rel, "calendarApp", "1",
[
kernel,
stdlib,
sasl,
mnesia,
calendarApp
]},
{rel, "start_clean", "",
[
kernel,
stdlib
]},
{boot_rel, "calendarApp"},
{profile, embedded},
{incl_cond, exclude},
{excl_archive_filters, [".*"]}, %% Do not archive built libs
{excl_sys_filters, ["^bin/.*", "^erts.*/bin/(dialyzer|typer)",
"^erts.*/(doc|info|include|lib|man|src)"]},
{excl_app_filters, ["\.gitignore"]},
{app, sasl, [{incl_cond, include}]},
{app, stdlib, [{incl_cond, include}]},
{app, kernel, [{incl_cond, include}]},
{app, mnesia, [{incl_cond, include}]},
{app, calendarApp, [{incl_cond, include}]}
]}.
{target_dir, "calendarApp"}.
{overlay, [
{mkdir, "log/sasl"},
{copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"},
{copy, "files/nodetool", "\{\{erts_vsn\}\}/bin/nodetool"},
{copy, "files/calendarApp", "bin/calendarApp"},
{copy, "files/calendarApp.cmd", "bin/calendarApp.cmd"},
{copy, "files/start_erl.cmd", "bin/start_erl.cmd"},
{copy, "files/install_upgrade.escript", "bin/install_upgrade.escript"},
{copy, "files/sys.config", "releases/\{\{rel_vsn\}\}/sys.config"},
{copy, "files/vm.args", "releases/\{\{rel_vsn\}\}/vm.args"}
]}.
calendarApp.app.src
{application, calendarApp,
[
{description, ""},
{vsn, "1"},
{registered, []},
{applications, [
kernel,
stdlib,
mnesia
]},
{mod, { calendarApp_app, []}},
{env, []}
]}.
If anyone know why the database is not created, please help me to find my mistake.
Upvotes: 1
Views: 264
Reputation: 1
Yes, I started myApp (dumperl_sync) first:
{relx, [{release, { dumperl_sync, "0.1.0" },
[dumperl_sync,
sasl,
mnesia
]},
...
}.
Then, in application behaviour:
start(_Application, _Type) ->
application:set_env(mnesia, dir,"/path/to/Mnesia.node"),
mnesia:create_schema([node()])
...
end.
Then, in gen_server behaviour inside handle_info:
handle_info(_, State) ->
mnesia:start(),
mnesia:create_table(dates,
[
{disc_only_copies, [node()]},
{attributes,record_info(fields, dates)}
]
)
....
{noreply, State}.
dates is a record:
-record(dates,{}).
Everything should be correct!
Upvotes: 0
Reputation: 2554
For creating disc-based Mnesia you can use mnesia:create_schema/1
function (which I think you did somewhere in your code). This function requires Mnesia to be stopped.
In your reltool.config
you specified mnesia
application before calendarApp
application which is where you probably created mnesia disc-based schema. It means that mnesia was started before creating its schema, so the schema cannot be created.
If you change the order of mnesia
and calendarApp
under the key of rel
in your reltool.config
file, everything should be correct.
{sys, [
{lib_dirs, ["../apps"]},
{erts, [{mod_cond, derived}, {app_file, strip}]},
{app_file, strip},
{rel, "calendarApp", "1",
[
kernel,
stdlib,
sasl,
calendarApp,
mnesia
]},
...
Upvotes: 1