A service file and a tip for ReSTUNd

I've recently worked on a quite important WebRTC project including live streams, recording, multiroom chat and broadcasting (more on that maybe in following articles), and in the process, I needed a proper STUN server (Session Traversal Utilities for NAT) to be able to ... well, traverse a NAT.

A few options exist, but I settled for restund (http://www.creytiv.com/restund.html) since it includes a TURN implementation as well (which provides a fallback for when the WebRTC stream cannot be exchanged in a pure peer-to-peer manner).

1. Compilation

The installation is straightforward but you might encounter a problem when compiling on Ubuntu or Debian :

error: storage size of 'ts' isn't known

It's mainly due to unavailable POSIX features, and is very easily fixed by changing the Makefile and adding -D_POSIX_C_SOURCE=199309L to the CLFAGS like so :

CFLAGS += -D_POSIX_C_SOURCE=199309L

And then compile normally :

make && sudo make install

2. Service file

While setting up my production environment, I figured I needed a service file to properly launch and restart the restund binary. The culprit being that we need a Type=forking service file to be able to do so :

[Unit]
Description=ReSTUNd Service

[Service]
ExecStart=/usr/local/sbin/restund -f /etc/restund.conf
Type=forking
Restart=on-failure
RestartSec=4
User=root

[Install]
WantedBy=multi-user.target

the configuration file is generally /etc/restund.conf, adapt to your needs