1
0
mirror of https://github.com/coturn/coturn.git synced 2025-10-24 12:31:00 +02:00

Add systemd notification support

This commit is contained in:
Mészáros Mihály 2021-01-07 17:51:34 +00:00
parent ae0b41153c
commit ef7916842d
12 changed files with 56 additions and 13 deletions

View File

@ -32,7 +32,8 @@ Version 4.5.2 'dan Eider':
- Fix stale-nonce documentation. Resolves #604 - Fix stale-nonce documentation. Resolves #604
- Version number is changed to semver 2.0 - Version number is changed to semver 2.0
- Merge PR #288 (by Hristo Venev) - Merge PR #288 (by Hristo Venev)
* pkg-config, and various cleanups in connfigure file * pkg-config, and various cleanups in connfigure file
- Add systemd notification for better systemd integration
24/06/2020 Oleg Moskalenko <mom040267@gmail.com> Mihály Mészáros <misi@majd.eu> 24/06/2020 Oleg Moskalenko <mom040267@gmail.com> Mihály Mészáros <misi@majd.eu>
Version 4.5.1.3 'dan Eider': Version 4.5.1.3 'dan Eider':

View File

@ -158,6 +158,8 @@ Flags:
-o, --daemon Run server as daemon. -o, --daemon Run server as daemon.
--systemd Notify systemd about server status. (Use only in forground!)
--no-software-attribute Production mode: hide the software version. --no-software-attribute Production mode: hide the software version.
-f, --fingerprint Use fingerprints in the TURN messages. If an incoming request -f, --fingerprint Use fingerprints in the TURN messages. If an incoming request

15
configure vendored
View File

@ -864,6 +864,21 @@ else
OSCFLAGS="${OSCFLAGS} -DTURN_NO_PROMETHEUS" OSCFLAGS="${OSCFLAGS} -DTURN_NO_PROMETHEUS"
fi fi
###########################
# Test libsystemd
###########################
if [ -z "${TURN_NO_SYSTEMD}" ] ; then
if testpkg_common libsystemd; then
${ECHO_CMD} "Systemd library found."
else
${ECHO_CMD} "Systemd library not found. Building without systemd support."
TURN_NO_PQ="-DTURN_NO_SYSTEMD"
fi
else
TURN_NO_PQ="-DTURN_NO_SYSTEMD"
fi
########################### ###########################
# Test SQLite3 setup # Test SQLite3 setup
########################### ###########################

View File

@ -6,7 +6,7 @@ ENV BUILD_PREFIX /usr/local/src
# Install build dependencies # Install build dependencies
RUN export DEBIAN_FRONTEND=noninteractive && \ RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \ apt-get update && \
apt-get install -y build-essential git debhelper dpkg-dev libssl-dev libevent-dev sqlite3 libsqlite3-dev postgresql-client libpq-dev default-mysql-client default-libmysqlclient-dev libhiredis-dev libmongoc-dev libbson-dev apt-get install -y build-essential git debhelper dpkg-dev libssl-dev libevent-dev sqlite3 libsqlite3-dev postgresql-client libpq-dev default-mysql-client default-libmysqlclient-dev libhiredis-dev libmongoc-dev libbson-dev libsystemd-dev
# Clone Coturn # Clone Coturn
WORKDIR ${BUILD_PREFIX} WORKDIR ${BUILD_PREFIX}

View File

@ -9,12 +9,10 @@ Wants=network-online.target
[Service] [Service]
User=turnserver User=turnserver
Group=turnserver Group=turnserver
Type=forking Type=notify
RuntimeDirectory=turnserver RuntimeDirectory=turnserver
PIDFile=/run/turnserver/turnserver.pid PIDFile=/run/turnserver/turnserver.pid
ExecStart=/usr/bin/turnserver --daemon -c /etc/turnserver.conf --pidfile /run/turnserver/turnserver.pid ExecStart=/usr/bin/turnserver --systemd -c /etc/turnserver.conf --pidfile /run/turnserver/turnserver.pid
#FixMe: turnserver exit faster than it is finshing the setup and ready for handling the connection.
ExecStartPost=/bin/sleep 2
Restart=on-failure Restart=on-failure
InaccessibleDirectories=/home InaccessibleDirectories=/home
PrivateTmp=yes PrivateTmp=yes

View File

@ -1,5 +1,5 @@
.\" Text automatically generated by txt2man .\" Text automatically generated by txt2man
.TH TURN 1 "05 January 2021" "" "" .TH TURN 1 "07 January 2021" "" ""
.SH GENERAL INFORMATION .SH GENERAL INFORMATION
\fIturnadmin\fP is a TURN administration tool. This tool can be used to manage \fIturnadmin\fP is a TURN administration tool. This tool can be used to manage

View File

@ -1,5 +1,5 @@
.\" Text automatically generated by txt2man .\" Text automatically generated by txt2man
.TH TURN 1 "05 January 2021" "" "" .TH TURN 1 "07 January 2021" "" ""
.SH GENERAL INFORMATION .SH GENERAL INFORMATION
The \fBTURN Server\fP project contains the source code of a TURN server and TURN client The \fBTURN Server\fP project contains the source code of a TURN server and TURN client
@ -230,6 +230,10 @@ Extra verbose mode, very annoying and not recommended.
.B .B
\fB\-o\fP, \fB\-\-daemon\fP \fB\-o\fP, \fB\-\-daemon\fP
Run server as daemon. Run server as daemon.
.TP
.B
\fB\-\-systemd\fP
Notify systemd about server status. (Use only in forground!)
.PP .PP
\fB\-\-no\-software\-attribute\fP Production mode: hide the software version. \fB\-\-no\-software\-attribute\fP Production mode: hide the software version.
.TP .TP

View File

@ -1,5 +1,5 @@
.\" Text automatically generated by txt2man .\" Text automatically generated by txt2man
.TH TURN 1 "05 January 2021" "" "" .TH TURN 1 "07 January 2021" "" ""
.SH GENERAL INFORMATION .SH GENERAL INFORMATION
A set of turnutils_* programs provides some utility functionality to be used A set of turnutils_* programs provides some utility functionality to be used

View File

@ -6,10 +6,10 @@ After=syslog.target network.target
[Service] [Service]
User=turnserver User=turnserver
Group=turnserver Group=turnserver
Type=forking Type=notify
EnvironmentFile=/etc/sysconfig/turnserver EnvironmentFile=/etc/sysconfig/turnserver
PIDFile=/var/run/turnserver/turnserver.pid PIDFile=/var/run/turnserver/turnserver.pid
ExecStart=/usr/bin/turnserver -o -c /etc/turnserver/turnserver.conf $EXTRA_OPTIONS ExecStart=/usr/bin/turnserver --systemd -c /etc/turnserver/turnserver.conf $EXTRA_OPTIONS
ExecStopPost=/usr/bin/rm -f /var/run/turnserver/turnserver.pid ExecStopPost=/usr/bin/rm -f /var/run/turnserver/turnserver.pid
Restart=on-abort Restart=on-abort

View File

@ -170,7 +170,8 @@ DEFAULT_CPUS_NUMBER,
0, /* no_dynamic_ip_list */ 0, /* no_dynamic_ip_list */
0, /* no_dynamic_realms */ 0, /* no_dynamic_realms */
0 /* log_binding */ 0, /* log_binding */
0 /* systemd */
}; };
//////////////// OpenSSL Init ////////////////////// //////////////// OpenSSL Init //////////////////////
@ -463,6 +464,7 @@ static char Usage[] = "Usage: turnserver [options]\n"
" -v, --verbose 'Moderate' verbose mode.\n" " -v, --verbose 'Moderate' verbose mode.\n"
" -V, --Verbose Extra verbose mode, very annoying (for debug purposes only).\n" " -V, --Verbose Extra verbose mode, very annoying (for debug purposes only).\n"
" -o, --daemon Start process as daemon (detach from current shell).\n" " -o, --daemon Start process as daemon (detach from current shell).\n"
" --systemd Notify systemd about server status. (Use only in forground!)\n"
" --no-software-attribute Production mode: hide the software version (formerly --prod).\n" " --no-software-attribute Production mode: hide the software version (formerly --prod).\n"
" -f, --fingerprint Use fingerprints in the TURN messages.\n" " -f, --fingerprint Use fingerprints in the TURN messages.\n"
" -a, --lt-cred-mech Use the long-term credential mechanism.\n" " -a, --lt-cred-mech Use the long-term credential mechanism.\n"
@ -813,7 +815,8 @@ enum EXTRA_OPTS {
NO_HTTP_OPT, NO_HTTP_OPT,
SECRET_KEY_OPT, SECRET_KEY_OPT,
ACME_REDIRECT_OPT, ACME_REDIRECT_OPT,
LOG_BINDING_OPT LOG_BINDING_OPT,
SYSTEMD_OPT
}; };
struct myoption { struct myoption {
@ -949,6 +952,7 @@ static const struct myoption long_options[] = {
{ "keep-address-family", optional_argument, NULL, 'K' }, { "keep-address-family", optional_argument, NULL, 'K' },
{ "acme-redirect", required_argument, NULL, ACME_REDIRECT_OPT }, { "acme-redirect", required_argument, NULL, ACME_REDIRECT_OPT },
{ "log-binding", optional_argument, NULL, LOG_BINDING_OPT }, { "log-binding", optional_argument, NULL, LOG_BINDING_OPT },
{ "systemd", optional_argument, NULL, SYSTEMD_OPT },
{ NULL, no_argument, NULL, 0 } { NULL, no_argument, NULL, 0 }
}; };
@ -1606,6 +1610,9 @@ static void set_option(int c, char *value)
case LOG_BINDING_OPT: case LOG_BINDING_OPT:
turn_params.log_binding = get_bool_value(value); turn_params.log_binding = get_bool_value(value);
break; break;
case SYSTEMD_OPT:
turn_params.systemd = get_bool_value(value);
break;
/* these options have been already taken care of before: */ /* these options have been already taken care of before: */
case 'l': case 'l':

View File

@ -85,6 +85,10 @@
#include <openssl/modes.h> #include <openssl/modes.h>
#endif #endif
#if !defined(TURN_NO_SYSTEMD)
#include <systemd/sd-daemon.h>
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -335,6 +339,8 @@ typedef struct _turn_params_ {
vint log_binding; vint log_binding;
vint systemd;
} turn_params_t; } turn_params_t;
extern turn_params_t turn_params; extern turn_params_t turn_params;

View File

@ -1590,6 +1590,11 @@ void run_listener_server(struct listener_server *ls)
unsigned int cycle = 0; unsigned int cycle = 0;
while (!turn_params.stop_turn_server) { while (!turn_params.stop_turn_server) {
#if !defined(TURN_NO_SYSTEMD)
if(turn_params.systemd)
sd_notify (0, "READY=1");
#endif
if (eve(turn_params.verbose)) { if (eve(turn_params.verbose)) {
if ((cycle++ & 15) == 0) { if ((cycle++ & 15) == 0) {
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "%s: cycle=%u\n", __FUNCTION__, cycle); TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "%s: cycle=%u\n", __FUNCTION__, cycle);
@ -1600,6 +1605,11 @@ void run_listener_server(struct listener_server *ls)
rollover_logfile(); rollover_logfile();
} }
#if !defined(TURN_NO_SYSTEMD)
if(turn_params.systemd)
sd_notify (0, "STOPPING=1");
#endif
} }
static void setup_relay_server(struct relay_server *rs, ioa_engine_handle e, int to_set_rfc5780) static void setup_relay_server(struct relay_server *rs, ioa_engine_handle e, int to_set_rfc5780)