Systemd - Erlang library for communicating with (surprise) systemd

There are still some bugs there and here (mostly in biggest part of the repo which is systemd_journal_formatter) with fixes on master (I will publish 0.3.3 soon).

Additionally I have finally got socket activation working. Unfortunately due to ERL-1138 the passed FDs can be used only in UNIX sockets (as these do not bind(3) and this is the culprit there), so I just have done some “socket jumping” and translate TCP port to UNIX Stream socket and then to the Cowboy.

So in other words there are 5 systemd units:

  • example-application.service - which is THE application service file, it will just simply run the application when started
  • example-application.socket - UNIX Stream socket definition that will be handled by systemd, this is required due to the above bug; this will start example-application.service on any connection incoming
  • example-activation.service - service that will take the systemd activated FD and forward all it all to another socket provided as an argument, think. of it as an alternative implementation of socat
  • example-activation.socket - definition of TCP socket that systemd will listen on and will pass it down when there will be any request incoming
  • example.target - simple target for ease of use

Within the application the magic happens there:

It creates new gen_tcp socket from the provided file descriptor and then pass it to the Ranch (via Cowboy). The only problem is that currently each first request (when service is down) will fail with no response sent, but all consecutive requests will work as expected.

2 Likes