[svn-commits] oej: branch oej/moremanager r63151 - in /team/oej/moremanager: ./ main/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sat May 5 05:35:06 MST 2007


Author: oej
Date: Sat May  5 07:35:06 2007
New Revision: 63151

URL: http://svn.digium.com/view/asterisk?view=rev&rev=63151
Log:
- Adding manager event ModuleLoadReport for report when system has finished loading
  all modules
- Adding manager action for module load, reload, unload

This is based on mail conversation with Martin Smith. Please test.

Modified:
    team/oej/moremanager/CHANGES.moremanager
    team/oej/moremanager/main/loader.c

Modified: team/oej/moremanager/CHANGES.moremanager
URL: http://svn.digium.com/view/asterisk/team/oej/moremanager/CHANGES.moremanager?view=diff&rev=63151&r1=63150&r2=63151
==============================================================================
--- team/oej/moremanager/CHANGES.moremanager (original)
+++ team/oej/moremanager/CHANGES.moremanager Sat May  5 07:35:06 2007
@@ -98,6 +98,21 @@
 	New header
 	- (new)		-> Items: 	Reports number of channels reported
 
+* NEW ACTIONS
+-------------
+- Action: ModuleLoad
+	Modules: loader.c
+	Purpose:
+		To be able to unload, reload and unload modules from AMI.
+	Variables: 
+	  ActionID: <id>          Action ID for this transaction. Will be returned.
+  	  Module: <name>          Asterisk module name (including .so extension)
+				  or subsystem identifier:
+				cdr, enum, dnsmgr, extconfig, manager, rtp, http
+          LoadType: load | unload | reload
+                          The operation to be done on module
+	If no module is specified for a reload loadtype, all modules are reloaded
+
 * NEW EVENTS
 ------------
 
@@ -178,6 +193,20 @@
 		AccountCode: Stinas account 1234848484
 		OldAccountCode: OllesAccount 12345
 
+- Event: ModuleLoadReport
+	Modules: loader.c
+	Purpose: To report that module loading is complete. Some aggressive
+		clients connect very quickly to AMI and needs to know when
+		all manager events embedded in modules are loaded
+		Also, if this does not happen, something is seriously wrong.
+		This could happen to chan_sip and other modules using DNS.
+	Example:
+		Event: ModuleLoad
+		ModuleLoadStatus: Done
+		ModuleSelection: All
+		ModuleCount: 24
+		
+
 * TODO
 ------
 - Someone needs to fix "iaxpeers"

Modified: team/oej/moremanager/main/loader.c
URL: http://svn.digium.com/view/asterisk/team/oej/moremanager/main/loader.c?view=diff&rev=63151&r1=63150&r2=63151
==============================================================================
--- team/oej/moremanager/main/loader.c (original)
+++ team/oej/moremanager/main/loader.c Sat May  5 07:35:06 2007
@@ -79,6 +79,9 @@
 static unsigned int embedding = 1; /* we always start out by registering embedded modules,
 				      since they are here before we dlopen() any
 				   */
+/* Forward declaration */
+static int manager_moduleload(struct mansession *s, const struct message *m);
+static char mandescr_moduleload[];
 
 struct ast_module {
 	const struct ast_module_info *info;
@@ -706,6 +709,7 @@
 	unsigned int load_count;
 	struct load_order load_order;
 	int res = 0;
+	int modulecount = 0;
 #if LOADABLE_MODULES
 	struct dirent *dirent;
 	DIR *dir;
@@ -809,6 +813,7 @@
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&load_order, order, entry) {
 		switch (load_resource(order->resource, 1)) {
 		case AST_MODULE_LOAD_SUCCESS:
+			modulecount++;
 		case AST_MODULE_LOAD_DECLINE:
 			AST_LIST_REMOVE_CURRENT(&load_order, entry);
 			free(order->resource);
@@ -828,6 +833,7 @@
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&load_order, order, entry) {
 		switch (load_resource(order->resource, 0)) {
 		case AST_MODULE_LOAD_SUCCESS:
+			modulecount++;
 		case AST_MODULE_LOAD_DECLINE:
 			AST_LIST_REMOVE_CURRENT(&load_order, entry);
 			free(order->resource);
@@ -851,6 +857,12 @@
 
 	AST_LIST_UNLOCK(&module_list);
 
+	ast_manager_register2("ModuleLoad", EVENT_FLAG_SYSTEM, manager_moduleload, "Module management", mandescr_moduleload);
+
+	/* Tell manager clients that are aggressive at logging in that we're done
+	   loading modules. If there's a DNS problem in chan_sip, we might not
+	   even reach this */
+	manager_event(EVENT_FLAG_SYSTEM, "ModuleLoadReport", "ModuleLoadStatus: Done\r\nModuleSelection: %s\r\nModuleCount: %d\r\n", preload_only ? "Preload" : "All", modulecount);
 	return res;
 }
 
@@ -931,3 +943,55 @@
 	ast_atomic_fetchadd_int(&mod->usecount, -1);
 	ast_update_use_count();
 }
+
+static char mandescr_moduleload[] = 
+"Description: Loads, unloads or reloads an Asterisk module in a running system.\n"
+"Variables: \n"
+"  ActionID: <id>          Action ID for this transaction. Will be returned.\n"
+"  Module: <name>          Asterisk module name (including .so extension)\n"
+"                          or subsystem identifier:\n"
+"				cdr, enum, dnsmgr, extconfig, manager, rtp, http\n"
+"  LoadType: load | unload | reload\n"
+"                          The operation to be done on module\n"
+" If no module is specified for a reload loadtype, all modules are reloaded";
+
+static int manager_moduleload(struct mansession *s, const struct message *m)
+{
+	int res;
+	const char *module = astman_get_header(m, "Module");
+	const char *loadtype = astman_get_header(m, "LoadType");
+
+	if (!loadtype || strlen(loadtype) == 0)
+		astman_send_error(s, m, "Incomplete ModuleLoad action.");
+	if ((!module || strlen(module) == 0) && strcasecmp(loadtype, "reload") != 0)
+		astman_send_error(s, m, "Need module name");
+
+	if (!strcasecmp(loadtype, "load")) {
+		res = ast_load_resource(module);
+		if (res)
+			astman_send_error(s, m, "Could not load module.");
+		else
+			astman_send_ack(s, m, "Module loaded.");
+	} else if (!strcasecmp(loadtype, "unload")) {
+		res = ast_unload_resource(module, AST_FORCE_SOFT);
+		if (res)
+			astman_send_error(s, m, "Could not unload module.");
+		else
+			astman_send_ack(s, m, "Module unloaded.");
+	} else if (!strcasecmp(loadtype, "reload")) {
+		if (module != NULL) {
+			res = ast_module_reload(module);
+			if (res == 0)
+				astman_send_error(s, m, "No such module.");
+			else if (res == 1)
+				astman_send_error(s, m, "Module does not support reload action.");
+			else
+				astman_send_ack(s, m, "Module reloaded.");
+		} else {
+			ast_module_reload(NULL);	/* Reload all modules */
+			astman_send_ack(s, m, "All modules reloaded");
+		}
+	} else 
+		astman_send_error(s, m, "Incomplete ModuleLoad action.");
+	return 0;
+}



More information about the svn-commits mailing list