.TH appup 4 "sasl 4.3" "Ericsson AB" "Erlang Module Definition" .SH NAME appup \- Application upgrade file .SH DESCRIPTION .PP The \fIapplication upgrade file\fR defines how an application is upgraded or downgraded in a running system. .PP This file is used by the functions in \fIsystools\fR when generating a release upgrade file \fIrelup\fR. .SS "File Syntax" .PP The application upgrade file is to be called \fIApplication.appup\fR, where \fIApplication\fR is the application name. The file is to be located in the \fIebin\fR directory for the application. .PP The \fI.appup\fR file contains one single Erlang term, which defines the instructions used to upgrade or downgrade the application. The file has the following syntax: .IP .nf {Vsn, [{UpFromVsn, Instructions}, ...], [{DownToVsn, Instructions}, ...]}. .fi Vsn = string() .RS 2 Current application version. .RE UpFromVsn = string() | binary() .RS 2 An earlier application version to upgrade from. If it is a string, it is interpreted as a specific version number. If it is a binary, it is interpreted as a regular expression that can match multiple version numbers. .RE DownToVsn = string() | binary() .RS 2 An earlier application version to downgrade to. If it is a string, it is interpreted as a specific version number. If it is a binary, it is interpreted as a regular expression that can match multiple version numbers. .RE Instructions .RS 2 A list of \fIrelease upgrade instructions\fR, see Release Upgrade Instructions. It is recommended to use high-level instructions only. These are automatically translated to low-level instructions by \fIsystools\fR when creating the \fIrelup\fR file. .RE .PP To avoid duplication of upgrade instructions, it is allowed to use regular expressions to specify \fIUpFromVsn\fR and \fIDownToVsn\fR. To be considered a regular expression, the version identifier must be specified as a binary. For example, the following match all versions \fI2.1.x\fR, where \fIx\fR is any number: .IP .nf <<"2\\\\.1\\\\.[0-9]+">> .fi .PP Notice that the regular expression must match the complete version string, so this example works for, for example, \fI2.1.1\fR, but not for \fI2.1.1.1\fR. .SS "Release Upgrade Instructions" .PP Release upgrade instructions are interpreted by the release handler when an upgrade or downgrade is made. For more information, see \fIRelease Handling\fR in \fIOTP Design Principles\fR. .PP A process is said to \fIuse\fR a module \fIMod\fR if \fIMod\fR is listed in the \fIModules\fR part of the child specification used to start the process, see \fIsupervisor\fR. In the case of \fIgen_event\fR, an event manager process is said to use \fIMod\fR if \fIMod\fR is an installed event handler. .PP \fBHigh-Level Instructions\fR .IP .nf {update, Mod} {update, Mod, supervisor} {update, Mod, Change} {update, Mod, DepMods} {update, Mod, Change, DepMods} {update, Mod, Change, PrePurge, PostPurge, DepMods} {update, Mod, Timeout, Change, PrePurge, PostPurge, DepMods} {update, Mod, ModType, Timeout, Change, PrePurge, PostPurge, DepMods} Mod = atom() ModType = static | dynamic Timeout = int()>0 | default | infinity Change = soft | {advanced,Extra} Extra = term() PrePurge = PostPurge = soft_purge | brutal_purge DepMods = [Mod] .fi .PP Synchronized code replacement of processes using module \fIMod\fR. .PP All those processes are suspended using \fIsys:suspend\fR, the new module version is loaded, and then the processes are resumed using \fIsys:resume\fR. Change .RS 2 Defaults to \fIsoft\fR and defines the type of code change. If it is set to \fI{advanced,Extra}\fR, implemented processes using \fIgen_server\fR, \fIgen_fsm\fR, \fIgen_statem\fR, or \fIgen_event\fR transform their internal state by calling the callback function \fIcode_change\fR. Special processes call the callback function \fIsystem_code_change/4\fR. In both cases, the term \fIExtra\fR is passed as an argument to the callback function. .RE PrePurge .RS 2 Defaults to \fIbrutal_purge\fR. It controls what action to take with processes executing old code before loading the new module version. If the value is \fIbrutal_purge\fR, the processes are killed. If the value is \fIsoft_purge\fR, \fIrelease_handler:install_release/1\fR returns \fI{error,{old_processes,Mod}}\fR. .RE PostPurge .RS 2 Defaults to \fIbrutal_purge\fR. It controls what action to take with processes that are executing old code when the new module version has been loaded. If the value is \fIbrutal_purge\fR, the code is purged when the release is made permanent and the processes are killed. If the value is \fIsoft_purge\fR, the release handler purges the old code when no remaining processes execute the code. .RE DepMods .RS 2 Defaults to \fI[]\fR and defines other modules that \fIMod\fR is dependent on. In the \fIrelup\fR file, instructions for suspending processes using \fIMod\fR come before instructions for suspending processes using modules in \fIDepMods\fR when upgrading, and conversely when downgrading. In case of circular dependencies, the order of the instructions in the \fIappup\fR file is kept. .RE Timeout .RS 2 Defines the time-out when suspending processes. If no value or \fIdefault\fR is specified, the default value for \fIsys:suspend\fR is used. .RE ModType .RS 2 Defaults to \fIdynamic\fR. It specifies if the code is "dynamic", that is, if a process using the module spontaneously switches to new code, or if it is "static". When doing an advanced update and upgrade, the new version of a dynamic module is loaded before the process is asked to change code. When downgrading, the process is asked to change code before loading the new version. For static modules, the new version is loaded before the process is asked to change code, both in the case of upgrading and downgrading. Callback modules are dynamic. .RE .PP \fIupdate\fR with argument \fIsupervisor\fR is used when changing the start specification of a supervisor. .IP .nf {load_module, Mod} {load_module, Mod, DepMods} {load_module, Mod, PrePurge, PostPurge, DepMods} Mod = atom() PrePurge = PostPurge = soft_purge | brutal_purge DepMods = [Mod] .fi .PP Simple code replacement of the module \fIMod\fR. .PP For a description of \fIPrePurge\fR and \fIPostPurge\fR, see \fIupdate\fR above. .PP \fIDepMods\fR defaults to \fI[]\fR and defines which other modules \fIMod\fR is dependent on. In the \fIrelup\fR file, instructions for loading these modules come before the instruction for loading \fIMod\fR when upgrading, and conversely when downgrading. .IP .nf {add_module, Mod} {add_module, Mod, DepMods} Mod = atom() DepMods = [Mod] .fi .PP Loads a new module \fIMod\fR. .PP \fIDepMods\fR defaults to \fI[]\fR and defines which other modules \fIMod\fR is dependent on. In the \fIrelup\fR file, instructions related to these modules come before the instruction for loading \fIMod\fR when upgrading, and conversely when downgrading. .IP .nf {delete_module, Mod} {delete_module, Mod, DepMods} Mod = atom() .fi .PP Deletes a module \fIMod\fR using the low-level instructions \fIremove\fR and \fIpurge\fR. .PP \fIDepMods\fR defaults to \fI[]\fR and defines which other modules \fIMod\fR is dependent on. In the \fIrelup\fR file, instructions related to these modules come before the instruction for removing \fIMod\fR when upgrading, and conversely when downgrading. .IP .nf {add_application, Application} {add_application, Application, Type} Application = atom() Type = permanent | transient | temporary | load | none .fi .PP Adding an application means that the modules defined by the \fImodules\fR key in the \fI.app\fR file are loaded using \fIadd_module\fR. .PP \fIType\fR defaults to \fIpermanent\fR and specifies the start type of the application. If \fIType = permanent | transient | temporary\fR, the application is loaded and started in the corresponding way, see \fIapplication\fR. If \fIType = load\fR, the application is only loaded. If \fIType = none\fR, the application is not loaded and not started, although the code for its modules is loaded. .IP .nf {remove_application, Application} Application = atom() .fi .PP Removing an application means that the application is stopped, the modules are unloaded using \fIdelete_module\fR, and then the application specification is unloaded from the application controller. .IP .nf {restart_application, Application} Application = atom() .fi .PP Restarting an application means that the application is stopped and then started again, similar to using the instructions \fIremove_application\fR and \fIadd_application\fR in sequence. Note that, even if the application has been started before the release upgrade is performed, \fIrestart_application\fR may only \fIload\fR it rather than \fIstart\fR it, depending on the application's \fIstart type\fR: If \fIType = load\fR, the application is only loaded. If \fIType = none\fR, the application is not loaded and not started, although the code for its modules is loaded. .PP \fBLow-Level Instructions\fR .IP .nf {load_object_code, {App, Vsn, [Mod]}} App = Mod = atom() Vsn = string() .fi .PP Reads each \fIMod\fR from directory \fIApp-Vsn/ebin\fR as a binary. It does not load the modules. The instruction is to be placed first in the script to read all new code from the file to make the suspend-load-resume cycle less time-consuming. .IP .nf point_of_no_return .fi .PP If a crash occurs after this instruction, the system cannot recover and is restarted from the old release version. The instruction must only occur once in a script. It is to be placed after all \fIload_object_code\fR instructions. .IP .nf {load, {Mod, PrePurge, PostPurge}} Mod = atom() PrePurge = PostPurge = soft_purge | brutal_purge .fi .PP Before this instruction occurs, \fIMod\fR must have been loaded using \fIload_object_code\fR. This instruction loads the module. \fIPrePurge\fR is ignored. For a description of \fIPostPurge\fR, see the high-level instruction \fIupdate\fR earlier. .IP .nf {remove, {Mod, PrePurge, PostPurge}} Mod = atom() PrePurge = PostPurge = soft_purge | brutal_purge .fi .PP Makes the current version of \fIMod\fR old. \fIPrePurge\fR is ignored. For a description of \fIPostPurge\fR, see the high-level instruction \fIupdate\fR earlier. .IP .nf {purge, [Mod]} Mod = atom() .fi .PP Purges each module \fIMod\fR, that is, removes the old code. Notice that any process executing purged code is killed. .IP .nf {suspend, [Mod | {Mod, Timeout}]} Mod = atom() Timeout = int()>0 | default | infinity .fi .PP Tries to suspend all processes using a module \fIMod\fR. If a process does not respond, it is ignored. This can cause the process to die, either because it crashes when it spontaneously switches to new code, or as a result of a purge operation. If no \fITimeout\fR is specified or \fIdefault\fR is specified, the default value for \fIsys:suspend\fR is used. .IP .nf {resume, [Mod]} Mod = atom() .fi .PP Resumes all suspended processes using a module \fIMod\fR. .IP .nf {code_change, [{Mod, Extra}]} {code_change, Mode, [{Mod, Extra}]} Mod = atom() Mode = up | down Extra = term() .fi .PP \fIMode\fR defaults to \fIup\fR and specifies if it is an upgrade or downgrade. This instruction sends a \fIcode_change\fR system message to all processes using a module \fIMod\fR by calling function \fIsys:change_code\fR, passing term \fIExtra\fR as argument. .IP .nf {stop, [Mod]} Mod = atom() .fi .PP Stops all processes using a module \fIMod\fR by calling \fIsupervisor:terminate_child/2\fR. This instruction is useful when the simplest way to change code is to stop and restart the processes that run the code. .IP .nf {start, [Mod]} Mod = atom() .fi .PP Starts all stopped processes using a module \fIMod\fR by calling \fIsupervisor:restart_child/2\fR. .IP .nf {sync_nodes, Id, [Node]} {sync_nodes, Id, {M, F, A}} Id = term() Node = node() M = F = atom() A = [term()] .fi .PP \fIapply(M, F, A)\fR must return a list of nodes. .PP This instruction synchronizes the release installation with other nodes. Each \fINode\fR must evaluate this command with the same \fIId\fR. The local node waits for all other nodes to evaluate the instruction before execution continues. If a node goes down, it is considered to be an unrecoverable error, and the local node is restarted from the old release. There is no time-out for this instruction, which means that it can hang forever. .IP .nf {apply, {M, F, A}} M = F = atom() A = [term()] .fi .PP Evaluates \fIapply(M, F, A)\fR. .PP If the instruction appears before instruction \fIpoint_of_no_return\fR, a failure is caught. \fIrelease_handler:install_release/1\fR then returns \fI{error,{'EXIT',Reason}}\fR, unless \fI{error,Error}\fR is thrown or returned. Then it returns \fI{error,Error}\fR. .PP If the instruction appears after instruction \fIpoint_of_no_return\fR and the function call fails, the system is restarted. .IP .nf restart_new_emulator .fi .PP This instruction is used when the application ERTS, Kernel, STDLIB, or SASL is upgraded. It shuts down the current emulator and starts a new one. All processes are terminated gracefully, and the new version of ERTS, Kernel, STDLIB, and SASL are used when the emulator restarts. Only one \fIrestart_new_emulator\fR instruction is allowed in the \fIrelup\fR file, and it must be placed first. \fIsystools:make_relup/3,4\fR ensures this when the \fIrelup\fR file is generated. The rest of the instructions in the \fIrelup\fR file is executed after the restart as a part of the boot script. .PP An info report is written when the upgrade is completed. To programmatically determine if the upgrade is complete, call \fIrelease_handler:which_releases/0,1\fR and check if the expected release has status \fIcurrent\fR. .PP The new release must still be made permanent after the upgrade is completed, otherwise the old emulator is started if there is an emulator restart. .PP \fBWARNING: \fRAs stated earlier, instruction \fIrestart_new_emulator\fR causes the emulator to be restarted with new versions of ERTS, Kernel, STDLIB, and SASL. However, all other applications do at startup run their old versions in this new emulator. This is usually no problem, but every now and then incompatible changes occur to the core applications, which can cause trouble in this setting. Such incompatible changes (when functions are removed) are normally preceded by a deprecation over two major releases. To ensure that your application is not crashed by an incompatible change, always remove any call to deprecated functions as soon as possible. .IP .nf restart_emulator .fi .PP This instruction is similar to \fIrestart_new_emulator\fR, except it must be placed at the end of the \fIrelup\fR file. It is not related to an upgrade of the emulator or the core applications, but can be used by any application when a complete reboot of the system is required. .PP When generating the \fIrelup\fR file, \fIsystools:make_relup/3,4\fR ensures that there is only one \fIrestart_emulator\fR instruction and that it is the last instruction in the \fIrelup\fR file. .SS "See Also" .PP \fIrelease_handler\fR, \fIrelup(4)\fR, \fIsupervisor\fR, \fIsystools\fR