In the past week, I’ve been bundling one of my Erlang projects into an OTP release. I struggled a bit using rebar, so I thought I’d put my notes in a blog post and share what I did. I created a simple test project to learn the framework. One of my projects dependencies is the lager application for logging. Therefore, my test project also had a dependency on lager.
I called my test project esempio and posted it on GitHub: esempio
Create esempio application
I used rebar to create the initial application skeleton files:
I added a gen_server module, esempio_server.erl which is supervised by esempio_sup.erl and contains some lager log statements.
I created a rebar.config file and added a dependency for lager along with its required erl_opts (see lager project for details). I added the ‘rel’ subdirectory so rebar knows to check it. I also added a statement to require OTP version R15 since some of the release configuration statements I’m using require it.
I added lager as a dependency in the application resource file: esempio.app.src. This will prevent the esempio application from starting until lager is running.
esempio.app.src file (excerpt)
I used rebar to resolve the lager dependency and pull its application code into the deps subdirectory:
Create esempio release
I used the same name for the release as I did for the main application which is perfectly acceptable. I used rebar to create the OTP release skeleton files:
I made the following changes to the generated files:
- Removed the *.cmd files since I won’t be installing on windows
- Removed the install_upgrade.escript (don’t need it now)
- Renamed sys.config to app.config (just my personal preference)
I edited the rel/reltool.config file and made the following changes:
- Added deps directory to lib_dirs parameter
- Added lager application dependency to rel section
- Added project root relative directory (“..”) to esempio application lib_dir parameter
- Added inclusion statement for lager application
- Added exclusion statement for hipe application
- Removed incl_cond parameter since it’s set to default value (derived)
- Removed mod_cond parameter since we want it set to default value (all)
- Changed ‘log/sasl’ directory to just ‘log’ directory
- Renamed sys.config to app.config and changed to install to etc directory
- Removed copy statements of previously deleted files (*.cmd and install_upgrade.escript)
I edited the rel/files/app.config file and made the following changes:
- Disable sasl logging
- Add lager configuration
- Add esempio configuration
Esempio configuration parameters can be accessed like this example from esempio_server module.