TT#42906 Add systemd notify support

Change-Id: Iba046fa3e36654cedb73203eb06a9d768720a6b0
changes/86/23386/2
Guillem Jover 7 years ago
parent 89084da8d8
commit 5ba52952c0

@ -817,6 +817,8 @@ int main(int argc, char **argv) {
rtpe_config.num_threads = 4;
}
service_notify("READY=1\n");
for (;idx<rtpe_config.num_threads;++idx) {
thread_create_detach_prio(poller_loop, rtpe_poller, rtpe_config.scheduling, rtpe_config.priority);
}
@ -826,6 +828,8 @@ int main(int argc, char **argv) {
threads_join_all(0);
}
service_notify("STOPPING=1\n");
if (!is_addr_unspecified(&rtpe_config.redis_ep.address)) {
redis_notify_event_base_action(EVENT_BASE_LOOPBREAK);
redis_notify_event_base_action(EVENT_BASE_FREE);

1
debian/control vendored

@ -23,6 +23,7 @@ Build-Depends:
libpcre3-dev,
libssl-dev (>= 1.0.1),
libswresample-dev (>= 6:10),
libsystemd-dev,
libxmlrpc-c3-dev (>= 1.16.07) | libxmlrpc-core-c3-dev (>= 1.16.07),
markdown,
zlib1g-dev,

@ -5,7 +5,7 @@ After=remote-fs.target
Requires=network-online.target
[Service]
Type=simple
Type=notify
EnvironmentFile=/etc/default/ngcp-rtpengine-daemon
PIDFile=/var/run/ngcp-rtpengine-daemon.pid
ExecStartPre=/usr/sbin/ngcp-rtpengine-iptables-setup start

@ -7,7 +7,7 @@ Requires=network-online.target
Requires=ngcp-rtpengine-recording-nfs-mount.service
[Service]
Type=simple
Type=notify
PIDFile=/run/ngcp-rtpengine-recording-daemon.pid
ExecStart=/usr/sbin/rtpengine-recording -f -E --pidfile /run/ngcp-rtpengine-recording-daemon.pid --config-file /etc/rtpengine/rtpengine-recording.conf

@ -7,6 +7,9 @@
#include <string.h>
#include <errno.h>
#include <inttypes.h>
#ifdef HAVE_LIBSYSTEMD
#include <systemd/sd-daemon.h>
#endif
#include "log.h"
#include "loglib.h"
@ -43,6 +46,12 @@ void wpidfile() {
fclose(fp);
}
void service_notify(const char *message) {
#ifdef HAVE_LIBSYSTEMD
sd_notify(0, message);
#endif
}
static unsigned int options_length(const GOptionEntry *arr) {
unsigned int len = 0;

@ -20,6 +20,7 @@ extern struct rtpengine_common_config *rtpe_common_config_ptr;
void daemonize(void);
void wpidfile(void);
void service_notify(const char *message);
void config_load(int *argc, char ***argv, GOptionEntry *entries, const char *description,
char *default_config, char *default_section,
struct rtpengine_common_config *);

@ -25,6 +25,15 @@ ifeq ($(RTPENGINE_VERSION),)
endif
CFLAGS+= -DRTPENGINE_VERSION="\"$(RTPENGINE_VERSION)\""
# look for libsystemd
ifeq ($(shell pkg-config --exists libsystemd && echo yes),yes)
have_libsystemd := yes
endif
ifeq ($(have_libsystemd),yes)
CFLAGS+= $(shell pkg-config --cflags libsystemd)
CFLAGS+= -DHAVE_LIBSYSTEMD
LDLIBS+= $(shell pkg-config --libs libsystemd)
endif
ifeq ($(DBG),yes)
CFLAGS+= -D__DEBUG=1

@ -188,11 +188,14 @@ int main(int argc, char **argv) {
daemonize();
wpidfile();
service_notify("READY=1\n");
for (int i = 0; i < num_threads; i++)
start_poller_thread();
wait_for_signal();
service_notify("STOPPING=1\n");
dbg("shutting down");
wait_threads_finish();

Loading…
Cancel
Save