erlang 热更新

说明

依赖于 rebar3 的 appup 插件

步骤

代码

创建项目

1
rebar3 new release demo

rebar.config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
% 编译时配置
{erl_opts, [debug_info]}.
{deps, []}.

% 热更新的插件
{plugins, [rebar3_appup_plugin]}.

{provider_hooks, [
{pre, [{tar, {appup, tar}}]},
{post, [
{compile, {appup, compile}},
{clean, {appup, clean}}]}
]}.

% 发布时配置
% 默认模式的配置
{relx, [
{release, {demo, "1.0.0"}, [
demo,
sasl
]},

{mode, dev},
{sys_config, "./config/sys.config"},
{vm_args, "./config/vm.args"}
]}.

% prod 模式下的特殊配置,其它的配置,从上面的默认模式里面拿
{profiles, [
{prod, [
{relx, [
{mode, prod}
]}
]}
]}.

初始版本

1
2
rebar3 as prod release
rebar3 as prod tar

修改版本号

1
2
rebar.config 里面的 release 版本号
多个 .app.src 里面的 vsn 版本号

构建新版本

原来 build 过的老的 release 不能删除,这个升级插件至少需要两个版本的 release

1
2
3
4
5
6
rebar3 as prod release

# 生成 appup 文件
rebar3 as prod appup generate
rebar3 as prod relup -n demo -v 2.0.0
rebar3 as prod tar

测试

1.0.0 的压缩包先解压,然后运行

1
bin/demo console

一定要注意,新版本的存放目录

1
2
3
4
5
cp ../demo-2.0.0.tar.gz ./releases/
bin/demo upgrade 2.0.0
bin/demo versions
bin/demo attach
application:which_applications().

降级

1
2
bin/demo downgrade 1.0.0
bin/demo uninstall 2.0.0