summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2016-09-20 14:03:15 -0500
committerGerrit Code Review <gerrit2@gerrit.digium.api>2016-09-20 14:03:15 -0500
commit77fafd15343c21a6c26e311086b944ca0428b386 (patch)
tree2407ff1425724e061f32c02e65567b82a49eeb52 /main
parent177557bc00b59a1ef6c64cf2ca86cebe18d227d6 (diff)
parent36092ee3a087e6c37bf4efcd101b324f1ba9fada (diff)
Merge "sd_notify (systemd status notifications) support" into 13
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);