4
votes

I'm trying to find some good documentation (book, blog, mailing list etc) on how to properly deploy into a production system with Erlang.

For instance, I have an application that by design should launch three processes of a particular module that takes on the gen_server behavior. When you are starting a production Erlang system, what is the right way of going about this?

  • Manually start them in the erl shell? my_server:start(). %% do this three times? (I hope this is a no.)
  • Let a supervisor handle it? (seems the most likely?)
  • Let the server start itself three times? (I think this is a no.)
  • Let a tool like rebar handle it? (Haven't learned this tool yet, so not sure.)

I'm trying to find some good resource(s) that will explain the right way of going about this in the Erlang world.

1

1 Answers

7
votes

Supervisors are the way to go. You should read up on the docs but a supervisor init like this will boot up three identical children and keep them running:

init([]) ->
  MyChildren =
  [{list_to_atom(ChildName),
    {theworkermodule, start_link, [ChildName]},
    permanent, 1000, worker, [theworkermodule]} || ChildName <- [c1,c2,c3]],
  {ok, {{one_for_one, 5, 10}, MyChildren}} 

You can have your application boot up this supervisor and it will keep your three child gen_servers (defined in theworkermodule.erl) running - and when/if one dies it will restart automatically.