Sync’ up! … without getting drained

nov 8

Erlang/OTP on OpenBSD

Installing OTP on OpenBSD is a pretty painless process, considering OTP is regarded highly as indicated by the fact that several releases of the language are currently offered as first-class packages.

As of OpenBSD 6.3, OTP 19 is available, both with ‘wx’ support, and without.

Although installation is quite simple, there are some things that need tuning in order for Erlang to work properly on OpenBSD.

Handling packages

For the sake of this tutorial, we assume doas has been configured to your liking. But to make the directions terse, we will further assume that ‘root’ is making all the commands.

First, we need to see what versions of OTP are available. We do this as follows:

pkg_info -Q erlang

Among the several versions listed, I’ve gone and chosen ‘erlang-19.3p3v0’ — a version without ‘wx’ support.

After choosing an appropriate version, an install is as easy as follows:

pkg_add erlang

You will be prompted for a version selection if you give ‘erlang’ rather than ‘erlang-19.3p3v0.’

Erlang should now be installed. By running which erl19 one can see the installation path.

Adjusting things

The Erlang Runtime System, or ERTS, will complain if it doesn’t have enough headroom for number of files it can open. The OpenBSD default limits are conservative, and some small changes need to be made to allow ERTS to run.

First, take note of the original ‘maxfiles’ configuration as follows:

sysctl | grep maxfiles

If it yields, say ‘7030,’ then let’s go ahead and double that number in our new configurations (ie. ‘14060’).

We can make this change, as follows:

sysctl kern.maxfiles=14060

In order for our change to persist beyond server restarts, using your favorite editor, add or change ‘/etc/sysctl.conf’ to contain the same setting, as in the following:

...

kern.maxfiles=14060

...

With that, most the installation is complete.

Liberal resources

If you have a user that will be running Erlang often, and perhaps, needing ample resources, it could be advised to set open-file and data settings to a higher threshold.

Still as ‘root,’ append the following (with the backslashes and tabs noted carefully) snippet to ‘/etc/login.conf’ :

erts:\
        :datasize-max=1536M:\
        :datasize-cur=1536M:\
        :openfiles-max=4096

This login-class is now ready to be used for any Erlang user. For example, say Alice (alice) is an Erlang power user. Let’s add her to this new login-class. We do that as follows:

usermod -L erts alice

With that, running erl19 should bring up an Erlang shell without error. In the Erlang shell, you can check all is well as follows:

1> {ok, [crypto]} = application:ensure_all_started(crypto).
2> init:stop().

If there wasn’t any issue, then your OpenBSD server now can freely wield OTP.