| 1 | /* |
| 2 | * Asterisk -- An open source telephony toolkit. |
| 3 | * |
| 4 | * Copyright (C) 2021, Naveen Albert |
| 5 | * |
| 6 | * Naveen Albert <[email protected]> |
| 7 | * |
| 8 | * See http://www.asterisk.org for more information about |
| 9 | * the Asterisk project. Please do not directly contact |
| 10 | * any of the maintainers of this project for assistance; |
| 11 | * the project provides a web site, mailing lists and IRC |
| 12 | * channels for your use. |
| 13 | * |
| 14 | * This program is free software, distributed under the terms of |
| 15 | * the GNU General Public License Version 2. See the LICENSE file |
| 16 | * at the top of the source tree. |
| 17 | */ |
| 18 | |
| 19 | /*! \file |
| 20 | * |
| 21 | * \brief Reload Asterisk modules |
| 22 | * |
| 23 | * \author Naveen Albert <[email protected]> |
| 24 | * |
| 25 | * \ingroup applications |
| 26 | */ |
| 27 | |
| 28 | /*** MODULEINFO |
| 29 | <support_level>extended</support_level> |
| 30 | ***/ |
| 31 | |
| 32 | #include "asterisk.h" |
| 33 | |
| 34 | #include "asterisk/logger.h" |
| 35 | #include "asterisk/channel.h" |
| 36 | #include "asterisk/pbx.h" |
| 37 | #include "asterisk/module.h" |
| 38 | #include "asterisk/app.h" |
| 39 | |
| 40 | /*** DOCUMENTATION |
| 41 | <application name="Reload" language="en_US"> |
| 42 | <since> |
| 43 | <version>16.20.0</version> |
| 44 | <version>18.6.0</version> |
| 45 | </since> |
| 46 | <synopsis> |
| 47 | Reloads an Asterisk module, blocking the channel until the reload has completed. |
| 48 | </synopsis> |
| 49 | <syntax> |
| 50 | <parameter name="module" required="false"> |
| 51 | <para>The full name(s) of the target module(s) or resource(s) to reload. |
| 52 | If omitted, everything will be reloaded.</para> |
| 53 | <para>The full names MUST be specified (e.g. <literal>chan_iax2</literal> |
| 54 | to reload IAX2 or <literal>pbx_config</literal> to reload the dialplan.</para> |
| 55 | </parameter> |
| 56 | </syntax> |
| 57 | <description> |
| 58 | <para>Reloads the specified (or all) Asterisk modules and reports success or failure. |
| 59 | Success is determined by each individual module, and if all reloads are successful, |
| 60 | that is considered an aggregate success. If multiple modules are specified and any |
| 61 | module fails, then FAILURE will be returned. It is still possible that other modules |
| 62 | did successfully reload, however.</para> |
| 63 | <para>Sets <variable>RELOADSTATUS</variable> to one of the following values:</para> |
| 64 | <variablelist> |
| 65 | <variable name="RELOADSTATUS"> |
| 66 | <value name="SUCCESS"> |
| 67 | Specified module(s) reloaded successfully. |
| 68 | </value> |
| 69 | <value name="FAILURE"> |
| 70 | Some or all of the specified modules failed to reload. |
| 71 | </value> |
| 72 | </variable> |
| 73 | </variablelist> |
| 74 | </description> |
| 75 | </application> |
| 76 | ***/ |
| 77 | |
| 78 | static char *app = "Reload"; |
| 79 | |
| 80 | static int reload_exec(struct ast_channel *chan, const char *data) |
| 81 | { |
| 82 | char *targets, *target = NULL; |
| 83 | enum ast_module_reload_result res = AST_MODULE_RELOAD_SUCCESS; |
| 84 | |
| 85 | targets = ast_strdupa(data); |
| 86 | ast_autoservice_start(chan); |
| 87 | if (ast_strlen_zero(targets)) { /* Reload everything */ |
| 88 | res = ast_module_reload(NULL); |
| 89 | } else { |
| 90 | while((target = ast_strsep(&targets, ',', AST_STRSEP_ALL))) { |
| 91 | res |= ast_module_reload(target); |
| 92 | } |
| 93 | } |
| 94 | ast_autoservice_stop(chan); |
| 95 | |
| 96 | if (res == AST_MODULE_RELOAD_SUCCESS) { |
| 97 | pbx_builtin_setvar_helper(chan, "RELOADSTATUS", "SUCCESS"); |
| 98 | } else { |
| 99 | pbx_builtin_setvar_helper(chan, "RELOADSTATUS", "FAILURE"); |
| 100 | } |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static int unload_module(void) |
| 105 | { |
| 106 | return ast_unregister_application(app); |
| 107 | } |
| 108 | |
| 109 | static int load_module(void) |
| 110 | { |
| 111 | return ast_register_application_xml(app, reload_exec); |
| 112 | } |
| 113 | |
| 114 | AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Reload module(s)"); |