[asterisk-gui] executecommand script
David Kerr
David at kerr.net
Thu Dec 18 16:53:31 CST 2008
Brandon, et al. One issue I have been seeing a lot of is a channel
remaining open in the asterisk_guitools context, executecommand "extension".
Invariably if I look at the open channels I will see one or more channels
in "Ring" state often with a duration in the thousands, if not tens or
hundreds of thousands of seconds. They just never go away, and clicking on
"hangup" in the active channels page does nothing.
I have been investigating this for some time to try and find a solution, but
rather than finding a solution I just find one gotcha after another. First
the context (as built by pbx.js) looks like...
exten=executecommand,1,System(${command})
exten=executecommand,n,Hangup
The parameters to the System() call being setup in astman.js. First thing I
observed is that there is no timeout condition... there is a timeout set on
the call to the AMI in astman.js (for 60 seconds!) but that timeout is only
for until control is passed to the context? (
http://www.voip-info.org/wiki/view/Asterisk+Manager+API+Action+Originate)
and not a timeout for the System() command inside the context. So I
considered adding a timeout(absolute) to the script. But find that this only
works after an Answer (
http://www.voip-info.org/wiki/view/Asterisk+cmd+AbsoluteTimeout)... which is
when I realized that the "call" is never answered... maybe that is why it
sometimes gets stuck on "Ring". So I tried...
exten=executecommand,1,Answer
exten=executecommand,n,Set(TIMEOUT(absolute)=30)
exten=executecommand,n,System(${command})
exten=executecommand,n,Hangup
exten=T,1,Hangup
But on testing this I find that while it works when the command being
executed is VERY quick, it fails when the command is slow (I'm doing some
other enhancements that execute a wget, which needs time (1 or 2 seconds) to
pull results from the network). It fails because as soon as the call is
"answered" control returns to the callback function set in astman.js...
which then attempts to read the result from the command (as saved in
sysinfo_output.html), which may not have completed yet. If I move the Answer
statement to after the System call, then it works again... but then the
behavior of Timeout(absolute) is undefined (according to
http://www.voip-info.org/wiki/view/Asterisk+cmd+AbsoluteTimeout) which
states that extension "T" will never get called.
So I am in a catch 22 situation.
I also tried changing astman.js in the systemCmd() function... rather than
make a request with a "noop" application, I told it to use "System" and
passed some data into it (also modifying the context not to call System).
Same problem... because of the asynchronous nature of the request, control
passes to the callback before the command I want to execute completes. I
have not tried making a synchronous request on the asterisk manager API
because I don't want to hang the user interface while the command executes
on the server.
So... any ideas. I'd like a way to stop these phantom channels remaining
open?
Thanks,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-gui/attachments/20081218/41731d00/attachment.htm
More information about the asterisk-gui
mailing list