coturn: new package

This is meant as a replacement for restund.

By default, sqlite3 support is enabled. The DBs to use can be freely
changed in menuselect, though. sqlite3 is enabled by default as it is
the upstream default DB.

The package installs turnserver, which includes an init script. Options
can be set via /etc/config/turnserver and /etc/turnserver.conf.

turnserver is started as root and later drops privileges to user/group
turnserver/turnserver.

DB schemas etc. get installed to /usr/share/coturn. The default DB path
is set to /etc/turnserver, to avoid volatile /var on OpenWrt.
/etc/turnserver is created and permissions are automatically set to only
allow access for user turnserver (done via fakeroot).

The utilities coturn provides are installed as well.

Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
This commit is contained in:
Sebastian Kemper 2021-12-07 00:30:04 +01:00
parent 5ee7928640
commit ceec95d92d
6 changed files with 222 additions and 0 deletions

143
net/coturn/Makefile Normal file
View File

@ -0,0 +1,143 @@
#
# Copyright (C) 2021 Sebastian Kemper <sebastian_ml@gmx.net>
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=coturn
PKG_VERSION:=4.5.2
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/coturn/coturn/tar.gz/$(PKG_VERSION)?
PKG_HASH:=462f1aa5c2455f28c1c8df09510d9e88ab14a1159b5e33ea5be5095262e83745
PKG_LICENSE:=BSD-COTURN-CITRIX COMBINED-CITRIX-VIVOCHA-BSD MIT-HASH
PKG_LICENSE_FILES:=LICENSE src/apps/relay/dbdrivers/* src/server/ns_turn_khash.h
PKG_MAINTAINER:=Jiri Slachta <jiri@slachta.eu>, Sebastian Kemper <sebastian_ml@gmx.net>
PKG_BUILD_PARALLEL:=1
PKG_INSTALL:=1
PKG_CONFIG_DEPENDS+= \
CONFIG_COTURN_ENABLE_MYSQL \
CONFIG_COTURN_ENABLE_POSTGRESQL \
CONFIG_COTURN_ENABLE_REDIS \
CONFIG_COTURN_ENABLE_SQLITE
PKG_CPE_ID:=cpe:/a:coturn_project:coturn
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
define Package/coturn
TITLE:=coturn TURN and STUN Server
CATEGORY:=Network
SECTION:=net
SUBMENU:=Telephony
URL:=https://github.com/coturn/coturn
USERID:=turnserver=379:turnserver=379
DEPENDS := \
+libevent2 \
+libevent2-extra \
+libevent2-pthreads \
+libevent2-openssl \
+libopenssl \
+COTURN_ENABLE_MYSQL:libmariadb \
+COTURN_ENABLE_POSTGRESQL:libpq \
+COTURN_ENABLE_REDIS:libhiredis \
+COTURN_ENABLE_SQLITE:libsqlite3
FILE_MODES:=/etc/turnserver:turnserver:turnserver:0750
endef
define Package/coturn/conffiles
/etc/config/turnserver
/etc/init.d/turnserver
/etc/turnserver.conf
endef
define Package/coturn/config
menu "coturn configuration"
depends on PACKAGE_coturn
config COTURN_ENABLE_SQLITE
bool "SQLite support"
default y
help
Enable SQLite support
config COTURN_ENABLE_MYSQL
bool "MySQL support"
default n
help
Enable MySQL support
config COTURN_ENABLE_POSTGRESQL
bool "PostgreSQL support"
default n
help
Enable PostgreSQL support
config COTURN_ENABLE_REDIS
bool "Redis support"
default n
help
Enable Redis support
endmenu
endef
define Package/coturn/description
The TURN Server is a VoIP media traffic NAT traversal server and
gateway. It can be used as a general-purpose network traffic TURN server
and gateway, too.
endef
define Package/coturn/install
$(INSTALL_DIR) \
$(1)/etc/{config,init.d,turnserver} $(1)/usr/{bin,share/coturn}
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/etc/turnserver.conf.default \
$(1)/etc/turnserver.conf
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/turn* $(1)/usr/bin
$(INSTALL_BIN) ./files/turnserver.init \
$(1)/etc/init.d/turnserver
$(INSTALL_CONF) ./files/turnserver.conf \
$(1)/etc/config/turnserver
ifneq ($(CONFIG_COTURN_ENABLE_MYSQL)$(CONFIG_COTURN_ENABLE_POSTGRESQL)$(CONFIG_COTURN_ENABLE_SQLITE),)
$(INSTALL_DATA) \
$(PKG_INSTALL_DIR)/usr/share/coturn/{schema,testsqldbsetup}.sql \
$(1)/usr/share/coturn
endif
ifneq ($(CONFIG_COTURN_ENABLE_REDIS),)
$(INSTALL_DATA) \
$(PKG_INSTALL_DIR)/usr/share/coturn/schema.{stats,userdb}.redis \
$(1)/usr/share/coturn
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/share/coturn/testredisdbsetup.sh \
$(1)/usr/share/coturn
endif
endef
CONFIGURE_ARGS+= \
--disable-rpath \
--schemadir=/usr/share/coturn \
--turndbdir=/etc/turnserver
CONFIGURE_VARS+= \
TURN_NO_PROMETHEUS=1 \
TURN_NO_SCTP=1 \
TURN_NO_SYSTEMD=1 \
TURN_NO_MONGO=1 \
$(if $(CONFIG_COTURN_ENABLE_MYSQL),,TURN_NO_MYSQL=1) \
$(if $(CONFIG_COTURN_ENABLE_POSTGRESQL),,TURN_NO_PQ=1) \
$(if $(CONFIG_COTURN_ENABLE_REDIS),,TURN_NO_HIREDIS=1) \
$(if $(CONFIG_COTURN_ENABLE_SQLITE),,TURN_NO_SQLITE=1)
define Build/InstallDev
endef
$(eval $(call BuildPackage,coturn))

View File

@ -0,0 +1,6 @@
config turnserver 'general'
option enabled '0'
option log_stderr '0'
option log_stdout '0'
option options '--pidfile /var/run/turnserver.pid --log-file syslog --no-cli --proc-user turnserver --proc-group turnserver'

View File

@ -0,0 +1,39 @@
#!/bin/sh /etc/rc.common
START=90
STOP=10
USE_PROCD=1
#PROCD_DEBUG=1
NAME=turnserver
COMMAND=/usr/bin/$NAME
LOGGER="/usr/bin/logger -s -t $NAME"
LOG_ERR="$LOGGER -p daemon.err --"
start_service() {
config_load $NAME
config_get_bool enabled general enabled 0
if [ $enabled -eq 0 ]; then
$LOG_ERR service not enabled in /etc/config/$NAME
exit 1
fi
config_get_bool log_stderr general log_stderr 1
config_get_bool log_stdout general log_stdout 1
config_get options general options
procd_open_instance
procd_set_param command $COMMAND
procd_append_param command $options
# forward stderr to logd
procd_set_param stderr $log_stderr
# same for stdout
procd_set_param stdout $log_stdout
procd_close_instance
}

View File

@ -0,0 +1,9 @@
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,5 +1,5 @@
-LIBEVENT_INCLUDE = -I${PREFIX}/include/ -I/usr/local/include/
+LIBEVENT_INCLUDE =
INCFLAGS = -Isrc -Isrc/apps/common -Isrc/server -Isrc/client -Isrc/client++ ${LIBEVENT_INCLUDE}

View File

@ -0,0 +1,14 @@
--- a/configure
+++ b/configure
@@ -1034,9 +1034,9 @@ ${ECHO_CMD} "# Generated by configure sc
${ECHO_CMD} "#################################" >> Makefile
${ECHO_CMD} "ECHO_CMD = ${ECHO_CMD}" >> Makefile
${ECHO_CMD} "CC = ${CC}" >> Makefile
-${ECHO_CMD} "LDFLAGS += ${OSLIBS}" >> Makefile
+${ECHO_CMD} "LDFLAGS = ${OSLIBS}" >> Makefile
${ECHO_CMD} "DBLIBS += ${DBLIBS}" >> Makefile
-${ECHO_CMD} "CFLAGS += ${OSCFLAGS}" >> Makefile
+${ECHO_CMD} "CFLAGS = ${OSCFLAGS}" >> Makefile
${ECHO_CMD} "CPPFLAGS = ${CPPFLAGS}" >> Makefile
${ECHO_CMD} "DBCFLAGS += ${DBCFLAGS} ${TURN_NO_PQ} ${TURN_NO_MYSQL} ${TURN_NO_SQLITE} ${TURN_NO_MONGO} ${TURN_NO_HIREDIS} ${TURN_NO_SYSTEMD}" >> Makefile
${ECHO_CMD} "#" >> Makefile

View File

@ -0,0 +1,11 @@
--- a/configure
+++ b/configure
@@ -931,7 +931,7 @@ fi
###########################
if [ -z "${TURN_NO_MYSQL}" ] ; then
- if testpkg_db mariadb || testpkg_db mysqlclient ; then
+ if testpkg_db libmariadb || testpkg_db mysqlclient ; then
${ECHO_CMD} "MySQL found."
else
${ECHO_CMD} "MySQL not found. Building without MySQL support."