使用erlang开发服务端の使用rebar生成release

继续使用之前的game_server做例子(加入了简易登陆的原型),具体参考:http://blog.csdn.net/huang1196/article/details/38401197

下载见最后。


参考:https://github.com/rebar/rebar/wiki/Release-handling


1. 因为我们的项目已经是按照otp设计原则建立,所以可以省去rebar create-app 这步。

2. 

mark@localhost:~/eclipse-erlang/workspace/game_demo$ mkdir rel
mark@localhost:~/eclipse-erlang/workspace/game_demo$ cd rel
mark@localhost:~/eclipse-erlang/workspace/game_demo/rel$ ../rebar create-node nodeid=game_server
==> rel (create-node)
Writing reltool.config
Writing files/erl
Writing files/nodetool
Writing files/game
Writing files/app.config
Writing files/vm.args

3. 编辑reltool.config

注意因为使用到了deps里面的ranch,所以使用

{lib_dirs, ["../deps"]}

{sys, [
       {lib_dirs, ["../deps"]},
       {rel, "game_server", "1",
        [
         kernel,
         stdlib,
         sasl,
         ranch,
         game_server
        ]},
       {rel, "start_clean", "",
        [
         kernel,
         stdlib
        ]},
       {boot_rel, "game_server"},
       {profile, embedded},
       {excl_sys_filters, ["^bin/.*",
                           "^erts.*/bin/(dialyzer|typer)"]},
       {app, sasl, [{incl_cond, include}]},
       {app, ranch, [{incl_cond, include}]},
       {app, game_server, [{mod_cond, app}, {incl_cond, include}, {lib_dir, ".."}]}
      ]}.

{target_dir, "game_server"}.

{overlay, [
           {mkdir, "log/sasl"},
           {copy, "files/erl", "{{erts_vsn}}/bin/erl"},
           {copy, "files/nodetool", "{{erts_vsn}}/bin/nodetool"},
           {copy, "files/game_server", "bin/game_server"},
           {copy, "files/app.config", "etc/app.config"},
           {copy, "files/vm.args", "etc/vm.args"}
           ]}.


4. 修改game_demo目录下的rebar.config

添加

{sub_dirs, ["rel"]}.


5.

mark@localhost:~/eclipse-erlang/workspace/game_demo$ ./rebar compile generate
==> ranch (compile)
==> rel (compile)
==> game_demo (compile)
==> rel (generate)

6. 去运行吧!

mark@localhost:~/eclipse-erlang/workspace/game_demo$ cd rel/game_server/bin
mark@localhost:~/eclipse-erlang/workspace/game_demo/rel/game_server/bin$ ./game_server start
mark@localhost:~/eclipse-erlang/workspace/game_demo/rel/game_server/bin$ ./game_server attach
Attaching to /tmp//home/mark/eclipse-erlang/workspace/game_demo/rel/game_server/erlang.pipe.1 (^D to exit)

(game_server@127.0.0.1)1> application:which_applications().
[{game_server,"Ranch TCP reverse example.","1"},
 {ranch,"Socket acceptor pool for TCP protocols.","1.0.0"},
 {sasl,"SASL  CXC 138 11","2.3.2"},
 {stdlib,"ERTS  CXC 138 10","1.19.2"},
 {kernel,"ERTS  CXC 138 10","2.16.2"}]
(game_server@127.0.0.1)2> client:send(<<>>).
#Port<0.754>
Data:<<1,0,1,6,77,97,114,107,95,104,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
       0,0,0,112,97,115,115,119,111,114,100>>
{<<1,0,1,6,77,97,114,107,95,104,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
   0,112,97,115,115,119,111,114,100>>,
 {tcpstat,#Port<0.755>,ranch_tcp,<<>>,<<>>}}
{1,85080926805864,8097880544751088228,<<>>}
{1,<<"Mark_h">>,
 <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,112,97,115,115,119,111,114,
   100>>}
Client received = <<"Mark_h">>
ok


相对于使用demo中的start.sh启动,这种方法的一个好处就是可以很方便地使用./game_server attach调出console。



demo及其release已经打包,点击下载










  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值