Search code examples
erlangerlang-otprebar

When to use erlang application:start or included_applications and a supervisor?


I have an Erlang application which has a dependency in its deps directory on another application.

From what I understand I can either;

a) start my dependent application from my including application by calling application:start(some_other_app) which starts the application and shows it running standalone within Observer.

b) include my dependent application in my .app file with {included_applications, [some_other_app]} so that the application is loaded and not started and then start the included application from my own top level supervisor. This again starts the included application and shows its running below my own supervision hierarchy in Observer.

My question is when should I use either approach? If I use option “a” and my dependent application exits will it be restarted or should I be using approach “b” so that any dependencies I have are monitored accordingly?

On a side note I use Rebar to package and manage my dependencies.

Thanks,

Andy.


Solution

  • Having your dependencies declared in your application descriptor is the way to go, so you should use option B in most of the scenarios.

    The application controller will ensure that all your dependencies are present and started (in order) before starting your application and will also make your app fail if those terminate with errors. Also, the application controller will shutdown everything when needed.

    Other than that, if you choose option A, when starting an application with application:start/1, you will get a temporary application by default, so you should use application:start/2, passing the permanent atom as the second argument.

    EDIT: Having your dependencies in the application descriptor also helps visibility, it's easy to know your deps without scanning the source code.