login | register
Tue 02 of Dec, 2008 [01:53 UTC]

voip-info.org

Discuss [5] History

Asterisk cmd DeadAGI

Created by: oej,Last modification on Sat 08 of Dec, 2007 [00:49 UTC] by JustRumours
DeadAGI is a variant of AGI that you use when the channel is hung up.

Syntax and Usage:

Please refer to the AGI application for general AGI information as the syntax and usage are identical.

The main difference is that the AGI application may terminate if the line is hung up during execution and DeadAGI will not terminate even if the call is hung up during execution, however, the call leg will not automatically enter a "down" state until execution is completed if executed on a live line. As such, commands and applications designed to return the call state will inaccurately return an "up" status.

This also means that any calls stuck in a DeadAGI execution upon hangup will continue to be considered "up" by the CDR. It is very important for your script to be aggressive in completing after hangup in order to maintain accurate CDR records.

A possible method of checking the channel would be to "exec playback" of an audio file (possibly a short, silent file) and look for the returned result of that execution. This relies on the fact that the file actually exists and will "answer" the call if it is not yet up. Of course, this will display a "Failed to write frame" warning on failure, returning -1 and indicating the channel is down. It returns a 0 result on success.

Versions

This command was added to the development (CVS) edition of Asterisk on 2004-03-03. It does not exist in Asterisk 1.0 or 0.9.
It is available in 1.0.9 and 1.2.x.

Notes

I can't verify lack of presence in 1.0 or 0.9, but I can verify presence in 1.0.9 and 1.2.x. Anyone using older copies, please update version information. Thanks - Flobi

Alternative approach: SIGHUP

Q: I've got a very nice PHP AGI script but I want to be able to do some database cleanup when the user hangs up the phone. I wish everyone would hang up when they were suposed to, but some people don't. So what does Asterisk send to an AGI file when the line has been disconnected?

A: SIGHUP

Q: If I remember reading somewhere correctly, I don't need to use DeadAGI. Instead I'm able to use normal AGI but I just need to catch a SIGTERM or something like that and process it.

A: You need to catch it or the script will terminate. Not sure if this is possible at all in PHP. I think there's an inofficial POSIX module which can do it. Perl can do it for sure.

In fact, if you need to cleanup connections, catching the signal is EXACTLY what you ought to do. Just bear in mind that as soon as you get a signal, the current version of AGI will stop interacting with your script.
Note: This has been changed for the next release cycle (Asterisk 1.6), so AGI will transparently switch over to what is now DeadAGI behavior (after sending a HUP) and continue to interact with the script until the script dies (which is what most people wanted anyway).

In Asterisk 1.2 even a DeadAGI script will receive a SIGHUP and may terminate when the channel is hung up. Your script will have to block SIGHUP signals, which you can do like so:

Perl:
 $SIG{HUP} = "IGNORE" (Perl)

PHP (though you must compile with --enable-pcntl to get this function):
 pcntl_signal(SIGHUP, SIG_IGN)

Ruby:
 trap('SIGHUP','IGNORE')

In addition, don't try and communicate with the Asterisk server after the hangup or you'll receive a SIGPIPE which will also terminate your script (again unless you ignore it). To avoid this be sure and check result codes. Info gathered from bug4845

See also



Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ


Comments

Comments Filter
222

333Re:

by bo_shen, Friday 01 of August, 2008 [10:48:23 UTC]
For, at least, asterisk 1.4.17, when the script is inside the DeadAGI, there is no SIGHUP sent to the script. It only sends when the script is in the AGI. Hope that helps
222

333

by steved67fb, Tuesday 10 of June, 2008 [19:05:34 UTC]
I'm seeing strang behavior trying to trap SIGHUP from an Asterisk session using my php script.
I do all the usual, declare (ticks=1);
pcntl_signal(SIGHUP, "my_handler_func");

etc..etc..
I don't see the call hangup signaling me.
BUT, here's the strange part, if I throw in a posix_kill call to send a SIGHUP signal, my script does get the signal as expected (this is when asterisk is calling my script during a phone call).
So I know the signaling works, and I also installed and configured php with the pcntl support.
Any thoughts??
222

333asterisk 1.6 beta 3 and DeadAGI

by gianrico, Thursday 21 of February, 2008 [18:03:17 UTC]
In asterisk 1.6 you should always use Agi cmd and never DeadAGI (is deprecated). If you want to keep up the agi script after hangup you can use $SIG{HUP} = "IGNORE" (perl).
After that if you "hang up" a call the script will go ahead and the channel in asterisk remains up (you will see that with 'core show channels'). So you can communicate with asterisk after the 'hang up' and read channel variables. Another way should be to use set(AGISIGHUP=no) in extensions.ael but it seems to not work property (can you help?).
That is not true for Asterisk 1.4 (I tried with 1.4.18). After the hang-up you will not be able to read variables from asterisk because the channel is deleted.


222

333Attention to use DeadAGI!!!

by ig0rb79, Tuesday 31 of July, 2007 [00:43:04 UTC]
From 1.2.20 something change....
http://lists.digium.com/pipermail/asterisk-dev/2007-July/028666.html

If u ignore SIGHUP your DeadAGI will not be killed but u can't read DIAL status vars

Changes like this in a stable branchare soo dangerous... all AGI that calculate billing after HangUp stop to work after an asterisk update



222

333DeadAGI apps do receive SIGHUP

by ncc, Thursday 30 of November, 2006 [01:46:53 UTC]
In Asterisk 1.2 even a DeadAGI script will receive a SIGHUP and may terminate when the channel is hung up. Your script will have to block SIGHUP signals, which you can do like so:
$SIG{HUP} = "IGNORE"; (Perl)
pcntl_signal(SIGHUP, SIG_IGN); (PHP, though you must compile with --enable-pcntl to get this function)
trap('SIGHUP','IGNORE') (Ruby)

In addition, don't try and communicate with the Asterisk server after the hangup or you'll receive a SIGPIPE which will also terminate your script (again unless you ignore it). To avoid this be sure and check result codes.

Info gathered from here: http://bugs.digium.com/view.php?id=4854