Applications

Start types: permanent (node stops if app dies), transient, temporary (default).

29.1 Application resource file (.app.src)

{application, myapp,
 [{description, "My application"},
  {vsn, "0.1.0"},
  {registered, [myapp_sup, kv_store]},
  {mod, {myapp_app, []}},
  {applications, [kernel, stdlib, crypto, cowboy]},   % started before this app
  {env, [{port, 8080}, {pool_size, 10}]},
  {modules, []},
  {licenses, ["Apache-2.0"]},
  {links, [{"GitHub", "https://github.com/me/myapp"}]}]}.

29.2 Application callback

-module(myapp_app).
-behaviour(application).
-export([start/2, stop/1]).

start(_StartType, _StartArgs) -> myapp_sup:start_link().
stop(_State) -> ok.

29.3 Working with applications

Start types: permanent (node stops if app dies), transient, temporary (default).

application:start(myapp),
application:ensure_all_started(myapp),
application:stop(myapp),
application:which_applications(),
application:get_env(myapp, port),                 % {ok, 8080} | undefined
application:get_env(myapp, port, 80),
application:set_env(myapp, port, 9090),
code:priv_dir(myapp).

29.4 Configuration: sys.config & vm.args

sys.config.src / vm.args.src support ${ENV_VAR} substitution in releases.

%% config/sys.config
[{myapp, [{port, 8080}]},
 {kernel, [{logger_level, info}]}].
## config/vm.args
-name [email protected]
-setcookie secret_cookie
+P 1000000
+K true
+A 64

29.5 Included & library applications

Library applications have no mod (no processes) — e.g., stdlib. Core OTP apps: kernel, stdlib, sasl, crypto, ssl, inets, mnesia, os_mon, runtime_tools, observer, tools.