<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>1996</year>
      <year>2020</year>
      <holder>Ericsson AB, All Rights Reserved</holder>
    </copyright>
    <legalnotice>
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
 
      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

  The Initial Developer of the Original Code is Ericsson AB.
    </legalnotice>

    <title>systools</title>
    <prepared></prepared>
    <docno></docno>
    <date></date>
    <rev></rev>
  </header>
  <module since="">systools</module>
  <modulesummary>A Set of Release Handling Tools</modulesummary>
  <description>
    <p>This module contains functions to generate boot scripts
      (<c>.boot</c>, <c>.script</c>), a release upgrade file
      (<c>relup</c>), and release packages.</p>
  </description>

  <funcs>
    <func>
      <name since="">make_relup(Name, UpFrom, DownTo) -> Result</name>
      <name since="">make_relup(Name, UpFrom, DownTo, [Opt]) -> Result</name>
      <fsummary>Generates a release upgrade file <c>relup</c>.</fsummary>
      <type>
        <v>Name = string()</v>
        <v>UpFrom = DownTo = [Name | {Name,Descr}]</v>
        <v>&nbsp;Descr = term()</v>
        <v>Opt = {path,[Dir]} | restart_emulator | silent | noexec | {outdir,Dir}
	| warnings_as_errors</v>
        <v>&nbsp;Dir = string()</v>
        <v>Result = ok | error | {ok,Relup,Module,Warnings} | {error,Module,Error}</v>
        <v>&nbsp;Relup, see relup(4)</v>
        <v>&nbsp;Module = atom()</v>
        <v>&nbsp;Warnings = Error = term()</v>
      </type>
      <desc>
        <p>Generates a release upgrade file <c>relup</c> containing instructions 
	for upgrading from or downgrading to one or more previous releases. 
	The instructions are used by 
	<seeerl marker="release_handler"><c>release_handler</c></seeerl> 
	when installing a new version of a release in runtime.</p>
        <p>By default, <c>relup</c> file is located in the current working
          directory. If option <c>{outdir,Dir}</c> is specified,
          the <c>relup</c> file is located in <c>Dir</c> instead.</p>
        <p>The release resource file <c>Name.rel</c> is compared with
          all release resource files <c>Name2.rel</c>, specified in
          <c>UpFrom</c> and <c>DownTo</c>. For each such pair, the
          following is deducted:</p>
        <list type="bulleted">
          <item>
            <p>Which applications to be deleted, that is,
              applications listed in <c>Name.rel</c> but not
              in <c>Name2.rel</c></p>
          </item>
          <item>
            <p>Which applications to be added, that is, applications
              listed in <c>Name2.rel</c> but not in <c>Name.rel</c></p>
          </item>
          <item>
            <p>Which applications to be upgraded/downgraded, that
              is, applications listed in both <c>Name.rel</c> and
              <c>Name2.rel</c> but with different versions</p>
          </item>
          <item>
            <p>If the emulator needs to be restarted after upgrading or
              downgrading, that is, if the ERTS version differs
              between <c>Name.rel</c> and <c>Name2.rel</c></p>
          </item>
        </list>
        <p>Instructions for this are added to the <c>relup</c> file in
          the above order. Instructions for upgrading or downgrading
          between application versions are fetched from the relevant
          application upgrade files <c>App.appup</c>, sorted in
          the same order as when generating a boot script, see
          <seemfa marker="#make_script/1"><c>make_script/1,2</c></seemfa>. 
	  High-level instructions are translated
          into low-level instructions and the result is printed to the
          <c>relup</c> file.</p>
        <p>The optional <c>Descr</c> parameter is included "as is" in
          the <c>relup</c> file, see
          <seefile marker="relup"><c>relup(4)</c></seefile>. Defaults to
          the empty list.</p>
        <p>All the files are searched for in the code path. It is
          assumed that the <c>.app</c> and <c>.appup</c> files for an
          application are located in the same directory.</p>
        <p>If option <c>{path,[Dir]}</c> is specified, this path is
          appended to the current path. Wildcard <c>*</c> is
          expanded to all matching directories, for example,
          <c>lib/*/ebin</c>.</p>
        <p>If option <c>restart_emulator</c> is specified, a
          low-level instruction to restart the emulator is appended to
          the <c>relup</c> file. This ensures that a complete reboot of
          the system is done when the system is upgraded or downgraded.</p>
        <p>If an upgrade includes a change from an emulator earlier
          than OTP R15 to OTP R15 or later, the warning
          <c>pre_R15_emulator_upgrade</c> is issued. For more information
          about this, see
          <seeguide marker="system/design_principles:appup_cookbook">Design
          Principles</seeguide> in <em>System Documentation</em>.</p>
        <p>By default, errors and warnings are printed to tty and
          the function returns <c>ok</c> or <c>error</c>. If option
          <c>silent</c> is specified, the function instead either returns
          <c>{ok,Relup,Module,Warnings}</c>, where <c>Relup</c> is
          the release upgrade file, or <c>{error,Module,Error}</c>.
          Warnings and errors can be converted to strings by calling
          <c>Module:format_warning(Warnings)</c> or
          <c>Module:format_error(Error)</c>.</p>
        <p>If option <c>noexec</c> is specified, the function returns
          the same values as for <c>silent</c> but no <c>relup</c> file
          is created.</p>
        <p>If option <c>warnings_as_errors</c> is specified, warnings
          are treated as errors.</p>
      </desc>
    </func>

    <func>
      <name since="">make_script(Name) -> Result</name>
      <name since="">make_script(Name, [Opt]) -> Result</name>
      <fsummary>Generates a boot script <c>.script/.boot</c>.</fsummary>
      <type>
        <v>Name = string()</v>
        <v>Opt = src_tests | {path,[Dir]} | local | {variables,[Var]} | exref |
	  {exref,[App]}] | silent | {outdir,Dir} | no_dot_erlang | no_warn_sasl |
	  warnings_as_errors | {script_name, Name}</v>
        <v>&nbsp;Dir = string()</v>
        <v>&nbsp;Var = {VarName,Prefix}</v>
        <v>&nbsp;&nbsp;VarName = Prefix = string()</v>
        <v>&nbsp;App = atom()</v>
        <v>Result = ok | error | {ok,Module,Warnings} | {error,Module,Error}</v>
        <v>&nbsp;Module = atom()</v>
        <v>&nbsp;Warnings = Error = term()</v>
      </type>
      <desc>
        <p>Generates a boot script <c>Name.script</c> and its binary
          version, the boot file <c>Name.boot</c>, unless the <c>{script_name, ScriptName}</c>
          option is given, in which case the names are <c>ScriptName.script</c>
          and <c>ScriptName.boot</c>  The boot file
          specifies which code to be loaded and which applications
          to be started when the Erlang runtime system is started.
          See <seefile marker="script"><c>script(4)</c></seefile>.</p>
        <p>The release resource file <c>Name.rel</c> is read to determine
          which applications are included in the release. Then
          the relevant application resource files <c>App.app</c> are read
          to determine which modules to be loaded, and if and
          how the applications are to be started. (Keys <c>modules</c>
          and <c>mod</c>, see
          <seefile marker="kernel:app"><c>app(4)</c></seefile>.</p>
        <p>By default, the boot script and boot file are located in
          the same directory as <c>Name.rel</c>. That is, in the current
          working directory unless <c>Name</c> contains a path. If
          option <c>{outdir,Dir}</c> is specified, they are located
          in <c>Dir</c> instead.</p>
        <p>The correctness of each application is checked as follows:</p>
        <list type="bulleted">
          <item>
            <p>The version of an application specified in
              the <c>.rel</c> file is to be the same as the version
              specified in the <c>.app</c> file.</p>
          </item>
          <item>
            <p>There are to be no undefined applications, that is,
              dependencies to applications that are not included in
              the release. (Key <c>applications</c> in the <c>.app</c>
              file).</p>
          </item>
          <item>
            <p>There are to be no circular dependencies among
              the applications.</p>
          </item>
          <item>
            <p>There are to be no duplicated modules, that is, modules with
              the same name but belonging to different applications.</p>
          </item>
          <item>
            <p>If option <c>src_tests</c> is specified, a
              warning is issued if the source code for a module is
              missing or is newer than the object code.</p>
          </item>
        </list>
        <p>The applications are sorted according to the dependencies
          between the applications. Where there are no dependencies,
          the order in the <c>.rel</c> file is kept.</p>
        <p>The function fails if the mandatory
          applications Kernel and STDLIB are not
          included in the <c>.rel</c> file and have start
          type <c>permanent</c> (which is default).</p>
        <p>If SASL is not included as an application in
          the <c>.rel</c> file, a warning is issued because such a
          release cannot be used in an upgrade. To turn off this
          warning, add option <c>no_warn_sasl</c>.</p>
        <p>All files are searched for in the current path. It is
          assumed that the <c>.app</c> and <c>.beam</c> files for an
          application are located in the same directory. The <c>.erl</c>
          files are also assumed to be located in this directory, unless
          it is an <c>ebin</c> directory in which case they can be
          located in the corresponding <c>src</c> directory.</p>
        <p>If option <c>{path,[Dir]}</c> is specified, this path is
          appended to the current path. A directory in the path can be
          specified with a wildcard <c>*</c>, this is expanded to all
          matching directories. Example: <c>"lib/*/ebin"</c>.</p>
        <p>In the generated boot script all application directories are
          structured as <c>App-Vsn/ebin</c>. They are assumed to be located
          in <c>$ROOT/lib</c>, where <c>$ROOT</c> is the root directory
          of the installed release. If option <c>local</c> is
          specified, the actual directories where the applications were
          found are used instead. This is a useful way to test a
          generated boot script locally.</p>
        <p>Option <c>variables</c> can be used to specify an
          installation directory other than <c>$ROOT/lib</c> for some of
          the applications. If a variable <c>{VarName,Prefix}</c> is
          specified and an application is found in a directory
          <c>Prefix/Rest/App[-Vsn]/ebin</c>, this application gets
          the path <c>VarName/Rest/App-Vsn/ebin</c> in the boot script.
          If an application is found in a directory <c>Prefix/Rest</c>,
          the path is <c>VarName/Rest/App-Vsn/ebin</c>. When
          starting Erlang, all variables <c>VarName</c> are given
          values using command-line flag <c>boot_var</c>.</p>
        <p><em>Example:</em> If option <c>{variables,[{"TEST","lib"}]}</c>
          is specified and <c>myapp.app</c> is found in
          <c>lib/myapp/ebin</c>, the path to this application in
          the boot script is <c>"$TEST/myapp-1/ebin"</c>. If
          <c>myapp.app</c> is found in <c>lib/test</c>, the path
          is <c>$TEST/test/myapp-1/ebin</c>.</p>
        <p>The checks performed before the boot script is generated can
          be extended with some cross reference checks by specifying
          option <c>exref</c>. These checks are performed with
          the Xref tool. All applications, or the applications specified
          with <c>{exref,[App]}</c>, are checked by Xref and
          warnings are issued for calls to undefined functions.</p>
        <p>By default, errors and warnings are printed to tty and
          the function returns <c>ok</c> or <c>error</c>. If option
          <c>{ok,Module,Warnings}</c> or <c>{error,Module,Error}</c>.
          <c>silent</c> is specified, the function instead returns
          Warnings and errors can be converted to strings by calling
          <c>Module:format_warning(Warnings)</c> or
          <c>Module:format_error(Error)</c>.</p>
        <p>If option <c>warnings_as_errors</c> is specified, warnings
          are treated as errors.</p>
        <p>If option <c>no_dot_erlang</c> is specified, the instruction to
          load the <c>.erlang</c> file during boot is <em>not</em>
          included.</p>
      </desc>
    </func>

    <func>
      <name name="make_tar" arity="1" since=""/>
      <name name="make_tar" arity="2" since=""/>
      <fsummary>Creates a release package.</fsummary>
      <desc>
        <p>Creates a release package file <c>Name.tar.gz</c>.
          This file must be uncompressed and unpacked on the target
          system using 
	  <seeerl marker="release_handler"><c>release_handler</c></seeerl> 
	  before the new release can be installed.</p>
        <p>The release resource file <c>Name.rel</c> is read to determine
          which applications are included in the release. Then
          the relevant application resource files <c>App.app</c> are
          read to determine the version and modules of each application
          (keys <c>vsn</c> and <c>modules</c>, see
          <seefile marker="kernel:app"><c>app(4)</c></seefile>).</p>
        <p>By default, the release package file is located in the same
          directory as <c>Name.rel</c>. That is, in the current working
          directory unless <c>Name</c> contains a path. If option
          <c>{outdir,Dir}</c> is specified, it is located in <c>Dir</c>
          instead.</p>
        <p>If SASL is not included as an application in
          the <c>.rel</c> file, a warning is issued because such a
          release cannot be used in an upgrade. To turn off this
          warning, add option <c>no_warn_sasl</c>.</p>
        <p>By default, the release package contains the directories
          <c>lib/App-Vsn/ebin</c> and <c>lib/App-Vsn/priv</c> for each
          included application. If more directories are to be included,
          option <c>dirs</c> is specified, for example,
          <c>{dirs,[src,examples]}</c>.</p>
        <p>All these files are searched for in the current path. If
          option <c>{path,[Dir]}</c> is specified, this path is
          appended to the current path. Wildcard <c>*</c> is
          expanded to all matching directories.
          Example: <c>"lib/*/ebin"</c>.</p>
        <p>If the <c>{extra_files, ExtraFiles}</c> option is given then the
          <c>ExtraFiles</c> are added to the tarball after everything else to be
          included has been added. The <c>ExtraFiles</c> list is a list of files
          or directories in the same format as the <c>add_type()</c> tuple for
          <seemfa marker="stdlib:erl_tar#add/3">erl_tar:add/3,4</seemfa></p>
        <p>Option <c>variables</c> can be used to specify an
          installation directory other than <c>lib</c> for some of
          the applications. If variable <c>{VarName,Prefix}</c> is
          specified and an application is found in directory
          <c>Prefix/Rest/App[-Vsn]/ebin</c>, this application is
          packed into a separate <c>VarName.tar.gz</c> file as
          <c>Rest/App-Vsn/ebin</c>.</p>
        <p><em>Example:</em> If option <c>{variables,[{"TEST","lib"}]}</c>
          is specified and <c>myapp.app</c> is located in
          <c>lib/myapp-1/ebin</c>, application <c>myapp</c> is
          included in <c>TEST.tar.gz</c>:</p>
        <pre>
% <input>tar tf TEST.tar</input>
myapp-1/ebin/myapp.app
...</pre>
        <p>Option <c>{var_tar,VarTar}</c> can be used to specify if
          and where a separate package is to be stored. In this option
          <c>VarTar</c> is one of the following:</p>
        <taglist>
          <tag><c>include</c></tag>
            <item><p>Each separate (variable) package is included in the
              main <c>ReleaseName.tar.gz</c> file. This is the
              default.</p></item>
          <tag><c>ownfile</c></tag>
            <item><p>Each separate (variable) package is
              generated as a separate file in the same directory as
              the <c>ReleaseName.tar.gz</c> file.</p></item>
          <tag><c>omit</c></tag>
            <item><p>No separate (variable) packages are
              generated. Applications that are found underneath a
              variable directory are ignored.</p></item>
        </taglist>
        <p>A directory <c>releases</c> is also included in
          the release package, containing <c>Name.rel</c> and a
          subdirectory <c>RelVsn</c>. <c>RelVsn</c> is
          the release version as specified in <c>Name.rel</c>.</p>
        <p><c>releases/RelVsn</c> contains the boot script
          <c>Name.boot</c> renamed to <c>start.boot</c> and, if found,
          the files <c>relup</c> and <c>sys.config</c> or <c>sys.config.src</c>. These files
          are searched for in the same directory as <c>Name.rel</c>,
          in the current working directory, and in any directories
          specified using option <c>path</c>. In the case of <c>sys.config</c>
          it is not included if <c>sys.config.src</c> is found.</p>
        <p>If the release package is to contain a new Erlang runtime
          system, the <c>erts-ErtsVsn/bin</c> directory of the specified runtime
          system <c>{erts,Dir}</c> is copied to <c>erts-ErtsVsn/bin</c>. Some
          erts executables are not copied by default, if you want to include all
          executables you can give the <c>erts_all</c> option.</p>
        <p>All checks with function 
	<seemfa marker="#make_script/1"><c>make_script</c></seemfa>
          are performed before the release package is created.
          Options <c>src_tests</c> and <c>exref</c> are also
          valid here.</p>
        <p>The return value and the handling of errors and warnings
          are the same as described for 
	<seemfa marker="#make_script/1"><c>make_script</c></seemfa>.</p>
      </desc>
    </func>

    <func>
      <name since="">script2boot(File) -> ok | error</name>
      <fsummary>Generates a binary version of a boot script.</fsummary>
      <type>
        <v>File = string()</v>
      </type>
      <desc>
        <p>The Erlang runtime system requires that the contents of
          the script used to boot the system is a binary Erlang term.
          This function transforms the <c>File.script</c> boot script
          to a binary term, which is stored in the <c>File.boot</c>
          file.</p>
        <p>A boot script generated using 
	<seemfa marker="#make_script/1"><c>make_script</c></seemfa>
          is already transformed to the binary form.</p>
      </desc>
    </func>
  </funcs>

  <section>
    <title>See Also</title>
    <p><seefile marker="kernel:app"><c>app(4)</c></seefile>,
      <seefile marker="appup"><c>appup(4)</c></seefile>,
      <seecom marker="erts:erl"><c>erl(1)</c></seecom>,
      <seefile marker="rel"><c>rel(4)</c></seefile>,
      <seeerl marker="release_handler"><c>release_handler(3)</c></seeerl>,
      <seefile marker="relup"><c>relup(4)</c></seefile>,
      <seefile marker="script"><c>script(4)</c></seefile></p>
  </section>
</erlref>
