[Asterisk-code-review] cli: Add module refresh command (asterisk[master])

N A asteriskteam at digium.com
Wed Dec 15 08:27:24 CST 2021


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/17700 )


Change subject: cli: Add module refresh command
......................................................................

cli: Add module refresh command

Adds a command to the CLI to unload and then
load a module. This makes it easier to perform
these operations which are often done
subsequently to load a new version of a module.

"module reload" already refers to reloading of
configuration, so the name "refresh" is chosen
instead.

ASTERISK-29807 #close

Change-Id: I595f6f11774a0de2565a1fba38da22309ce93a2c
---
A doc/CHANGES-staging/cli_refresh.txt
M main/cli.c
2 files changed, 40 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/00/17700/1

diff --git a/doc/CHANGES-staging/cli_refresh.txt b/doc/CHANGES-staging/cli_refresh.txt
new file mode 100644
index 0000000..82bcd23
--- /dev/null
+++ b/doc/CHANGES-staging/cli_refresh.txt
@@ -0,0 +1,5 @@
+Subject: cli
+
+The "module refresh" command has been added,
+which allows unloading and then loading a
+module with a single command.
diff --git a/main/cli.c b/main/cli.c
index dc13019..ae5693b 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -805,6 +805,39 @@
 	return CLI_SUCCESS;
 }
 
+static char *handle_refresh(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	int force = AST_FORCE_SOFT;
+	/* "module refresh <mod>" */
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "module refresh";
+		e->usage =
+			"Usage: module refresh <module name>\n"
+			"       Unloads and loads the specified module into Asterisk.\n";
+		return NULL;
+
+	case CLI_GENERATE:
+		if (a->pos != e->args) {
+			return NULL;
+		}
+		return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, AST_MODULE_HELPER_LOAD);
+	}
+	if (a->argc != e->args + 1) {
+		return CLI_SHOWUSAGE;
+	}
+	if (ast_unload_resource(a->argv[e->args], force)) {
+		ast_cli(a->fd, "Unable to unload resource %s\n", a->argv[e->args]);
+		return CLI_FAILURE;
+	}
+	if (ast_load_resource(a->argv[e->args])) {
+		ast_cli(a->fd, "Unable to load module %s\n", a->argv[e->args]);
+		return CLI_FAILURE;
+	}
+	ast_cli(a->fd, "Unloaded and loaded %s\n", a->argv[e->args]);
+	return CLI_SUCCESS;
+}
+
 static char *handle_unload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	/* "module unload mod_1 [mod_2 .. mod_N]" */
@@ -2016,6 +2049,8 @@
 
 	AST_CLI_DEFINE(handle_unload, "Unload a module by name"),
 
+	AST_CLI_DEFINE(handle_refresh, "Completely unloads and loads a module by name"),
+
 	AST_CLI_DEFINE(handle_showuptime, "Show uptime information"),
 
 	AST_CLI_DEFINE(handle_softhangup, "Request a hangup on a given channel"),

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/17700
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I595f6f11774a0de2565a1fba38da22309ce93a2c
Gerrit-Change-Number: 17700
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20211215/48c75712/attachment.html>


More information about the asterisk-code-review mailing list