]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
cli: Add module refresh command
authorNaveen Albert <asterisk@phreaknet.org>
Wed, 15 Dec 2021 14:23:06 +0000 (14:23 +0000)
committerJoshua Colp <jcolp@sangoma.com>
Wed, 5 Jan 2022 17:22:11 +0000 (11:22 -0600)
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

doc/CHANGES-staging/cli_refresh.txt [new file with mode: 0644]
main/cli.c

diff --git a/doc/CHANGES-staging/cli_refresh.txt b/doc/CHANGES-staging/cli_refresh.txt
new file mode 100644 (file)
index 0000000..82bcd23
--- /dev/null
@@ -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.
index 3b4c958bc5716497853c84c17f3db722290ebe55..fb4dbc58ef9efbd5ea515e0355abb0ad8b73df81 100644 (file)
@@ -805,6 +805,38 @@ static char *handle_logger_mute(struct ast_cli_entry *e, int cmd, struct ast_cli
        return CLI_SUCCESS;
 }
 
+static char *handle_refresh(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+       /* "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_UNLOAD);
+       }
+       if (a->argc != e->args + 1) {
+               return CLI_SHOWUSAGE;
+       }
+       if (ast_unload_resource(a->argv[e->args], AST_FORCE_SOFT)) {
+               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]" */
@@ -2025,6 +2057,8 @@ static struct ast_cli_entry cli_cli[] = {
 
        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"),