summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>2016-06-27 21:26:54 +0200
committerGeorge Joseph <gjoseph@digium.com>2016-09-20 08:12:38 -0600
commit29e096cd13f2a927006ba491dfdae1d900b11b10 (patch)
tree53cbb385b8371f5b56dc06130cbe385ad8be5e95 /main
parentb56717b39651e2069500076d8c6aa54bf22da7f1 (diff)
sd_notify (systemd status notifications) support
sd_notify() is used to notify systemd of changes to the status of the process. This allows the systemd daemon to know when the process finished loading (and thus only start another program after Asterisk has finished loading). To use this, use a systemd unit with 'Type=notify' for Asterisk. This commit also adds the function ast_sd_notify(), a wrapper around sd_notify that does nothing if not built with systemd support. Also adds support for libsystemd detection in the configure script. Change-Id: Ied6a59dafd5ef331c5c7ae8f3ccd2dfc94be7811 (cherry picked from commit 07b95f7c65b7c083724f1af2b26f93cc22cad58c)
Diffstat (limited to 'main')
-rw-r--r--main/Makefile1
-rw-r--r--main/asterisk.c4
-rw-r--r--main/io.c10
-rw-r--r--main/loader.c9
4 files changed, 20 insertions, 4 deletions
diff --git a/main/Makefile b/main/Makefile
index a6c3ab1b8..d41302a7f 100644
--- a/main/Makefile
+++ b/main/Makefile
@@ -45,6 +45,7 @@ AST_LIBS+=$(UUID_LIB)
AST_LIBS+=$(CRYPT_LIB)
AST_LIBS+=$(AST_CLANG_BLOCKS_LIBS)
AST_LIBS+=$(RT_LIB)
+AST_LIBS+=$(SYSTEMD_LIB)
ifneq ($(findstring $(OSARCH), linux-gnu uclinux linux-uclibc linux-musl kfreebsd-gnu),)
ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
diff --git a/main/asterisk.c b/main/asterisk.c
index 7b1338c3d..c9e3b59a5 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -2039,6 +2039,9 @@ static void really_quit(int num, shutdown_nice_t niceness, int restart)
ast_module_shutdown();
}
+ if (!restart) {
+ ast_sd_notify("STOPPING=1");
+ }
if (ast_opt_console || (ast_opt_remote && !ast_opt_exec)) {
ast_el_write_default_histfile();
if (consolethread == AST_PTHREADT_NULL || consolethread == pthread_self()) {
@@ -4566,6 +4569,7 @@ static void asterisk_daemon(int isroot, const char *runuser, const char *rungrou
ast_register_cleanup(main_atexit);
run_startup_commands();
+ ast_sd_notify("READY=1");
ast_verb(0, COLORIZE_FMT "\n", COLORIZE(COLOR_BRGREEN, 0, "Asterisk Ready."));
diff --git a/main/io.c b/main/io.c
index ff5ca57f7..3441fbae9 100644
--- a/main/io.c
+++ b/main/io.c
@@ -36,6 +36,9 @@ ASTERISK_REGISTER_FILE()
#include "asterisk/io.h"
#include "asterisk/utils.h"
+#ifdef HAVE_SYSTEMD
+#include <systemd/sd-daemon.h>
+#endif
#ifdef DEBUG_IO
#define DEBUG DEBUG_M
@@ -384,3 +387,10 @@ int ast_get_termcols(int fd)
return cols;
}
+int ast_sd_notify(const char *state) {
+#ifdef HAVE_SYSTEMD
+ return sd_notify(0, state);
+#else
+ return 0;
+#endif
+}
diff --git a/main/loader.c b/main/loader.c
index f95922173..36a3d5f61 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -891,6 +891,7 @@ enum ast_module_reload_result ast_module_reload(const char *name)
res = AST_MODULE_RELOAD_IN_PROGRESS;
goto module_reload_exit;
}
+ ast_sd_notify("RELOAD=1");
ast_lastreloadtime = ast_tvnow();
if (ast_opt_lock_confdir) {
@@ -904,9 +905,8 @@ enum ast_module_reload_result ast_module_reload(const char *name)
}
if (res != AST_LOCK_SUCCESS) {
ast_log(AST_LOG_WARNING, "Cannot grab lock on %s\n", ast_config_AST_CONFIG_DIR);
- ast_mutex_unlock(&reloadlock);
res = AST_MODULE_RELOAD_ERROR;
- goto module_reload_exit;
+ goto module_reload_done;
}
}
@@ -923,8 +923,7 @@ enum ast_module_reload_result ast_module_reload(const char *name)
if (ast_opt_lock_confdir) {
ast_unlock_path(ast_config_AST_CONFIG_DIR);
}
- ast_mutex_unlock(&reloadlock);
- goto module_reload_exit;
+ goto module_reload_done;
}
AST_DLLIST_LOCK(&module_list);
@@ -966,7 +965,9 @@ enum ast_module_reload_result ast_module_reload(const char *name)
if (ast_opt_lock_confdir) {
ast_unlock_path(ast_config_AST_CONFIG_DIR);
}
+module_reload_done:
ast_mutex_unlock(&reloadlock);
+ ast_sd_notify("READY=1");
module_reload_exit:
publish_reload_message(name, res);