Use the ".app" file in Erlang?

I have never used .app files for my projects. I understand that they are necessary to download the application through the application module.

Is there any other use for such files?

+7
erlang
source share
2 answers

* .app along with the * .rel file is used to create boot scripts. A boot script is used to automatically launch my application when erlang starts. The application resource file describes which applications should run before starting my application. For example, if I use mnesia and indicate that in the .app file for my application, when I create a boot script and use it to run my application, it will start mnesia for me when I launch my own application.

Although you can automatically install and handle dependencies with other package managers, the boot script is useful for managing dependencies when your application starts, which is important in configuring the OTP application.

note : applications in otp refer to a set of running processes and / or code. Applications can depend on other applications in several ways. Either they require the code to be installed, or they require the application to run.

+11
source share

They are used to create releases (using * .rel to create download scripts). I recommend only starting with the * .app file and the application behavior callback. Regarding getting started with OTP. This is a nice place to develop:

 -module(foo). -export([start/0]). start() -> [application:start(A) || A <- [sasl, inets, x, y, etc]]. 

to run all applications that depend on starting your application with a simple

 $ erl -s foo 
  • If your project will be used as a service or structure for other projects, another advantage is that these Erlang applications can in turn depend on your application or include it. An Erlang application is a device in which you can provide services and even libraries (stdlib is a library, "moving parts", only library modules).
  • As an Erlang application, you get an easy way to pass configuration settings to your application. When you pass -mnesia dir '"/some/path"' to erl, it is accessed by the mnesia application:get_env(mnesia, dir) as application:get_env(mnesia, dir) . If you define an application called foo , you can pass -foo key 'some-Erlang-literal' to erl. The * .app file may contain default values ​​in the env section, the * .rel file overrides them, and the command line overrides this.
  • There are sections in the * .app file that list the modules and registered processes that your application enters. This is used when creating releases to ensure that there are no collisions between applications.

Some additional features of Erlang applications that I know little about:

  • Launch Phases. Used for applications that have complex startup tasks, for example, "partially launched" for a while.
  • Distributed applications. Used to determine where the application should run in the cluster.
  • takeovers. Used to release a machine from a distributed application, for example, when maintenance or updating is required.

In the end, you will begin to want to start your application suite in a more structured way, and that is when the entire / boot - script release becomes more understandable. Or vice versa, you will think that it is unnecessary for you specific needs. Just start with a simple * .app and application callback module. You do not look back.

+8
source share

All Articles