CouchDB as a part of an Erlang release

▼魔方 西西 提交于 2019-12-04 21:12:06

问题


I would like to build and deploy an application which has Django as frontend, YAWS (appmods) or Mochiweb/Webmachine as a backend and CouchDB as a datastore. Furthermore, I plan to extensively use CouchDB's ability to replicate in order to provide high fault tolerance for the whole application.

I tend to think that in order to achieve this, I must create a single OTP release which has YAWS and CouchDB as Erlang/OTP applications.

Does this approach seem to be correct? How can I organize YAWS and CouchDB in terms of OTP applications in order to create a solid production setup? Are there any best practices for doing that?


回答1:


Erlang releases are a good way to package software, because they include all of the dependent libraries. This way, different erlang applications can run different versions of their required libraries without conflicting with each other.

A popular way of dealing with the complicated release process Erlang has is to let Rebar do it for you. They have a quick start guide to get you on the right path. I don't know if you're currently using Rebar to manage your project, but it makes things a lot easier. It is definitely worth looking into if you aren't using it yet.

However, rebar won't include your dependencies right out of the box. In order to do that, you should modify the reltool.config file and all your required applications.

First step is to add the directory where all your dependencies are located, e.g.:

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

Then, add your dependencies as applications to include in the release:

{sys, [
    ...
    {app, jiffy, [{incl_cond, include}]},
    {app, cowboy, [{incl_cond, include}]},
    ...
}.

Now, when you run the rebar generate command, your applications should be in the target directory under lib:

find brawl_server -type d -maxdepth 2

brawl_server
brawl_server/bin
brawl_server/erts-5.9.1
brawl_server/erts-5.9.1/bin
brawl_server/lib
brawl_server/lib/brawl_server-1.1
brawl_server/lib/cowboy-0.6.0
brawl_server/lib/jiffy-0.6.1
brawl_server/lib/kernel-2.15.1
brawl_server/lib/sasl-2.2.1
brawl_server/lib/stdlib-1.18.1
brawl_server/log
brawl_server/log/sasl
brawl_server/releases
brawl_server/releases/1

You also need to make sure your own OTP application knows it needs to start the applications it depends on. If you have a generated Rebar project, modify your <appname>.app.src file to include them:

{application, app, [
    ...
    {applications, [
              jiffy,
              cowboy,
              kernel,
              stdlib
             ]},
    ...
}.

You should be able to compile and generate the release and run it with the included scripts, as laid out in the Rebar release handling article.

At this point, though, there's an added wrinkle, because apparently vanilla CouchDB isn't OTP compliant, and you can't include it this way. There is another distribution you may be able to use, instead: rcouch. I haven't tried it myself, hopefully it will work for you.

Further reading:

  • Learn you some erlang for great good: Releases
  • I used my own project, brawl-online, as an example



回答2:


I would recommend to create DEB/RPM/you-name-it package or packages. CheckInstall is the simplest solution for this.



来源:https://stackoverflow.com/questions/13342741/couchdb-as-a-part-of-an-erlang-release

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!