rogach
I’ve spent some time understanding how to do hot code reloading with releases built using mix release, and here I’d like to detail the steps needed, in hopes that it will help someone.
So, in order to make hot-reloadable release you need:
- Write an appup file (the Erlang’s Appup cookbook is a great resource for that: Appup Cookbook — Erlang System Documentation v29.0.2).
- Tweak the release generated by
mix release, by copying the .rel & .appup files into expected places and generating the relup file. This can be done by hand, but I’ve wrote a simple function that can do that right inside themix releasetask:
def project do
[
releases: [
app_name: [
include_executables_for: [:unix],
steps: [:assemble, &release_fixup_step/1, :tar],
],
],
...
]
end
defp release_fixup_step(release) do
releases_dir = Path.join(release.path, "releases")
rel_file = Path.join([releases_dir, release.version, "#{release.name}.rel"])
:ok = :release_handler.create_RELEASES(releases_dir, rel_file, [])
# Yes, we have three copies of a same file in the same place.
# This is necessary to appease the release_handler.
File.cp!(rel_file, Path.join([releases_dir, release.version, "#{release.name}-#{release.version}.rel"]))
File.cp!(rel_file, Path.join([releases_dir, "#{release.name}-#{release.version}.rel"]))
# Copy appup file into the correct location and generate the relup.
appup_file = Path.join("appups", "#{release.version}.appup")
if File.exists?(Path.join("appups", "#{release.version}.appup")) do
File.cp!(
appup_file,
Path.join([release.path, "lib", "#{release.name}-#{release.version}", "ebin", "#{release.name}.appup"])
)
{:ok, appup} = :file.consult(appup_file)
[{appup_release_version, [{version_up_from, _}], [{version_down_to, _}]}] = appup
if appup_release_version != to_charlist(release.version) do
raise "Unexpected version in appup: #{appup_release_version} (expected #{release.version})"
end
if version_up_from != version_down_to do
raise "Unexpected versions in appup instructions: #{version_up_from} != #{version_down_to}"
end
:systools.make_relup(
~c"#{release.name}-#{release.version}",
[~c"#{release.name}-#{version_up_from}"],
[~c"#{release.name}-#{version_down_to}"],
path: [to_charlist(Path.join(release.path, "releases/*")), to_charlist(Path.join(release.path, "lib/*/ebin"))],
outdir: to_charlist(release.version_path)
)
end
release
end
Now, after running mix release you will get a release archive in _build/<env>/app_name-<version>.tar.gz.
- Copy this archive into the
releases/directory of your running release. - Connect to the Iex shell of the running release.
- Carefully run the commands:
:release_handler.unpack_release(~c"app_name-<version>")
:release_handler.install_release(~c"<version>")
:release_handler.make_permanent(~c"<version>")
Trending in Guides/Tuts
I’ve spent some time understanding how to do hot code reloading with releases built using mix release, and here I’d like to detail the st...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
defman
I’d like to explain a bit more about “appeasing the release_handler” because I’ve spent some time this night on this (I was interested for why we need 3 copies of the rel file).
The rel file in
_build/.../rel/releases/.../(/releases/.../in the tarball) is required by:systoos.make_relup.path: [Dir]in the call is wheremake_relupsearches for rel, app and appup files to generate the relup.mix release already creates a rel file named
release.namein that folder, butmake_relupwill search forrelease.name-release.version(Name.relandName2.relinmake_relup(Name, [Name2], [Name2]): systools — OTP 29.1 (sasl 4.4)).So it finds rel files in
releases/*/.../and app and appup files inlib/*/ebin/, for example:The rel file in
_build/.../rel/releases/(/releases/in the tarball) is required by:release_handler.unpack_release. Without it, unpacking will fail:This happens because
unpack_releasetries to extractreleases/{release-name}.relfrom the tarball:Then it tries to check the rel file:
and
check_relcallsconsult(..., false)which is defined asYou can go as much as:
:assemblefromreleases/#{release.version}/#{release.name}.erltoreleases/#{release.version}/#{release.name}-{release.version}.erlfor:systools.make_relupreleases/for:release_handler.unpack_releasereleases/back toreleases/#{release.version}(this is needed for your next release,make_relupsearches for previous release rel file inreleases/*/Here’s my final solution:
This will produce a tar.gz release without rel being duplicated 3 times in releases/version/ (app_name.rel and app_name-version.rel) and in releases/ (app_name-version.rel):
rogach
Nice! Thank you for your work on improving this.
defman
You can also add
So rel would be used like that:
releases/tomake_reluppath and it will find rel for current release andunpack_releasewill also be happyreleases/version/app_name.rel -> releases/app_name-version.rel -> create relup -> create tarball -> releases/version/app_name-version.rel (for next release)