Releases & Hot Code Upgrades
A release bundles the ERTS, your applications, and dependencies into a self-contained, deployable package.
36.1 Building releases
A release bundles the ERTS, your applications, and dependencies into a self-contained, deployable package.
Tools: relx (inside rebar3), systools, reltool.
rebar3 release # _build/default/rel/myapp
rebar3 as prod tar # tarball for deployment
_build/default/rel/myapp/bin/myapp foreground # run in foreground
_build/default/rel/myapp/bin/myapp daemon # background
_build/default/rel/myapp/bin/myapp remote_console
_build/default/rel/myapp/bin/myapp stop
_build/default/rel/myapp/bin/myapp eval "myapp:migrate()."36.2 Code loading basics
The BEAM can hold two versions of a module: current and old.
Fully qualified calls (?MODULE:loop(State)) jump to the newest version; local calls stay in the current one.
Loading a third version kills processes still running the oldest code.
code:load_file(mod), code:purge(mod), code:soft_purge(mod),
code:is_loaded(mod), code:get_path(), code:add_patha("ebin"),
code:which(mod), l(mod).loop(State) ->
receive
upgrade -> ?MODULE:loop(State); % switch to new code
Msg -> loop(handle(Msg, State))
end.36.3 Release upgrades: appup & relup
code_change/3 transforms process state between versions.
systools:make_relup/3 (or rebar3 relup / rebar3_appup_plugin) generates relup.
release_handler:unpack_release/1, install_release/1, make_permanent/1 apply upgrades live.
Instructions: {load_module, M}, {update, M, {advanced, Extra}}, {add_module, M}, {delete_module, M}, {apply, {M, F, A}}, {restart_application, App}.
%% myapp.appup
{"0.2.0",
[{"0.1.0", [{update, kv_store, {advanced, []}}]}], % upgrade instructions
[{"0.1.0", [{update, kv_store, {advanced, []}}]}]}. % downgrade instructions36.4 Deployment today
Many teams use rolling deploys with Docker/Kubernetes; hot upgrades remain valuable for telecom-grade systems that must never drop connections.