Add explicit SIGTERM and SIGINT handlers. (#1106)
coturn running inside a docker container runs as PID 1, however PID 1 has special signal handling semantics (see the note at the bottom of the section [here](https://docs.docker.com/engine/reference/run/#foreground)). coturn relies on the default behaviour of SIGTERM to terminate the process, however as no signal handler is explicitly installed, it doesn't respond to SIGTERM when running inside a container. This PR fixes this problem by installing explicit signal handlers for SIGINT and SIGTERM, which trigger the same termination mechanism as the admin interface "halt" command. This is a port of wireapp#6 for upstream.
This commit is contained in:
parent
eff1f9a09a
commit
82646a9023
@ -265,6 +265,8 @@ static char procgroupname[1025] = "\0";
|
||||
static void read_config_file(int argc, char **argv, int pass);
|
||||
static void reload_ssl_certs(evutil_socket_t sock, short events, void *args);
|
||||
|
||||
static void shutdown_handler(evutil_socket_t sock, short events, void *args);
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
static int make_local_listeners_list(void) {
|
||||
@ -3211,6 +3213,11 @@ int main(int argc, char **argv) {
|
||||
#else
|
||||
struct event *ev = evsignal_new(turn_params.listener.event_base, SIGUSR2, reload_ssl_certs, NULL);
|
||||
event_add(ev, NULL);
|
||||
|
||||
ev = evsignal_new(turn_params.listener.event_base, SIGTERM, shutdown_handler, NULL);
|
||||
event_add(ev, NULL);
|
||||
ev = evsignal_new(turn_params.listener.event_base, SIGINT, shutdown_handler, NULL);
|
||||
event_add(ev, NULL);
|
||||
#endif
|
||||
|
||||
drop_privileges();
|
||||
@ -3821,4 +3828,12 @@ static void reload_ssl_certs(evutil_socket_t sock, short events, void *args) {
|
||||
UNUSED_ARG(args);
|
||||
}
|
||||
|
||||
static void shutdown_handler(evutil_socket_t sock, short events, void *args) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "Terminating on signal %d\n", sock);
|
||||
turn_params.stop_turn_server = 1;
|
||||
|
||||
UNUSED_ARG(events);
|
||||
UNUSED_ARG(args);
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
Loading…
Reference in New Issue
Block a user