Elixir:如何利用release_handler? [英] Elixir: how can I leverage release_handler?

查看:88
本文介绍了Elixir:如何利用release_handler?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有exrm之类的项目可以为您做到这一点,而且看起来做得非常好。但是,出于教育目的,我想手动与release_handler一起玩,而我找不到关于该主题的文档或文章。

I know there are projects such as exrm which do that for you, and it seem to do it extremely well. However, I would like to manually play with release_handler for educational purposes, and I find little documentation or articles on the subject.

推荐答案

您是否已阅读了解有关发布处理的一些Erlang文章

使用发布处理程序进行升级既容易又困难。这很容易,因为一旦您了解所有细节,它几乎是自动的。但是很困难,因为首先要弄清所有细节是一项艰巨的任务。

Doing upgrades with release handler is both easy and difficult. Easy because once you know all the nitty gritty details it's pretty much automatic. But difficult, because getting all the details right in the first place is quite a task.

我花了很多时间试图了解如何正确完成流程,效果是 builderl ,一种构建系统,类似于钢筋,但从头到尾都要做 OTP方式

I spent quite a lot of time trying to understand how to get the process right and the effect is builderl, a build system, something like rebar, but doing everything from start to finish the OTP way.

如果您使用的是Elixir,可能用处不大,而且我对Elixir的处理过程不怎么了解。但是,我可以为您提供一些与Erlang相关的观点,您可以尝试调整以适应您的情况(在 builderl 的情况下,因为这样我可以分享一些代码示例)。

It's probably not of much use if you are using Elixir, and I don't know much about how the process differs for Elixir. But I can give you a few points that were relevant for Erlang, which you can try to adapt to your case (in the context of builderl, as that will allow me to share some code examples).

在一般的过程如下:


  1. 创建初始版本。这是使用 systools 处理的项目的编译版本。 code> reltool 包含发布处理程序期望的所有文件夹和文件。这是 builderl tmp / rel 中为 gmake rel 。这是一个独立的文件夹,也称为嵌入式Erlang 安装。

  1. Create the initial release. This is a compiled version of your project processed with systools and reltool that contains all the folders and files as release handler expects them to be. This is what builderl creates in tmp/rel for gmake rel. It's a self-contained folder also called an embedded Erlang installation. More about it later.

将发行版复制到生产系统,安装并启动节点。

Copy the release to the production system, install and start the node.

在您的开发环境中,对版本中运行的一个或多个应用程序进行一些更新。

In your development environment make some updates to one or more of the applications running in the release.

为每个应用程序创建一个新版本已经改变。为这些文件创建适当的 appup 文件应用程序。增加发行版本。

Create a new version of each application that has changed. Create appropriate appup files for those applications. Increase the release version.

创建 relup 文件和 systools 。最简单的方法是将两个发行版本相互解包,然后安装并运行较新的版本。然后,在新版本的Erlang Shell中,调用 make_relup 从发行版的旧版本中引用旧版本的应用程序(请参见答案底部的摘录)。

Create the relup file with systools. The easiest way is to have two release versions unpacked alongside each other and the newer version installed and running. Then in the Erlang shell of the new version call make_relup referencing the old version of applications from the old version of the release (see snippets at the bottom of the answer).

创建升级档案。这只是所有已升级的应用程序,releases文件夹和发行版定义文件(同样在底部的摘要)的压缩文件。

Create the upgrade archive. This is simply a tarball of all applications that have been upgraded, the releases folder, and the release definition file (again snippets at the bottom).

复制将存档升级到生产系统,并使用 release_handler:unpack_release /解压缩1 。这将在发行文件夹的 lib 文件夹中解压缩应用程序的新版本和旧版本。

Copy the upgrade archive to the production system and unpack with release_handler:unpack_release/1. This will unpack the new versions of your applications alongside the old versions in the lib folder of the release folder.

然后最后使用 release_handler:install_release安装新版本/ 1

Then finally install the new version with release_handler:install_release/1.






< h1>发布

要使用发布处理程序,必须以特定方式构造代码。 发布文档指定了发布文件夹的外观。 humbundee 应用程序就是一个示例,这里是 builderl 对其进行编译,并使用 systools (在 tmp / rel 中):


A release

In order to use release handler the code must be structured in a specific way. The Releases document specifies how a release folder should look like. The humbundee application is an example and here are its folders once builderl compiles it and creates the release using systools (in tmp/rel):

> tmp/rel/
bin/
erts-7.2.1/
etc/
lib/
releases/

文件夹如下:

包含应用程序的主文件夹。每个应用程序可能没有版本后缀( -Vsn ),或者同一应用程序的所有版本都必须具有后缀。您不能混合应用程序文件夹,其中一些文件夹包含版本后缀,而有些文件夹不包含版本后缀。

Main folder with applications. Each application may be either without the version suffix (-Vsn) or all versions of the same applications have to have the suffix. You can't mix application folders where some of them contain the version suffix and some don't.

但是在使用发布处理程序进行升级时,所有文件夹都必须具有正确的 -Vsn 后缀,否则升级没有意义-升级是在应用程序的版本之间进行的,而Erlang则通过应用程序文件夹名称中的后缀来区分版本。

But when doing upgrades with release handler all folders must have a proper -Vsn suffix, otherwise upgrades don't make sense - upgrades are between versions of applications and Erlang distinguishes the versions by the suffix in the application's folder name.

> l tmp/rel/lib/
builderl-0.2.7/
compiler-6.0.2/
deploy-0.0.1/
goldrush-0.1.7/
humbundee-0.0.1/
kernel-4.1.1/
lager-3.0.1/
mnesia-4.13.2/
sasl-2.6.1/
stdlib-2.7/
syntax_tools-1.7/
yajler-0.0.1/
yolf-0.1.1/



erts-Vsn



通常,这是安装Erlang的 erts 文件夹(在我的 /usr/local/lib/erlang/erts-7.2.1

包含文件定义发布。每个文件的创建方式稍有不同。

Contains files that define the release. Each file is created slightly differently.

> l tmp/rel/releases/
RELEASES
hbd-0.0.1/
start_erl.data
humbundee.rel

> cat release/RELEASES

[{release,"humbundee","hbd-0.0.1","7.2.1",
          [{kernel,"4.1.1","/usr/home/g/work/humbundee/lib/kernel-4.1.1"},
           {stdlib,"2.7","/usr/home/g/work/humbundee/lib/stdlib-2.7"},
           {sasl,"2.6.1","/usr/home/g/work/humbundee/lib/sasl-2.6.1"},
           {yolf,"0.1.1","/usr/home/g/work/humbundee/lib/yolf-0.1.1"},
           {yajler,"0.0.1","/usr/home/g/work/humbundee/lib/yajler-0.0.1"},
           {mnesia,"4.13.2","/usr/home/g/work/humbundee/lib/mnesia-4.13.2"},
           {syntax_tools,"1.7",
                         "/usr/home/g/work/humbundee/lib/syntax_tools-1.7"},
           {compiler,"6.0.2","/usr/home/g/work/humbundee/lib/compiler-6.0.2"},
           {goldrush,"0.1.7","/usr/home/g/work/humbundee/lib/goldrush-0.1.7"},
           {lager,"3.0.1","/usr/home/g/work/humbundee/lib/lager-3.0.1"},
           {humbundee,"0.0.1",
                      "/usr/home/g/work/humbundee/lib/humbundee-0.0.1"}],
          permanent}].

> cat releases/start_erl.data
7.2.1 hbd-0.0.1

> cat tmp/rel/releases/humbundee.rel
%% rel generated at {2016,3,24} {11,9,39}
{release,{"humbundee","hbd-0.0.1"},
         {erts,"7.2.1"},
         [{kernel,"4.1.1"},
          {stdlib,"2.7"},
          {sasl,"2.6.1"},
          {yolf,"0.1.1"},
          {yajler,"0.0.1"},
          {mnesia,"4.13.2"},
          {syntax_tools,"1.7"},
          {compiler,"6.0.2"},
          {goldrush,"0.1.7"},
          {lager,"3.0.1"},
          {humbundee,"0.0.1"}]}.

> l tmp/rel/releases/hbd-0.0.1/
builderl.config
cmd.boot
cmd.data
cmd.rel
cmd.script
hbd.config
humbundee.boot
humbundee.data
humbundee.rel
humbundee.script
start.boot -> humbundee.boot
sys.config -> hbd.config
sys.config.src -> ../../etc/sys.config.src

这些文件由<$自动创建c $ c> builderl ,它随后在Release Handler的帮助下生成它们:

Those files are created automatically by builderl, which in turn generates them with the help of Release Handler:

释放

包含系统上当前可用的当前和过去发行版的定义。可以使用 release_handler:create_RELEASES / 4 创建。 builderl 通过使用此命令启动节点来创建它(该命令运行该命令并随后关闭该节点):

Contains the definitions of current and past releases currently available on the system. Can be created with release_handler:create_RELEASES/4. builderl creates it by starting a node with this command (which runs the command and shuts down the node afterwards):

run_erl -daemon ../hbd/shell/ ../hbd/log "exec erl ../hbd releases releases/start_erl.data -config releases/$APP_VSN/hbd.config -args_file ../hbd/etc/vm.args -boot releases/$APP_VSN/humbundee -noshell -noinput -eval \"{ok, Cwd} = file:get_cwd(), release_handler:create_RELEASES(Cwd, \\\"releases\\\", \\\"releases/$APP_VSN/humbundee.rel\\\", []), init:stop()\""

start_erl.data

可以手动创建

humbundee.rel

包含版本的定义-哪些应用程序应包含在发布哪个版本。可以手动创建它,但是很难跟踪应用程序的版本。因此,通常是从更通用的文件生成的。如果是 builderl ,它.rel 文件reltool.config rel = nofollow> reltool.config 文件基于这些 reltool 示例

Contains a definition of a release - which applications should be included in the release in which versions. It can be created manually but it's difficult to keep track of the application versions. So, very often it's generated from a more generic file. In case of builderl it generates the .rel file from a reltool.config file based on these reltool examples.

包含指向发行版的Erlang可执行文件,脚本和启动文件的链接。如果是 builderl ,它们只是从Erlang安装中复制

Contains links to Erlang executables, script and boot files for releases. In case of builderl they are simply copied from the Erlang installation.

> l tmp/rel/bin/
builderl -> ../lib/builderl-0.2.7
config.esh -> builderl.esh
configure.esh -> builderl.esh
deps.esh -> builderl.esh
init.esh -> builderl.esh
migresia.esh -> builderl.esh
mk_dev.esh -> builderl.esh
mk_rel.esh -> builderl.esh
start.esh -> builderl.esh
stop.esh -> builderl.esh
update_root_dir.esh -> builderl.esh
builderl.esh
ct_run
epmd
erl
escript
run_erl
to_erl
start
cmd.boot
humbundee.boot
start_clean.boot
start_sasl.boot
start.boot
start.script

.esh 文件属于 builderl ,因此您可以跳过它们。可执行文件是从 / usr / local / lib / erlang / bin / 复制的(取决于系统-我正在使用FreeBSD)。 start * boot script 文件也从 / usr / local / lib / erlang / bin / cmd.boot humbundee。引导只需从 tmp / rel / releases / hbd-0.0.1 / 复制即可。

The .esh files belong to builderl so you can skip them. The executables are copied from /usr/local/lib/erlang/bin/ (which is system dependent - I am using FreeBSD). The start* boot and script files are also copied from /usr/local/lib/erlang/bin/ and cmd.boot and humbundee.boot are simply copied from tmp/rel/releases/hbd-0.0.1/.

builderl 用于存储配置文件,而不是OTP发布处理程序所需要的。

Used by builderl to store configuration files, not required by OTP release handler.

最后一些代码段可以帮助您使用发行工具:

Finally some code snippets to help you work with the release tools:

创建一个将发行版本1.1.1升级到9.9.9的relup文件(在具有旧发行版本的版本中运行,请参见答案顶部的鸟瞰图):

Create a relup file that upgrades release version 1.1.1 to 9.9.9 (run in the version having the old version of the release alongside, see The bird's view at the top of the answer):

systools:make_relup("releases/rel-9.9.9/my_release", ["../1.1.1/releases/rel-1.1.1/my_release"], ["../1.1.1/releases/rel-1.1.1/my_release"], [{path, ["../1.1.1/lib/lager-2.6/ebin", "../1.1.1/lib/backup_app-1.1.2/ebin", "../1.1.1/lib/goldrush-2.5/ebin"]}, {outdir, "releases/rel-9.9.9"}]).

创建一个将两个发行版本1.1.1和2.2.2升级到9.9.9的relup文件

Create a relup file that upgrades two release versions, 1.1.1 and 2.2.2 to 9.9.9

systools:make_relup("releases/rel-9.9.9/my_release", ["../1.1.1/releases/rel-1.1.1/my_release", "../2.2.2/releases/rel-2.2.2/my_release"], ["../1.1.1/releases/rel-1.1.1/my_release", "../2.2.2/releases/rel-2.2.2/my_release"], [{path, ["../1.1.1/lib/lager-2.6/ebin", "../2.2.2/lib/lager-2.4/ebin", "../1.1.1/lib/backup_app-1.1.2/ebin", "../2.2.2/lib/other_app-1.1/ebin"]}, {outdir, "releases/rel-9.9.9"}]).

手动创建发行升级包

tar -czf update_to_rel-9.9.9.tar.gz releases/my_release.rel releases/rel-9.9.9 lib/lager-2.6.1 lib/builderl-0.2.6 lib/deploy-0.4.2 lib/backup_app-2.0.0 lib/other_app-2.5.3

解压缩发行版升级软件包(已复制到生产节点上发行版中的 releases 文件夹之后):

Unpack the release upgrade package (after it has been copied to the releases folder in the release on the production node):

release_handler:unpack_release("rel-9.9.9").

验证版本已解压-新版本应标记为解压

Verify the release has been unpacked - the new version should be marked as unpacked:

release_handler:which_releases().

安装新版本:

release_handler:install_release("rel-9.9.9").

在按预期方式工作后将其永久保存:

Make it permanent once it's working as expected:

release_handler:make_permanent("rel-9.9.9").

回滚版本:

release_handler:install_release("rel-1.1.1").
release_handler:remove_release("rel-1.1.1").

这篇关于Elixir:如何利用release_handler?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆