mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 18:55:19 +00:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -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)),) | ||||
|   | ||||
| @@ -1999,6 +1999,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()) { | ||||
| @@ -4526,6 +4529,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.")); | ||||
|  | ||||
|   | ||||
							
								
								
									
										10
									
								
								main/io.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								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 | ||||
| } | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user