release_handler(3)
π release_handler(3) π
Erlang Module Definition Β· bestie edition β¨
πΈ NAME πΈ
release_handler β Unpacking and Installation of Release Packages π
β¨ DESCRIPTION β¨
okay so. The release handler process belongs to the SASL application, and it's the one in charge of release handling β that's unpacking, installation, and removal of release packages. She's the main character of upgrades, periodt. π
If you want an intro to release handling plus a whole example, go read the Release Handling section in OTP Design Principles. It's giving required reading fr fr.
So. A release package is a compressed tar file containing code for a certain version of a release, and you make one by calling systools:make_tar/1,2. That package is supposed to live in the $ROOT/releases directory of the previous version of the release, where $ROOT is the installation root directory, code:root_dir(). You can point at a different releases directory with the SASL configuration parameter releases_dir or the OS environment variable RELDIR. Heads up: the release handler must have write access to this directory to install the new release. Her persistent state is stored right there in a file called RELEASES. π
A release package is always to contain:
- release resource file,
Name.rel - boot script,
Name.boot
The .rel file has the info about the release: its name, version, and which ERTS and application versions it uses. iykyk.
A release package can also contain:
- release upgrade file,
relup - system configuration file,
sys.config - system configuration source file,
sys.config.src
The relup file contains instructions for how to upgrade to, or downgrade from, this version of the release. Iconic, honestly.
So here's the flow, bestie. The release package can be unpacked β that extracts the files. An unpacked release can be installed. The currently used version of the release is then upgraded or downgraded to the specified version by evaluating the instructions in the relup file. An installed release can be made permanent. Only one permanent release can exist in the system, and this release is the one used if the system is restarted. An installed release β any one except the permanent one β can be removed. When a release is removed, all files belonging to that release only are deleted. no crumbs left. π§Ή
Every release version has a status, and it can be unpacked, current, permanent, or old. There is always one latest release, which either has status permanent (the normal case) or current (installed, but not yet made permanent). Here's what each status actually means β the full vibe check π¦:
- status
-- action
unpackβ next statusunpacked
- action
- status
unpacked- action
installβ next statuscurrent - action
removeβ next status-
- action
- status
current- action
make_permanentβ next statuspermanent - action
install otherβ next statusold - action
removeβ next status-
- action
- status
permanent- action
make other permanentβ next statusold - action
installβ next statuspermanent
- action
- status
old- action
reboot_oldβ next statuspermanent - action
installβ next statuscurrent - action
removeβ next status-
- action
The release handler process is a locally registered process on each node. When a release is installed in a distributed system, the release handler on each node must be called. The release installation can be synchronized between nodes. From an operator view, it can be unsatisfactory to specify each node β the goal is to install one release package in the system, no matter how many nodes there are. So yes, it's recommended that software management functions are written that take care of this problem. Such a function can have knowledge of the system architecture, so it can contact each individual release handler to install the package. Cute, right? π
For release handling to work properly, the runtime system must know which release it's running. It must also be able to change (in runtime) which boot script and system configuration file are to be used if the system is restarted. This is taken care of automatically if Erlang is started as an embedded system. Read about that in Embedded System in System Documentation. In this case, the system configuration file sys.config is mandatory. no skipping, bestie π
The installation of a new release can restart the system. Which program to use is specified by the SASL configuration parameter start_prg, which defaults to $ROOT/bin/start.
The emulator restart on Windows NT expects that the system is started using the erlsrv program (as a service). Furthermore, the release handler expects that the service is named NodeName_Release, where NodeName is the first part of the Erlang node name (up to, but not including the "@") and Release is the current release version. The release handler furthermore expects that a program like start_erl.exe is specified as "machine" to erlsrv. During upgrading with restart, a new service is registered and started. The new service is set to automatic and the old service is removed when the new release is made permanent. very demure, very mindful of services π
The release handler at a node running on a diskless machine, or with a read-only file system, must be configured accordingly using the following SASL configuration parameters (for details, see sasl(6)):
mastersβ This node uses some master nodes to store and fetch release information. All master nodes must be operational whenever release information is written by this node.client_directoryβ Theclient_directoryin the directory structure of the master nodes must be specified.static_emulatorβ This parameter specifies if the Erlang emulator is statically installed at the client node. A node with a static emulator cannot dynamically switch to a new emulator, as the executable files are statically written into memory.
The release handler can also be used to unpack and install release packages when not running Erlang as an embedded system. However, in this case the user must somehow ensure that correct boot scripts and configuration files are used if the system must be restarted. your problem now π«Ά
Functions are provided for using another file structure than the structure defined in OTP. These functions can be used to test a release upgrade locally.
π¨ Typical Error Reasons π¨
{bad_masters, Masters}β The master nodesMastersare not alive. π{bad_rel_file, File}β Specified.relfileFilecannot be read or does not contain a single term.{bad_rel_data, Data}β Specified.relfile does not contain a recognized release specification, but another termData.{bad_relup_file, File}β SpecifiedrelupfileRelupcontains bad data.{cannot_extract_file, Name, Reason}β Problems when extracting from a tar file,erl_tar:extract/2returned{error, {Name, Reason}}.{existing_release, Vsn}β Specified release versionVsnis already in use.{Master, Reason, When}β Some operation, indicated by the termWhen, failed on the master nodeMasterwith the specified error reasonReason.{no_matching_relup, Vsn, CurrentVsn}β Cannot find a script for upgrading/downgrading betweenCurrentVsnandVsn.{no_such_directory, Path}β The directoryPathdoes not exist.{no_such_file, Path}β The pathPath(file or directory) does not exist.{no_such_file, {Master, Path}}β The pathPath(file or directory) does not exist at the master nodeMaster.{no_such_release, Vsn}β The specified release versionVsndoes not exist.{not_a_directory, Path}βPathexists but is not a directory.{Posix, File}β Some file operation failed forFile.Posixis an atom named from the Posix error codes, such asenoent,eacces, oreisdir. Seefilein Kernel.Posixβ Some file operation failed, as for the previous item in the list.
π§ͺ Application Upgrade/Downgrade π§ͺ
The functions in the Application Upgrade/Downgrade section can be used to test upgrade and downgrade of single applications (instead of upgrading/downgrading an entire release). A script corresponding to the instructions in the relup file is created on-the-fly, based on the .appup file for the application, and evaluated exactly in the same way as release_handler does. so slay of them honestly β¨
WARNING: These functions are primarily intended for simplified testing of.appupfiles. They are not run within the context of therelease_handlerprocess. They must therefore not be used together with calls toinstall_release/1,2, as this causes therelease_handlerto end up in an inconsistent state. No persistent information is updated, so these functions can be used on any Erlang node, embedded or not. Also, using these functions does not affect which code is loaded if there is a reboot. If the upgrade or downgrade fails, the application can end up in an inconsistent state. π read this one twice bestie
See Also
OTP Design Principles, config, rel, relup, script, sys, systools
π FUNCTIONS π
check_install_release(Vsn, Opts) ->
{ok, OtherVsn, Descr} | {error, Reason}
when
Vsn :: string(),
OtherVsn :: string(),
Opts :: [Opt],
Opt :: purge,
Descr :: term(),
Reason :: term().
Checks if the specified version Vsn of the release can be installed. like a vibe check but for releases π
The release must not have status current. Issues warnings if relup file or sys.config is not present. If relup file is present, its contents are checked and {error,Reason} is returned if an error is found. Also checks that all required applications are present and that all new code can be loaded; {error,Reason} is returned if an error is found.
Evaluates all instructions that occur before the point_of_no_return instruction in the release upgrade script. that's the line you don't cross, fr fr πΈ
Returns the same as install_release/1. Descr defaults to "" if no relup file is found.
If option purge is specified, all old code that can be soft-purged is purged after all other checks are successfully completed. This can be useful to reduce the time needed by install_release/1. π
β¨ create_RELEASES β¨
create_RELEASES(Root, RelDir, RelFile, AppDirs) ->
ok | {error, Reason}
when
Root :: string(),
RelDir :: string(),
RelFile :: string(),
AppDirs :: [{App, Vsn, Dir}],
App :: atom(),
Vsn :: string(),
Dir :: string(),
Reason :: term().
okay bestie so this one creates an initial RELEASES file that the release handler uses. This file must exist to install new releases. No RELEASES file = no new release, periodt. π
Root is the root of the installation ($ROOT) as described earlier. RelDir is the directory where the RELEASES file is to be created (normally $ROOT/releases). RelFile is the name of the .rel file that describes the initial release, including the extension .rel. If Root is not given, the RELEASES file will be location independent (i.e, it will not contain absolute paths unless there are absolute paths in AppDirs). A RELEASES file should be made location independent if the installation's $ROOT is unknown. The release_handler module will interpret relative paths in a running system's RELEASES file as being relative to $ROOT.
AppDirs can be used to specify from where the modules for the specified applications are to be loaded. App is the name of an application, Vsn is the version, and Dir is the name of the directory where App-Vsn is located. The corresponding modules are to be located under Dir/App-Vsn/ebin. The directories for applications not specified in AppDirs are assumed to be located in $ROOT/lib.
πΈ downgrade_app πΈ
downgrade_app(App, OldVsn, Dir) ->
{ok, Unpurged} |
restart_emulator |
{error, Reason}
when
App :: atom(),
Dir :: string(),
OldVsn :: string(),
Unpurged :: [Module],
Module :: atom(),
Reason :: term().
Downgrades an application App from the current version to a previous version OldVsn located in Dir according to the .appup file. π
App is the name of the application, which must be started. OldVsn is the previous application version and can be omitted if Dir is of the format "App-OldVsn". Dir is the library directory of the previous version of App. The corresponding modules and the old .app file are to be located under Dir/ebin. The .appup file is to be located in the ebin directory of the current library directory of the application (code:lib_dir(App)).
The function looks in the .appup file and tries to find a downgrade script to the previous version of the application using downgrade_script/3. This script is evaluated using eval_appup_script/4, exactly in the same way as install_release/1,2 does.
Returns one of the following:
{ok, Unpurged}if evaluating the script is successful, whereUnpurgedis a list of unpurged modulesrestart_emulatorif this instruction is encountered in the script{error, Reason}if an error occurred when finding or evaluating the script
π¦ downgrade_script π¦
downgrade_script(App, OldVsn, Dir) -> {ok, Script}
when
App :: atom(),
OldVsn :: string(),
Dir :: string(),
Script :: Instructions :: term().
Tries to find an application downgrade script for App from the current version to a previous version OldVsn located in Dir.
The downgrade script can then be evaluated using eval_appup_script/4. It is recommended to use downgrade_app/2,3 instead, but this function (downgrade_script) is useful to inspect the contents of the script.
App is the name of the application, which must be started. Dir is the previous library directory of App. The corresponding modules and the old .app file are to be located under Dir/ebin. The .appup file is to be located in the ebin directory of the current library directory of the application (code:lib_dir(App)).
The function looks in the .appup file and tries to find a downgrade script from the current application version. High-level instructions are translated to low-level instructions. The instructions are sorted in the same manner as when generating a relup file.
Returns {ok, Script} if successful. For details about Script, see appup(4).
Failure: If a script cannot be found, the function fails with an appropriate error reason.
π eval_appup_script π
eval_appup_script(App, ToVsn, ToDir, Script :: term()) ->
{ok, Unpurged} |
restart_emulator |
{error, Reason}
when
App :: atom(),
ToVsn :: string(),
ToDir :: string(),
Unpurged :: [{Module, PurgeMethod}],
Module :: atom(),
PurgeMethod :: term(),
Reason :: term().
Evaluates an application upgrade or downgrade script Script, the result from calling upgrade_script/2 or downgrade_script/3, exactly in the same way as install_release/1,2 does. β¨
App is the name of the application, which must be started. ToVsn is the version to be upgraded/downgraded to, and ToDir is the library directory of this version. The corresponding modules as well as the .app and .appup files are to be located under Dir/ebin.
Returns one of the following:
{ok, Unpurged}if evaluating the script is successful, whereUnpurgedis a list of unpurged modulesrestart_emulatorif this instruction is encountered in the script{error, Reason}if an error occurred when finding or evaluating the script
If the restart_new_emulator instruction is found in the script, eval_appup_script/4 returns {error,restart_new_emulator}. This because restart_new_emulator requires a new version of the emulator to be started before the rest of the upgrade instructions can be executed, and this can only be done by install_release/1,2.
π install_file π
install_file(Vsn, File) -> ok | {error, Reason}
when
Vsn :: string(),
File :: string(),
Reason :: term().
Installs a release-dependent file in the release structure. π
The release-dependent file must be in the release structure when a new release is installed: start.boot, relup, and sys.config.
The function can be called, for example, when these files are generated at the target. The function is to be called after set_unpacked/2 has been called.
π install_release π
install_release(Vsn, [Opt]) ->
{ok, OtherVsn, Descr} |
{continue_after_restart, OtherVsn, Descr} |
{error, Reason}
when
Vsn :: string(),
OtherVsn :: string(),
Opt ::
{error_action, Action} |
{code_change_timeout, Timeout} |
{suspend_timeout, Timeout} |
{update_paths, Bool},
Action :: restart | reboot,
Timeout ::
default | infinity | pos_integer(),
Bool :: boolean(),
Descr :: term(),
Reason ::
{illegal_option, Opt} |
{already_installed, Vsn} |
{change_appl_data, term()} |
{missing_base_app, OtherVsn, App} |
{could_not_create_hybrid_boot, term()}
|
term(),
App :: atom().
Installs the specified version Vsn of the release. π
Looks first for a relup file for Vsn and a script {UpFromVsn,Descr1,Instructions1} in this file for upgrading from the current version. If not found, the function looks for a relup file for the current version and a script {Vsn,Descr2,Instructions2} in this file for downgrading to Vsn.
If a script is found, the first thing that happens is that the application specifications are updated according to the .app files and sys.config belonging to the release version Vsn.
After the application specifications have been updated, the instructions in the script are evaluated and the function returns {ok,OtherVsn,Descr} if successful. OtherVsn and Descr are the version (UpFromVsn or Vsn) and description (Descr1 or Descr2) as specified in the script.
If {continue_after_restart,OtherVsn,Descr} is returned, the emulator is restarted before the upgrade instructions are executed. This occurs if the emulator or any of the applications Kernel, STDLIB, or SASL are updated. The new emulator version and these core applications execute after the restart. For all other applications the old versions are started and the upgrade is performed as normal by executing the upgrade instructions.
If a recoverable error occurs, the function returns {error,Reason} and the original application specifications are restored. If a non-recoverable error occurs, the system is restarted.
Options:
error_actionβ Defines if the node is to be restarted (init:restart()) or rebooted (init:reboot()) if there is an error during the installation. Default isrestart.code_change_timeoutβ this one sets the time-out for all the calls tosys:change_code. If you don't pass a value, or you literally passdefault, then the default value defined insysgets used instead. π«Άsuspend_timeoutβ same energy, but for all calls tosys:suspend. If no value is given, the values defined by the Timeout parameter of the upgrade or suspend instructions are used. If you passdefault, the default value defined insysis used. β¨{update_paths,Bool}β tells the system whether all application code paths should be updated (Bool==true) or only the code paths for modified applications (Bool==false, which is the default). Heads up though: this option only has an effect for application directories that are not the default$ROOT/lib/App-Vsn, aka application directories that you specified in the argumentAppDirsin a call tocreate_RELEASES/4orset_unpacked/2. π
Example, bestie:
Say in the current version CurVsn of a release, the application directory of myapp is $ROOT/lib/myapp-1.0. You unpack a new version NewVsn outside the release handler and let it know like this:
release_handler:set_unpacked(RelFile, [{myapp,"1.0","/home/user"},...]).
=> {ok,NewVsn}
Now if NewVsn is installed with the option {update_paths,true}, then code:lib_dir(myapp) returns /home/user/myapp-1.0. that's it, that's the whole thing π
NOTE: Installing a new release can be time consuming if there are lots of processes in the system. Why? Because every single process has to be checked for references to old code before a module can be purged. This check can lead to garbage collections and copying of data. π To speed up the execution ofinstall_release, first callcheck_install_release, using optionpurge. That does the same check for old code. Then it purges all modules that can be soft-purged. The purged modules then no longer have any old code, andinstall_releasedoesn't need to do the checks. It doesn't reduce the overall time for the upgrade, but it lets checks and purge run in the background before the real upgrade is started. main character scheduling fr fr π§
NOTE: When upgrading the emulator from a version older than OTP R15, an attempt is made to load new application beam code into the old emulator. Sometimes the new beam format cannot be read by the old emulator, so the code loading fails and the complete upgrade is terminated. π To overcome this problem, the new application code is to be compiled with the old emulator. For more info about emulator upgrade from pre OTP R15 versions, see Design Principles in System Documentation.
make_permanent(Vsn) -> ok | {error, Reason}
when
Vsn :: string(),
Reason ::
{bad_status, Status :: term()} | term().
Makes the specified release version Vsn permanent. Yep, that's the whole vibe β it's now the forever one. β¨
reboot_old_release(Vsn) -> ok | {error, Reason}
when
Vsn :: string(),
Reason ::
{bad_status, Status :: term()} |
term().
Reboots the system by making the old release permanent, and calls init:reboot() directly. π₯
The release has to have status old, or it's not happening.
remove_release(Vsn) -> ok | {error, Reason}
when
Vsn :: string(),
Reason ::
{permanent, Vsn} | client_node | term().
Removes a release and its files from the system. ποΈ
The release must not be the permanent release, bestie β try it and you get {permanent, Vsn} in your face. It removes only the files and directories that aren't in use by another release.
set_removed(Vsn) -> ok | {error, Reason}
when
Vsn :: string(),
Reason :: {permanent, Vsn} | term().
Makes it possible to handle removal of releases outside the release handler. π«Ά
It tells the release handler that the release is removed from the system. Warning though: this function does not delete any files. It's giving "I'm just the messenger."
set_unpacked(RelFile, AppDirs) -> {ok, Vsn} | {error, Reason}
when
RelFile :: string(),
AppDirs :: [{App, Vsn, Dir}],
App :: atom(),
Vsn :: string(),
Dir :: string(),
Reason :: term().
Makes it possible to handle unpacking of releases outside the release handler. β¨
Tells the release handler that the release is unpacked. Vsn is extracted from the release resource file RelFile.
AppDirs can be used to specify from where the modules for the specified applications are to be loaded. App is the name of an application, Vsn is the version, and Dir is the name of the directory where App-Vsn is located. The corresponding modules are to be located under Dir/App-Vsn/ebin. Directories for applications that aren't specified in AppDirs are assumed to be located in $ROOT/lib. periodt π
unpack_release(Name) -> {ok, Vsn} | {error, Reason}
when
Name :: string(),
Vsn :: string(),
Reason :: client_node | term().
Unpacks a release package Name.tar.gz located in the releases directory. π
It performs some checks on the package β for example, checking that all mandatory files are present β and extracts its contents.
upgrade_app(App, Dir) -> {ok, Unpurged} | restart_emulator | {error, Reason}
when
App :: atom(),
Dir :: string(),
Unpurged :: [Module],
Module :: atom(),
Reason :: term().
Upgrades an application App from the current version to a new version located in Dir, according to the .appup file.
App is the name of the application, which must be started. Dir is the new library directory of App. The corresponding modules as well as the .app and .appup files are to be located under Dir/ebin.
The function looks in the .appup file and tries to find an upgrade script from the current version of the application using upgrade_script/2. This script is evaluated using eval_appup_script/4, exactly in the same way as install_release/1,2 does.
Returns one of the following:
{ok, Unpurged}if evaluating the script is successful, whereUnpurgedis a list of unpurged modulesrestart_emulatorif this instruction is encountered in the script{error, Reason}if an error occurred when finding or evaluating the script
If the restart_new_emulator instruction is found in the script, upgrade_app/2 returns {error,restart_new_emulator}. Why? Because restart_new_emulator requires a new version of the emulator to be started before the rest of the upgrade instructions can be executed, and this can only be done by install_release/1,2. no cap, it's a whole thing. π
upgrade_script(App, Dir) -> {ok, NewVsn, Script}
when
App :: atom(),
Dir :: string(),
NewVsn :: string(),
Script :: Instructions :: term().
Tries to find an application upgrade script for App from the current version to a new version located in Dir. π¦
The upgrade script can then be evaluated using eval_appup_script/4. It's recommended to use upgrade_app/2 instead, but this function (upgrade_script) is useful to inspect the contents of the script. iykyk π
App is the name of the application, which must be started. Dir is the new library directory of App. The corresponding modules as well as the .app and .appup files are to be located under Dir/ebin.
The function looks in the .appup file and tries to find an upgrade script from the current application version. High-level instructions are translated to low-level instructions. The instructions are sorted in the same manner as when generating a relup file.
Returns {ok, NewVsn, Script} if successful, where NewVsn is the new application version. For details about Script, see appup(4).
Failure: if a script cannot be found, the function fails with an appropriate error reason. π
which_releases() -> [{Name, Vsn, Apps, Status}]
when
Name :: string(),
Vsn :: string(),
Apps :: [AppVsn :: string()],
Status ::
unpacked | current | permanent | old.
Returns all releases known to the release handler. the whole roster, bestie π
which_releases(Status) -> [{Name, Vsn, Apps, Status}]
when
Name :: string(),
Vsn :: string(),
Apps :: [AppVsn :: string()],
Status ::
unpacked | current | permanent | old.
Returns all releases, known to the release handler, of a specific status. filter by vibe, iconic behavior β¨
and that's a wrap on this whole page, bestie!! take care of ur releases and they'll take care of u π this queen was brought to you by Ericsson AB, living in sasl 4.4, answering to the name release_handler(3). slay, go upgrade something responsibly π«Άπ
π¦ where this page comes from
- nixos 26.05: erlang 29.1.2
- nixpkgs unstable: erlang 29.1.2
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms