erlang otp 應用發佈指南(三) tiny-3.0

tiny-3.0

最後,讓我們彌補前面tiny-2.0的缺憾, 我們要開發tiny-3.0. tiny-3.0中我們不會在重啓application, 我們這次 讓Application溫和的不間斷的完成升級.

 

這裏我假設你已經看懂前面的部分,並且親自動手做了很多嘗試. 下面是快速,直白的代碼羅列..

代碼修改

新建tiny-3.0目錄,添加一個module: mydict.erl 採用我們自定義的dict代替stdlib dict, 修改tiny_server, 使其加入一個last mofiy信息(最後修改時間), 添加一個supervisor child, 其定期的顯示當前應用的狀態.

 

代碼可以從後面的附件下載。

 

tiny-3.0.erl

下面是我們的tiny-3.0.rel:

 

{release, {"tiny app release", "3.0"}, {erts, "5.6.5"},
   [{kernel, "2.12.5"},
    {stdlib, "1.15.5"},
    {sasl, "2.1.5.4"},
    {tiny_app, "3.0"}
   ]}.

tiny_app.appup

下面是我們的tiny_app.appup:

 

{"3.0",
   [{"1.0", [{restart_application, tiny_app}]},
   {"2.0", [{add_module, mydict},
                {update, tiny_server, {advanced, []}},
                {update, tiny, supervisor},
                {apply, {supervisor, restart_child, [tiny_sup, tiny_reporter]}}
             ]}
   ],

   [{"1.0", [{restart_application, tiny_app}]},
    {"2.0", [{apply, {supervisor, terminate_child, [tiny_sup, tiny_reporter]}},
               {apply, {supervisor, delete_child, [tiny_sup, tiny_reporter]}},
               {update, tiny, supervisor},
               {update, tiny_server, {advanced, []}},
               {delete_module, mydict}
             ]}
   ]
}.

生成relup

代碼:

[da6600a1@litaocheng ~/install/tiny-3.0]$ erl -boot start_sasl -pa ./ebin/
 ../tiny-1.0/ ../tiny- 1.0/ebin/ ../tiny-2.0/ ../tiny-2.0/ebin/
1> systools:make_relup("tiny-3.0", ["tiny-1.0", "tiny-2.0"], ["tiny-1.0", "tiny-2.0"]).
ok
2> systools:make_script("tiny-3.0").
ok
3> systools:make_tar("tiny-3.0").
ok

 

隨後參照前面部分完成release

命令彙總

上面的章節,比較瑣碎,凌亂。讓我們最後來個彙總, 部署tiny及多個版本之間的upgrade和downgrade。

 

1) 在 /opt/local/tiny/ 目錄安裝 tiny-1.0

[da6600a1@litaocheng ~/install/tiny-1.0]$ erl -pa ../ ./ebin/
Erlang (BEAM) emulator version 5.6.5 [source] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.6.5  (abort with ^G)
1> target_system:create("tiny-1.0").
Reading file: "tiny-1.0.rel" ...
Creating file: "plain.rel" from "tiny-1.0.rel" ...
Making "plain.script" and "plain.boot" files ...
Making "tiny-1.0.script" and "tiny-1.0.boot" files ...
Creating tar file "tiny-1.0.tar.gz" ...
Creating directory "tmp" ...
Extracting "tiny-1.0.tar.gz" into directory "tmp" ...
Deleting "erl" and "start" in directory "tmp/erts-5.6.5/bin" ...
Creating temporary directory "tmp/bin" ...
Copying file "plain.boot" to "tmp/bin/start.boot" ...
Copying files "epmd", "run_erl" and "to_erl" from
"tmp/erts-5.6.5/bin" to "tmp/bin" ...
Creating "tmp/releases/start_erl.data" ...
Recreating tar file "tiny-1.0.tar.gz" from contents in directory "tmp" ...
Removing directory "tmp" ...
ok
2> target_system:install("tiny-1.0", "/opt/local/tiny").
Extracting tiny-1.0.tar.gz ...
Substituting in erl.src, start.src and start_erl.src to
form erl, start and start_erl ...
Creating the RELEASES file ...
ok

 

2) 運行 tiny-1.0 (假設爲Shell A)

 

[da6600a1@litaocheng /opt/local/tiny]$ ./bin/erl -boot ./releases/1.0/start -sname tiny
....
Eshell V5.6.5  (abort with ^G)
(tiny@da6600a1)1> tiny_app 1.0 running...
tiny_app 1.0 running...

 

3) 生成tiny-2.0的relup文件,及release tar

 

[da6600a1@litaocheng ~/install/tiny-2.0]$ erl -pa ../tiny-1.0/ ../tiny-1.0/ebin/ ./ebin/
Erlang (BEAM) emulator version 5.6.5 [source] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.6.5  (abort with ^G)
1> systools:make_relup("tiny-2.0", ["tiny-1.0"], ["tiny-1.0"]).
ok
2> systools:make_script("tiny-2.0").
ok
3> systools:make_tar("tiny-2.0").
ok

 

4) 生成tiny-3.0的relup文件,及release tar

 

[da6600a1@litaocheng ~/install/tiny-3.0]$ erl -boot start_sasl -pa ./ebin/ ../tiny-1.0/ ../tiny-1.0/ebin/
 ../tiny-2.0/ ../tiny-2.0/ebin/
...
Eshell V5.6.5  (abort with ^G)
1>  systools:make_relup("tiny-3.0", ["tiny-1.0", "tiny-2.0"], ["tiny-1.0", "tiny-2.0"]).
ok
2> systools:make_script("tiny-3.0").
ok
3> systools:make_tar("tiny-3.0").
ok

 

5) 將 tiny-2.0.tar.gz 和 tiny-3.0.tar.gz拷貝到部署目標: /opt/local/tiny/ 的releases目錄

 

[da6600a1@litaocheng ~/install]$ cp ./tiny-2.0/tiny-2.0.tar.gz /opt/local/tiny/releases/
[da6600a1@litaocheng ~/install]$ cp ./tiny-3.0/tiny-3.0.tar.gz /opt/local/tiny/releases/

 

6) tiny 1.0 升級到tiny 2.0

 

啓動一個新的erl shell
[da6600a1@litaocheng ~]$ erl -sname install
Erlang (BEAM) emulator version 5.6.5 [source] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.6.5  (abort with ^G)
(install@da6600a1)1>  %  按下 CTRL + G
User switch command
 --> r tiny@da6600a1 shell % 在運行tiny-1.0的node中創建shell
 --> j   % 顯示所有的可連接shell
  1  {shell,start,[init]}
  2* {tiny@da6600a1,shell,start,[]}
--> c 2  % 連接tiny@da6600a1
Eshell V5.6.5  (abort with ^G)
(tiny@da6600a1)1> application:which_applications().
[{tiny_app,"tiny app","1.0"},
 {sasl,"SASL  CXC 138 11","2.1.5.4"},
 {stdlib,"ERTS  CXC 138 10","1.15.5"},
 {kernel,"ERTS  CXC 138 10","2.12.5"}]
(tiny@da6600a1)2> release_handler:unpack_release("tiny-2.0"). % 解壓 tiny-2.0.tar.gz
{ok,"2.0"}
(tiny@da6600a1)3> release_handler:install_release("2.0"). % 安裝 tiny-2.0
{ok,"1.0",[]}
(tiny@da6600a1)4> release_handler:make_permanent("2.0"). % 使tiny-2.0成爲默認版本
ok

此時看到Shell A中變化:
 tiny_app 1.0 running...

=INFO REPORT==== 9-Mar-2009::13:56:58 ===
   application: tiny_app
   exited: stopped
   type: permanent

=PROGRESS REPORT==== 9-Mar-2009::13:56:58 ===
         supervisor: {local,tiny_sup}
            started: [{pid,<0.68.0>},
                      {name,tiny_server},
                      {mfa,{tiny_server,start_link,[]}},
                      {restart_type,permanent},
                      {shutdown,10},
                      {child_type,worker}]

=PROGRESS REPORT==== 9-Mar-2009::13:56:58 ===
        application: tiny_app
         started_at: tiny@da6600a1
tiny_app 2.0 running ....
tiny_app 2.0 running ....

 

7) tiny 2.0升級到 tiny 3.0

 

(tiny@da6600a1)5> release_handler:unpack_release("tiny-3.0"). % 解壓 tiny-3.0.tar.gz
{ok,"3.0"}
(tiny@da6600a1)6> release_handler:install_release("3.0").    % 安裝 tiny-3.0
{ok,"2.0",[]}
(tiny@da6600a1)7> release_handler:make_permanent("3.0").    % 使tiny-3.0成爲默認版本
ok

`此時看到Shell A中變化:`
tiny_app 2.0 running ....
tiny_server code change: from 1.0 to 2.0

=PROGRESS REPORT==== 9-Mar-2009::14:00:18 ===
         supervisor: {local,tiny_sup}
            started: [{pid,<0.78.0>},
                      {name,tiny_reporter},
                      {mfa,{tiny_reporter,start_link,[]}},
                      {restart_type,permanent},
                      {shutdown,10},
                      {child_type,worker}]
tiny_app 3.0 running ...
tiny_app 3.0 running ...

 

至此對於release hanlding相信,你應該比較熟悉了吧。 請參照附件中的代碼,動手實驗一下。如有錯誤,歡迎指正。

 

8) tiny 3.0回退到 tiny 2.0

(tiny@da6600a1)8> release_handler:install_release("2.0").
{ok,"2.0",[]}

此時看到Shell A中變化:
tiny_app 3.0 running ...
tiny_server code change: from 2.0 to 1.0

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章