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:00:14 -0600
commit36092ee3a087e6c37bf4efcd101b324f1ba9fada (patch)
treeac29aa9d7f96cf21b20418f4990ea79d2d561ced /main
parent34461b89ace3742056100bb226a3c0c2d90ca5ff (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/Makefile2
-rw-r--r--main/asterisk.c4
-rw-r--r--main/io.c10
-rw-r--r--main/loader.c9
4 files changed, 21 insertions, 4 deletions
diff --git a/main/Makefile b/main/Makefile
index 13f1c9cf5..e476969c9 100644
--- a/main/Makefile
+++ b/main/Makefile
@@ -44,6 +44,8 @@ AST_LIBS+=$(URIPARSER_LIB)
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 kfreebsd-gnu),)
ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
diff --git a/main/asterisk.c b/main/asterisk.c
index 69f1d7140..9ac9c4619 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -2124,6 +2124,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()) {
@@ -4612,6 +4615,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 cd35995ad..c2d2f9dd3 100644
--- a/main/io.c
+++ b/main/io.c
@@ -36,6 +36,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#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 f660a624d..85aeb249e 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -897,6 +897,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) {
@@ -910,9 +911,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;
}
}
@@ -929,8 +929,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);
@@ -972,7 +971,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);