I'm using Erlang/OTP 20.0 and rebar3. When I start a new release that use cowboy 2.0.0, the release fail to start.
Here are the steps I do to build the project. What's wrong?
create the release project
$ rebar3 new release cowboy2
add cowboy package
{deps, [{cowboy, {git, "https://github.com/ninenines/cowboy.git", {tag, "2.0.0"}}}]}.
add a basic dispatcher
start(_StartType, _StartArgs) -> Dispatch = cowboy_router:compile([ {'_', [ {"/", toppage_handler, []} ]} ]), {ok, _} = cowboy:start_clear(http, [{port, 8080}], #{ env => #{dispatch => Dispatch} }), cowboy2_sup:start_link().
add handler. for the purpose of this example I use (https://raw.githubusercontent.com/ninenines/cowboy/master/examples/hello_world/src/toppage_handler.erl)
compile and release
$ rebar3 compile && rebar3 release
run the application
$ ./_build/default/rel/cowboy2/bin/cowboy2-0.1.0 console
The output
$ ./_build/default/rel/cowboy2/bin/cowboy2-0.1.0 console
Exec: /home/deimos/.asdf/installs/erlang/20.0/lib/erlang/erts-9.0/bin/erlexec
-boot /home/deimos/Dev/personal/cowboy2/_build/default/rel/cowboy2/releases/0.1.0/cowboy2
-mode embedded -boot_var ERTS_LIB_DIR /home/deimos/.asdf/installs/erlang/20.0/lib/erlang/lib
-config /home/deimos/Dev/personal/cowboy2/_build/default/rel/cowboy2/releases/0.1.0/sys.config
-args_file /home/deimos/Dev/personal/cowboy2/_build/default/rel/cowboy2/releases/0.1.0/vm.args
-pa -- console
Root: /home/deimos/Dev/personal/cowboy2/_build/default/rel/cowboy2
/home/deimos/Dev/personal/cowboy2/_build/default/rel/cowboy2
Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:30] [hipe] [kernel-poll:true]
=INFO REPORT==== 11-Oct-2017::21:00:52 ===
application: cowboy2
exited: {bad_return,
{{cowboy2_app,start,[normal,[]]},
{'EXIT',
{undef,
[{cowboy_router,compile,
[[{'_',[{"/",toppage_handler,[]}]}]],
[]},
{cowboy2_app,start,2,
[{file,
"/home/deimos/Dev/personal/cowboy2/_build/default/lib/cowboy2/src/cowboy2_app.erl"},
{line,18}]},
{application_master,start_it_old,4,
[{file,"application_master.erl"},
{line,273}]}]}}}}
type: permanent
(...)
Kernel pid terminated (application_controller)
({application_start_failure,cowboy2,{bad_return,{{cowboy2_app,start,[normal,[]]},{'EXIT',{undef,[{cowboy_router,compile,[[{'_',[{"/",toppage_handler,[]}]
Crash dump is being written to: erl_crash.dump...done
cowboy 2
, but incowboy 1
, you had to manually start the cowboy-application inside your main process in order to use cowboy-routines, router, dispatcher and so on. I made a minimal cowboy-example a while ago to remind me of things like this. This was basically not documented. Take a look at github.com/maze-le/minimal-cowboy/blob/master/src/mincb.erl. – Mathias Vonende