Database is not created while release Erlang application - erlang

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.

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
]},
...

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!

Related

Including start_sasl.boot when creating a release with rebar3

When I create a release with rebar3 (rebar3 release or rebar3 tar) and that I include ERTS, the start_sasl.boot script is missing and prevents me from starting my application.
# ./erts-8.2.1/bin/erl -boot start_sasl [...]
{"init terminating in do_boot",{'cannot get bootfile','start_sasl.boot'}}
init terminating in do_boot ()
My current rebar.config section for releases:
{relx, [
{release, {my_app, "1.0.0"}, [my_app]},
{dev_mode, false},
{include_erts, true},
{extended_start_script, false},
{generate_start_script, false},
{overlay, [
{copy, "priv/scripts/nodetool", "bin"},
{copy, "priv/scripts/run", "bin"}
]}
]}.
Is there a setting that I'm missing that to include start_sasl.boot in the release directory?

rebar generate "Module application_starter potentially included by two different applications: kernel and xxx."}},

I have a application which use "included_applications"
It works fine, but if I use rebar(2.6) to generate release, It shows error message
"Module application_starter potentially included by two different applications: kernel and xxx.",
Can anyone tell me how to do, Thank you
below is main application
{application, top,
[{description, ""},
{vsn, "1"},
{modules, []},
{registered, []},
{included_applications, [bsc]},
{start_phases, [{init,[]}, {go,[]}]},
{applications, [kernel, stdlib, sasl]},
{mod, {application_starter,[top_app,[]]}}
]}.
below is included application
{application, bsc,
[{description, ""},
{vsn, "1"},
{modules, []},
{registered, []},
{start_phases, [{go,[]}]},
{applications, [kernel, stdlib, sasl]},
{mod, {bsc_app,[]}}
]}.

Mongooseim with rabbitMQ: mochijson2 potentially included by two different applications

I am trying to build mongooseim with rabbitMQ. Im getting the below error while doing make rel.
==> rel (generate)
ERROR: generate failed while processing /home/mongoose/MongooseIM/rel: {'EXIT',{{badmatch,{error,"Module mochijson2 potentially included by two different applications: mochijson2 and rabbit_common."}},
[{rebar_reltool,generate,2,[]},
{rebar_core,run_modules,4,[]},
{rebar_core,execute,5,[]},
{rebar_core,process_dir1,6,[]},
{rebar_core,process_each,5,[]},
{rebar_core,process_dir1,6,[]},
{rebar_core,process_commands,2,[]},
{rebar,main,1,[]}]}}
make: *** [rel] Error 1
What should be the best way to fix this? I didnt get much info from google. My rebar configuration file is as below:
{ok, Path} = file:get_cwd(),
ConfigureOut = Path ++ "/../configure.out",
Conf = case file:consult(ConfigureOut) of
{ok, Terms} -> Terms;
E -> io:format("WARN: error ~p reading file: ~p - using default rel config~n", [E, ConfigureOut]), []
end,
BaseAppsToRun = [compiler,
lager,
kernel,
mnesia,
sasl,
ssl,
stdlib,
ejabberd,
inets,
syntax_tools,
p1_stringprep,
exml,
cowboy,
fusco,
folsom,
exometer,
xmerl,
amqp_client,
rabbit_common],
AppsToRunIn = BaseAppsToRun ++ proplists:get_value(apps_to_run, Conf, []),
AppsToRun = ordsets:to_list(ordsets:from_list(AppsToRunIn)),
BaseAppsToInclude = AppsToRun ++
[asn1,
crypto,
public_key,
goldrush,
runtime_tools,
p1_utils,
ranch,
cowlib,
bear,
mochijson2,
p1_cache_tab,
pa,
base16,
cuesport,
alarms,
idna,
recon,
setup,
xmerl,
amqp_client,
rabbit_common],
RemovedApps = [mysql,pgsql,redo,seestar,odbc],
AppsToIncludeIn = BaseAppsToInclude ++ proplists:get_value(apps_to_include, Conf, []),
AppsToInclude = ordsets:to_list(ordsets:from_list(AppsToIncludeIn)),
IncludeApps = lists:map(fun(App) -> {app, App, [{incl_cond, include}]} end, AppsToInclude),
[{sys, [
{lib_dirs, ["../apps", "../deps"]},
{incl_cond, exclude},
{rel, "mongooseim", "", [mongoose | AppsToRun]},
{rel, "start_clean", "", [kernel,stdlib]},
{boot_rel, "mongooseim"},
{profile, embedded},
{excl_archive_filters, [".*"]}, % do no archive built libs
{excl_sys_filters, ["^bin/.*",
"^erts.*/bin/(dialyzer|typer)"]},
{app, mongoose, [{incl_cond, include}, {lib_dir, ".."}]}
] ++ IncludeApps},
{target_dir, "mongooseim"},
{overlay_vars, "vars.config"},
{overlay, [{mkdir, "log/sasl"},
{copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"},
{copy, "files/nodetool", "\{\{erts_vsn\}\}/bin/nodetool"},
{copy, "files/mongooseim", "bin/mongooseim"},
{copy, "files/mongooseimctl", "bin/mongooseimctl"},
{copy, "files/app.config", "etc/app.config"},
{template, "files/vm.args", "etc/vm.args"},
{template, "files/ejabberd.cfg", "etc/ejabberd.cfg"},
{mkdir, "var"},
{mkdir, "var/log"}
]}
].
I have faced the same problem before. There are several ways to solve the problem.
use older version of rabbitmq common. common's 2.8.2 version doesn't contain mochijson2 module.
In the "reltool.config" file, try to exclude mochijson2 for rabbitmq common or from mochiweb. ( it need to read carefully release-related documents).

rabbitmq-erlang-client, using rebar friendly pkg, works on dev env fails on rebar release

I am successfully using the rebar-friendly package of rabbitmq-erlang-client for a simple Hello World rebarized and OTP "compliant" app and things work fine on the dev environment. I am able to fire up an erl console and do my application:start(helloworld). and connect to the broker, open up a channel and communicate to queues.
However, then I proceed to do rebar generate and it builds up the release just fine, but when I try to fire up from the self contained release package then things suddenly explode.
I know rebar releases are known to be an obscure art, but I would like to know what are my options as far as deployment for an app using the rabbitmq-erlang-client.
Below you will find the output of the console on the crash:
=INFO REPORT==== 18-Dec-2012::16:41:35 ===
application: session_record
exited: {{{badmatch,
{error,
{'EXIT',
{undef,
[{amqp_connection_sup,start_link,
[{amqp_params_network,<<"guest">>,<<"guest">>,<<"/">>,
"127.0.0.1",5672,0,0,0,infinity,none,
[#Fun<amqp_auth_mechanisms.plain.3>,
#Fun<amqp_auth_mechanisms.amqplain.3>],
[],[]}],
[]},
{supervisor2,do_start_child_i,3,
[{file,"src/supervisor2.erl"},{line,391}]},
{supervisor2,handle_call,3,
[{file,"src/supervisor2.erl"},{line,413}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,588}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}}}},
[{amqp_connection,start,1,
[{file,"src/amqp_connection.erl"},{line,164}]},
{hello_qp,start_link,0,[{file,"src/hello_qp.erl"},{line,10}]},
{session_record_sup,init,1,
[{file,"src/session_record_sup.erl"},{line,55}]},
{supervisor_bridge,init,1,
[{file,"supervisor_bridge.erl"},{line,79}]},
{gen_server,init_it,6,[{file,"gen_server.erl"},{line,304}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]},
{session_record_app,start,[normal,[]]}}
type: permanent {"Kernel pid terminated",application_controller
EDIT: As requested in the comments.
reltool.config
{sys, [
{lib_dirs, ["..", "../deps"]},
{erts, [{mod_cond, derived}, {app_file, strip}]},
{app_file, strip},
{rel, "session_record", "0.1.0",
[
kernel,
stdlib,
sasl,
session_record
]},
{rel, "start_clean", "",
[
kernel,
stdlib
]},
{boot_rel, "session_record"},
{profile, embedded},
{incl_cond, derived},
{mod_cond, derived},
{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, session_record, [{mod_cond, app}, {incl_cond, include}, {lib_dir, ".."}]},
{app, hipe, [{incl_cond, exclude}]}
]}.
{target_dir, "session_record"}.
{overlay, [
{mkdir, "log/sasl"},
{copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"},
{copy, "files/nodetool", "\{\{erts_vsn\}\}/bin/nodetool"},
{copy, "files/session_record", "bin/session_record"},
{copy, "files/session_record.cmd", "bin/session_record.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"}
]}.
Try changing {mod_cond, derived} to {mod_cond, all}. That means that reltool will not try to be clever about which modules to take from the included applications. I suspect that your problem is that reltool didn't consider amqp_connection_sup to be necessary; you could confirm that by checking whether it's present in lib/amqp_client-0.8/ebin.
Answer given by #legoscia worked.
Here is sample, reltool.config
%% -*- mode: erlang -*-
%% ex: ft=erlang
{sys, [
{lib_dirs, ["..","../deps"]},
{erts, [{mod_cond, all}, {app_file, strip}]},
{app_file, strip},
{rel, "chat_grabber", "1",
[
kernel,
stdlib,
sasl,
couchbeam,
chat_grabber
]},
{rel, "start_clean", "",
[
kernel,
stdlib
]},
{boot_rel, "chat_grabber"},
{profile, embedded},
{incl_cond, derived},
{excl_archive_filters, [".*"]}, %% Do not archive built libs
{excl_sys_filters, ["^bin/(?!start_clean.boot)",
"^erts.*/bin/(dialyzer|typer)",
"^erts.*/(doc|info|include|lib|man|src)"]},
{excl_app_filters, ["\.gitignore"]},
{app,couchbeam,[{mod_cond,app},{incl_cond,include},{lib_dir, "../deps/"}]},
{app, chat_grabber, [{mod_cond, app}, {incl_cond, include}, {lib_dir, ".."}]}
]}.
{target_dir, "chat_grabber"}.
{overlay, [
{mkdir, "log/sasl"},
{copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"},
{copy, "files/nodetool", "releases/\{\{rel_vsn\}\}/nodetool"},
{copy, "chat_grabber/bin/start_clean.boot",
"\{\{erts_vsn\}\}/bin/start_clean.boot"},
{copy, "files/chat_grabber", "bin/chat_grabber"},
{copy, "files/chat_grabber.cmd", "bin/chat_grabber.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"}
]}.

erlang system with crypto app does not start in embedded mode

I have a system created according http://www.erlang.org/doc/system_principles/create_target.html
which includes crypto application.
I can boot it, but after I add '-mode embedded' to bin/start it seems that something does not start anymore.
I am stuck, how do I investigate? I also added -sname and -setcookie to bin/start, when I remove -mode embedded system starts, application works, I can connect to it using distributed erlang technique. But with embedded it does not interact at all.
The smallest test case is to apply the following patch to the example app from https://github.com/basho/rebar/wiki/Release-handling Once you 'rebar generate' and start it, you won't be able to connect to its erlang vm. Also it does not stop gracefully. Any ideas?
diff --git a/rel/reltool.config b/rel/reltool.config
index 0c26333..ba4bd35 100644
--- a/rel/reltool.config
+++ b/rel/reltool.config
## -6,7 +6,6 ##
kernel,
stdlib,
sasl,
- crypto,
test
]},
{rel, "start_clean", "",
## -24,7 +23,6 ##
{app, sasl, [{incl_cond, include}]},
{app, stdlib, [{incl_cond, include}]},
{app, kernel, [{incl_cond, include}]},
- {app, crypto, [{incl_cond, include}]},
{app, test, [{incl_cond, include}]}
]}.
In embedded mode, all code is loaded during system start-up according
to the boot script. (Code can also be loaded later by explicitly
ordering the code server to do so).
I think you may forgot to to load some library modules.
For debug erl, do you use +v now?
+V
Makes the emulator print out its version number.
**> +v
**Verbose**.**
How about to use rebar (rebar generation) to do the same thing (release operation)?
Rebar will generate the same kind of files for you automatically. You can compare these files with your files and find out the error. especially the boot script.

Resources