Skip to content

Commit 244491f

Browse files
InterLinked1Friendly Automation
authored and
Friendly Automation
committed
app_reload: New Reload application
Adds an application to reload modules from within the dialplan. ASTERISK-29454 Change-Id: Ic8ab025d8b38dd525b872b41c465c999c5810774
1 parent 99d44f0 commit 244491f

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

apps/app_reload.c

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Asterisk -- An open source telephony toolkit.
3+
*
4+
* Copyright (C) 2021, Naveen Albert
5+
*
6+
* Naveen Albert <asterisk@phreaknet.org>
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 <asterisk@phreaknet.org>
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+
<synopsis>
43+
Reloads an Asterisk module, blocking the channel until the reload has completed.
44+
</synopsis>
45+
<syntax>
46+
<parameter name="module" required="false">
47+
<para>The full name(s) of the target module(s) or resource(s) to reload.
48+
If omitted, everything will be reloaded.</para>
49+
<para>The full names MUST be specified (e.g. <literal>chan_iax2</literal>
50+
to reload IAX2 or <literal>pbx_config</literal> to reload the dialplan.</para>
51+
</parameter>
52+
</syntax>
53+
<description>
54+
<para>Reloads the specified (or all) Asterisk modules and reports success or failure.
55+
Success is determined by each individual module, and if all reloads are successful,
56+
that is considered an aggregate success. If multiple modules are specified and any
57+
module fails, then FAILURE will be returned. It is still possible that other modules
58+
did successfully reload, however.</para>
59+
<para>Sets <variable>RELOADSTATUS</variable> to one of the following values:</para>
60+
<variablelist>
61+
<variable name="RELOADSTATUS">
62+
<value name="SUCCESS">
63+
Specified module(s) reloaded successfully.
64+
</value>
65+
<value name="FAILURE">
66+
Some or all of the specified modules failed to reload.
67+
</value>
68+
</variable>
69+
</variablelist>
70+
</description>
71+
</application>
72+
***/
73+
74+
static char *app = "Reload";
75+
76+
static int reload_exec(struct ast_channel *chan, const char *data)
77+
{
78+
char *targets, *target = NULL;
79+
enum ast_module_reload_result res = AST_MODULE_RELOAD_SUCCESS;
80+
81+
targets = ast_strdupa(data);
82+
ast_autoservice_start(chan);
83+
if (ast_strlen_zero(targets)) { /* Reload everything */
84+
res = ast_module_reload(targets);
85+
} else {
86+
while((target = ast_strsep(&targets, ',', AST_STRSEP_ALL))) {
87+
res |= ast_module_reload(target);
88+
}
89+
}
90+
ast_autoservice_stop(chan);
91+
92+
if (res == AST_MODULE_RELOAD_SUCCESS) {
93+
pbx_builtin_setvar_helper(chan, "RELOADSTATUS", "SUCCESS");
94+
} else {
95+
pbx_builtin_setvar_helper(chan, "RELOADSTATUS", "FAILURE");
96+
}
97+
return 0;
98+
}
99+
100+
static int unload_module(void)
101+
{
102+
return ast_unregister_application(app);
103+
}
104+
105+
static int load_module(void)
106+
{
107+
return ast_register_application_xml(app, reload_exec);
108+
}
109+
110+
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Reload module(s)");

doc/CHANGES-staging/app_reload.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Subject: New Reload application
2+
3+
Adds an application to reload modules
4+

0 commit comments

Comments
 (0)