mirror of https://github.com/sipwise/kamailio.git
* added ngcp-kamailio-systemd-modules Change-Id: I91ff7f18fdbee0a9bac47cead9a84ed2374076e5changes/87/35387/10
parent
c896cdd82b
commit
6b91a6a966
@ -0,0 +1,60 @@
|
||||
From 99403c83f2163350eda3b76180947b1fddcdf500 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel-Constantin Mierla <miconda@gmail.com>
|
||||
Date: Thu, 21 Nov 2019 13:40:21 +0100
|
||||
Subject: [PATCH] core: events - support for basic void core callbacks
|
||||
|
||||
- can be used to allow modules execute their code from core for specific needs
|
||||
---
|
||||
src/core/events.c | 13 +++++++++++++
|
||||
src/core/events.h | 16 ++++++++++++++++
|
||||
2 files changed, 29 insertions(+)
|
||||
|
||||
diff --git a/src/core/events.c b/src/core/events.c
|
||||
index 5f71cd8f2..70d717969 100644
|
||||
--- a/src/core/events.c
|
||||
+++ b/src/core/events.c
|
||||
@@ -362,3 +362,16 @@ int sr_event_enabled(int type)
|
||||
return 0;
|
||||
}
|
||||
|
||||
+
|
||||
+/**
|
||||
+ *
|
||||
+ */
|
||||
+static sr_corecb_t _ksr_corecb = {0};
|
||||
+
|
||||
+/**
|
||||
+ *
|
||||
+ */
|
||||
+sr_corecb_t *sr_corecb_get(void)
|
||||
+{
|
||||
+ return &_ksr_corecb;
|
||||
+}
|
||||
diff --git a/src/core/events.h b/src/core/events.h
|
||||
index 9c4c54a2e..6282e65a5 100644
|
||||
--- a/src/core/events.h
|
||||
+++ b/src/core/events.h
|
||||
@@ -79,4 +79,20 @@ int sr_event_enabled(int type);
|
||||
void sr_core_ert_init(void);
|
||||
void sr_core_ert_run(sip_msg_t *msg, int e);
|
||||
|
||||
+typedef void (*sr_corecb_void_f)(void);
|
||||
+typedef struct sr_corecb {
|
||||
+ sr_corecb_void_f app_ready;
|
||||
+ sr_corecb_void_f app_shutdown;
|
||||
+} sr_corecb_t;
|
||||
+
|
||||
+sr_corecb_t *sr_corecb_get(void);
|
||||
+
|
||||
+#define sr_corecb_void_exec(fname) \
|
||||
+ do { \
|
||||
+ sr_corecb_t *__cbp = sr_corecb_get(); \
|
||||
+ if(__cbp && __cbp->fname) { \
|
||||
+ __cbp->fname(); \
|
||||
+ } \
|
||||
+ } while(0);
|
||||
+
|
||||
#endif
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
From 03aa6556ef59c0b274c78f2edc2231c6d2ed333b Mon Sep 17 00:00:00 2001
|
||||
From: Daniel-Constantin Mierla <miconda@gmail.com>
|
||||
Date: Thu, 21 Nov 2019 13:41:38 +0100
|
||||
Subject: [PATCH] core: main - executes callbacks on app ready and shutdown
|
||||
|
||||
---
|
||||
src/main.c | 3 +++
|
||||
1 file changed, 3 insertions(+)
|
||||
|
||||
diff --git a/src/main.c b/src/main.c
|
||||
index c8ee3ad11..a5a007053 100644
|
||||
--- a/src/main.c
|
||||
+++ b/src/main.c
|
||||
@@ -684,6 +684,8 @@ static void sig_alarm_abort(int signo)
|
||||
|
||||
static void shutdown_children(int sig, int show_status)
|
||||
{
|
||||
+ sr_corecb_void_exec(app_shutdown);
|
||||
+
|
||||
kill_all_children(sig);
|
||||
if (set_sig_h(SIGALRM, sig_alarm_kill) == SIG_ERR ) {
|
||||
LM_ERR("could not install SIGALARM handler\n");
|
||||
@@ -1788,6 +1790,7 @@ int main_loop(void)
|
||||
cfg_ok=1;
|
||||
|
||||
*_sr_instance_started = 1;
|
||||
+ sr_corecb_void_exec(app_ready);
|
||||
|
||||
#ifdef EXTRA_DEBUG
|
||||
for (r=0; r<*process_count; r++){
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
From: Daniel-Constantin Mierla <miconda@gmail.com>
|
||||
Date: Thu, 21 Nov 2019 13:44:35 +0100
|
||||
Subject: src/Makefile.groups: added systemdops module to systemd group
|
||||
|
||||
---
|
||||
src/Makefile.groups | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/Makefile.groups b/src/Makefile.groups
|
||||
index 33cbf0a..53d8cc6 100644
|
||||
--- a/src/Makefile.groups
|
||||
+++ b/src/Makefile.groups
|
||||
@@ -199,7 +199,7 @@ mod_list_cnxcc=cnxcc
|
||||
mod_list_erlang=erlang
|
||||
|
||||
# - modules depending on systemd library
|
||||
-mod_list_systemd=log_systemd
|
||||
+mod_list_systemd=log_systemd systemdops
|
||||
|
||||
# - modules depending on libtcap library
|
||||
mod_list_tcap=tcap
|
||||
@ -0,0 +1,347 @@
|
||||
From 0c48e1621c88bf1d390e4cfb82e52b2d6339b837 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel-Constantin Mierla <miconda@gmail.com>
|
||||
Date: Thu, 21 Nov 2019 13:42:14 +0100
|
||||
Subject: [PATCH] systemdops: new module to facilitate integration with systemd
|
||||
|
||||
---
|
||||
src/modules/systemdops/Makefile | 23 ++++++
|
||||
src/modules/systemdops/README | 77 +++++++++++++++++++
|
||||
src/modules/systemdops/doc/Makefile | 4 +
|
||||
src/modules/systemdops/doc/systemdops.xml | 36 +++++++++
|
||||
.../systemdops/doc/systemdops_admin.xml | 76 ++++++++++++++++++
|
||||
src/modules/systemdops/systemdops_mod.c | 72 +++++++++++++++++
|
||||
6 files changed, 288 insertions(+)
|
||||
create mode 100644 src/modules/systemdops/Makefile
|
||||
create mode 100644 src/modules/systemdops/README
|
||||
create mode 100644 src/modules/systemdops/doc/Makefile
|
||||
create mode 100644 src/modules/systemdops/doc/systemdops.xml
|
||||
create mode 100644 src/modules/systemdops/doc/systemdops_admin.xml
|
||||
create mode 100644 src/modules/systemdops/systemdops_mod.c
|
||||
|
||||
diff --git a/src/modules/systemdops/Makefile b/src/modules/systemdops/Makefile
|
||||
new file mode 100644
|
||||
index 000000000..26e15cd39
|
||||
--- /dev/null
|
||||
+++ b/src/modules/systemdops/Makefile
|
||||
@@ -0,0 +1,23 @@
|
||||
+#
|
||||
+# WARNING: do not run this directly, it should be run by the master Makefile
|
||||
+
|
||||
+include ../../Makefile.defs
|
||||
+auto_gen=
|
||||
+NAME=systemdops.so
|
||||
+
|
||||
+ifeq ($(CROSS_COMPILE),)
|
||||
+SYSTEMD_BUILDER=$(shell \
|
||||
+ if pkg-config --exists libsystemd; then \
|
||||
+ echo 'pkg-config libsystemd'; \
|
||||
+ fi)
|
||||
+endif
|
||||
+
|
||||
+ifneq ($(SYSTEMD_BUILDER),)
|
||||
+ DEFS += $(shell $(SYSTEMD_BUILDER) --cflags)
|
||||
+ LIBS += $(shell $(SYSTEMD_BUILDER) --libs)
|
||||
+else
|
||||
+ DEFS += -I$(LOCALBASE)/include
|
||||
+ LIBS= -L$(LOCALBASE)/lib -lsystemd
|
||||
+endif
|
||||
+
|
||||
+include ../../Makefile.modules
|
||||
diff --git a/src/modules/systemdops/README b/src/modules/systemdops/README
|
||||
new file mode 100644
|
||||
index 000000000..c93df6102
|
||||
--- /dev/null
|
||||
+++ b/src/modules/systemdops/README
|
||||
@@ -0,0 +1,77 @@
|
||||
+SYSTEMDOPS Module
|
||||
+
|
||||
+Daniel-Constantin Mierla
|
||||
+
|
||||
+ <miconda@gmail.com>
|
||||
+
|
||||
+Edited by
|
||||
+
|
||||
+Daniel-Constantin Mierla
|
||||
+
|
||||
+ <miconda@gmail.com>
|
||||
+
|
||||
+ Copyright © 2019 asipto.com
|
||||
+ __________________________________________________________________
|
||||
+
|
||||
+ Table of Contents
|
||||
+
|
||||
+ 1. Admin Guide
|
||||
+
|
||||
+ 1. Overview
|
||||
+ 2. Dependencies
|
||||
+
|
||||
+ 2.1. Kamailio Modules
|
||||
+ 2.2. External Libraries or Applications
|
||||
+
|
||||
+ 3. Systemd Notifications
|
||||
+
|
||||
+ List of Examples
|
||||
+
|
||||
+ 1.1. Systemd Notifications
|
||||
+
|
||||
+Chapter 1. Admin Guide
|
||||
+
|
||||
+ Table of Contents
|
||||
+
|
||||
+ 1. Overview
|
||||
+ 2. Dependencies
|
||||
+
|
||||
+ 2.1. Kamailio Modules
|
||||
+ 2.2. External Libraries or Applications
|
||||
+
|
||||
+ 3. Systemd Notifications
|
||||
+
|
||||
+1. Overview
|
||||
+
|
||||
+ It provides a collection of features to make easier the integration
|
||||
+ with systemd.
|
||||
+
|
||||
+2. Dependencies
|
||||
+
|
||||
+ 2.1. Kamailio Modules
|
||||
+ 2.2. External Libraries or Applications
|
||||
+
|
||||
+2.1. Kamailio Modules
|
||||
+
|
||||
+ The following modules must be loaded before this module:
|
||||
+ * none.
|
||||
+
|
||||
+2.2. External Libraries or Applications
|
||||
+
|
||||
+ The following libraries or applications must be installed before
|
||||
+ running Kamailio with this module loaded:
|
||||
+ * libsystemd
|
||||
+
|
||||
+3. Systemd Notifications
|
||||
+
|
||||
+ If loaded, the module will generated systemd notifications when
|
||||
+ Kamailio starts and when Kamailio shuts down. The content of these
|
||||
+ notifications (sent with sd_notify(...)) are shown in the next example
|
||||
+ (_PID_ is replaced by the PID of the main process).
|
||||
+
|
||||
+ Example 1.1. Systemd Notifications
|
||||
+...
|
||||
+READY=1\nMAINPID=_PID_
|
||||
+...
|
||||
+STOPPING=1
|
||||
+...
|
||||
diff --git a/src/modules/systemdops/doc/Makefile b/src/modules/systemdops/doc/Makefile
|
||||
new file mode 100644
|
||||
index 000000000..51a2fbb9d
|
||||
--- /dev/null
|
||||
+++ b/src/modules/systemdops/doc/Makefile
|
||||
@@ -0,0 +1,4 @@
|
||||
+docs = systemdops.xml
|
||||
+
|
||||
+docbook_dir = ../../../../doc/docbook
|
||||
+include $(docbook_dir)/Makefile.module
|
||||
diff --git a/src/modules/systemdops/doc/systemdops.xml b/src/modules/systemdops/doc/systemdops.xml
|
||||
new file mode 100644
|
||||
index 000000000..bf15611d2
|
||||
--- /dev/null
|
||||
+++ b/src/modules/systemdops/doc/systemdops.xml
|
||||
@@ -0,0 +1,36 @@
|
||||
+<?xml version="1.0" encoding='ISO-8859-1'?>
|
||||
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
|
||||
+
|
||||
+<!-- Include general documentation entities -->
|
||||
+<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
|
||||
+%docentities;
|
||||
+
|
||||
+]>
|
||||
+
|
||||
+<book xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
+ <bookinfo>
|
||||
+ <title>SYSTEMDOPS Module</title>
|
||||
+ <productname class="trade">kamailio.org</productname>
|
||||
+ <authorgroup>
|
||||
+ <author>
|
||||
+ <firstname>Daniel-Constantin</firstname>
|
||||
+ <surname>Mierla</surname>
|
||||
+ <email>miconda@gmail.com</email>
|
||||
+ </author>
|
||||
+ <editor>
|
||||
+ <firstname>Daniel-Constantin</firstname>
|
||||
+ <surname>Mierla</surname>
|
||||
+ <email>miconda@gmail.com</email>
|
||||
+ </editor>
|
||||
+ </authorgroup>
|
||||
+ <copyright>
|
||||
+ <year>2019</year>
|
||||
+ <holder>asipto.com</holder>
|
||||
+ </copyright>
|
||||
+ </bookinfo>
|
||||
+ <toc></toc>
|
||||
+
|
||||
+ <xi:include href="systemdops_admin.xml"/>
|
||||
+
|
||||
+</book>
|
||||
diff --git a/src/modules/systemdops/doc/systemdops_admin.xml b/src/modules/systemdops/doc/systemdops_admin.xml
|
||||
new file mode 100644
|
||||
index 000000000..7af4cc3d9
|
||||
--- /dev/null
|
||||
+++ b/src/modules/systemdops/doc/systemdops_admin.xml
|
||||
@@ -0,0 +1,76 @@
|
||||
+<?xml version="1.0" encoding='ISO-8859-1'?>
|
||||
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
|
||||
+
|
||||
+<!-- Include general documentation entities -->
|
||||
+<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
|
||||
+%docentities;
|
||||
+
|
||||
+]>
|
||||
+<!-- Module User's Guide -->
|
||||
+
|
||||
+<chapter>
|
||||
+
|
||||
+ <title>&adminguide;</title>
|
||||
+
|
||||
+ <section>
|
||||
+ <title>Overview</title>
|
||||
+ <para>
|
||||
+ It provides a collection of features to make easier the integration
|
||||
+ with systemd.
|
||||
+ </para>
|
||||
+ </section>
|
||||
+
|
||||
+ <section>
|
||||
+ <title>Dependencies</title>
|
||||
+ <section>
|
||||
+ <title>&kamailio; Modules</title>
|
||||
+ <para>
|
||||
+ The following modules must be loaded before this module:
|
||||
+ <itemizedlist>
|
||||
+ <listitem>
|
||||
+ <para>
|
||||
+ <emphasis>none</emphasis>.
|
||||
+ </para>
|
||||
+ </listitem>
|
||||
+ </itemizedlist>
|
||||
+ </para>
|
||||
+ </section>
|
||||
+ <section>
|
||||
+ <title>External Libraries or Applications</title>
|
||||
+ <para>
|
||||
+ The following libraries or applications must be installed before running
|
||||
+ &kamailio; with this module loaded:
|
||||
+ <itemizedlist>
|
||||
+ <listitem>
|
||||
+ <para>
|
||||
+ <emphasis>libsystemd</emphasis>
|
||||
+ </para>
|
||||
+ </listitem>
|
||||
+ </itemizedlist>
|
||||
+ </para>
|
||||
+ </section>
|
||||
+ </section>
|
||||
+
|
||||
+ <section>
|
||||
+ <title>Systemd Notifications</title>
|
||||
+ <para>
|
||||
+ If loaded, the module will generated systemd notifications when &kamailio;
|
||||
+ starts and when &kamailio; shuts down. The content of these notifications
|
||||
+ (sent with sd_notify(...)) are shown in the next example (_PID_ is
|
||||
+ replaced by the PID of the main process).
|
||||
+ </para>
|
||||
+ <example>
|
||||
+ <title><function>Systemd Notifications</function></title>
|
||||
+ <programlisting format="linespecific">
|
||||
+...
|
||||
+READY=1\nMAINPID=_PID_
|
||||
+...
|
||||
+STOPPING=1
|
||||
+...
|
||||
+</programlisting>
|
||||
+ </example>
|
||||
+ </section>
|
||||
+
|
||||
+</chapter>
|
||||
+
|
||||
diff --git a/src/modules/systemdops/systemdops_mod.c b/src/modules/systemdops/systemdops_mod.c
|
||||
new file mode 100644
|
||||
index 000000000..58d7a2b24
|
||||
--- /dev/null
|
||||
+++ b/src/modules/systemdops/systemdops_mod.c
|
||||
@@ -0,0 +1,72 @@
|
||||
+/**
|
||||
+ * Copyright (C) 2019 Daniel-Constantin Mierla (asipto.com)
|
||||
+ *
|
||||
+ * This file is part of Kamailio, a free SIP server.
|
||||
+ *
|
||||
+ * This file is free software; you can redistribute it and/or modify
|
||||
+ * it under the terms of the GNU General Public License as published by
|
||||
+ * the Free Software Foundation; either version 2 of the License, or
|
||||
+ * (at your option) any later version
|
||||
+ *
|
||||
+ *
|
||||
+ * This file is distributed in the hope that it will be useful,
|
||||
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
+ * GNU General Public License for more details.
|
||||
+ *
|
||||
+ * You should have received a copy of the GNU General Public License
|
||||
+ * along with this program; if not, write to the Free Software
|
||||
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+ *
|
||||
+ */
|
||||
+
|
||||
+#include <stdio.h>
|
||||
+#include <unistd.h>
|
||||
+#include <stdlib.h>
|
||||
+#include <string.h>
|
||||
+#include <systemd/sd-daemon.h>
|
||||
+
|
||||
+#include "../../core/sr_module.h"
|
||||
+#include "../../core/dprint.h"
|
||||
+#include "../../core/events.h"
|
||||
+#include "../../core/globals.h"
|
||||
+
|
||||
+
|
||||
+MODULE_VERSION
|
||||
+
|
||||
+struct module_exports exports = {
|
||||
+ "systemdops", /* module name */
|
||||
+ DEFAULT_DLFLAGS, /* dlopen flags */
|
||||
+ 0, /* cmd (cfg function) exports */
|
||||
+ 0, /* param exports */
|
||||
+ 0, /* RPC method exports */
|
||||
+ 0, /* pseudo-variables exports */
|
||||
+ 0, /* response handling function */
|
||||
+ 0, /* module init function */
|
||||
+ 0, /* per-child init function */
|
||||
+ 0 /* module destroy function */
|
||||
+};
|
||||
+
|
||||
+/**
|
||||
+ *
|
||||
+ */
|
||||
+void ksr_sd_app_ready(void)
|
||||
+{
|
||||
+ sd_notifyf(0, "READY=1\nMAINPID=%lu", (unsigned long)creator_pid);
|
||||
+}
|
||||
+
|
||||
+/**
|
||||
+ *
|
||||
+ */
|
||||
+void ksr_sd_app_shutdown(void)
|
||||
+{
|
||||
+ sd_notify(0, "STOPPING=1");
|
||||
+}
|
||||
+
|
||||
+/**
|
||||
+ * module registration function
|
||||
+ */
|
||||
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
|
||||
+{
|
||||
+ return 0;
|
||||
+}
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
From fffd892b7d18734c8f60d2eebec5d4a15a0fdc26 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel-Constantin Mierla <miconda@gmail.com>
|
||||
Date: Fri, 22 Nov 2019 09:42:08 +0100
|
||||
Subject: [PATCH] systemdops: proper check for null value
|
||||
|
||||
---
|
||||
src/modules/systemdops/systemdops_mod.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/modules/systemdops/systemdops_mod.c b/src/modules/systemdops/systemdops_mod.c
|
||||
index 0ac15426d..8c24ac186 100644
|
||||
--- a/src/modules/systemdops/systemdops_mod.c
|
||||
+++ b/src/modules/systemdops/systemdops_mod.c
|
||||
@@ -69,7 +69,7 @@ void ksr_sd_app_shutdown(void)
|
||||
int mod_register(char *path, int *dlflags, void *p1, void *p2)
|
||||
{
|
||||
sr_corecb_t *cbp = sr_corecb_get();
|
||||
- if(cbp) {
|
||||
+ if(cbp==NULL) {
|
||||
return -1;
|
||||
}
|
||||
cbp->app_ready = ksr_sd_app_ready;
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
From d4fc8b0168ba3de78e29deb7c7d7ed9b3fd29a36 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel-Constantin Mierla <miconda@gmail.com>
|
||||
Date: Fri, 22 Nov 2019 09:14:06 +0100
|
||||
Subject: [PATCH] systemdops: set core callbacks in mod_register()
|
||||
|
||||
---
|
||||
src/modules/systemdops/systemdops_mod.c | 6 ++++++
|
||||
1 file changed, 6 insertions(+)
|
||||
|
||||
diff --git a/src/modules/systemdops/systemdops_mod.c b/src/modules/systemdops/systemdops_mod.c
|
||||
index 58d7a2b24..0ac15426d 100644
|
||||
--- a/src/modules/systemdops/systemdops_mod.c
|
||||
+++ b/src/modules/systemdops/systemdops_mod.c
|
||||
@@ -68,5 +68,11 @@ void ksr_sd_app_shutdown(void)
|
||||
*/
|
||||
int mod_register(char *path, int *dlflags, void *p1, void *p2)
|
||||
{
|
||||
+ sr_corecb_t *cbp = sr_corecb_get();
|
||||
+ if(cbp) {
|
||||
+ return -1;
|
||||
+ }
|
||||
+ cbp->app_ready = ksr_sd_app_ready;
|
||||
+ cbp->app_shutdown = ksr_sd_app_shutdown;
|
||||
return 0;
|
||||
}
|
||||
--
|
||||
2.20.1
|
||||
|
||||
Loading…
Reference in new issue