3 # lame quickie script to snarf a core of a hung asterisk process.
4 # bugs to ast_grab_core, blinky-lights.org (derrick daugherty)
6 # we have found that gcore doesn't yield as useful a core file
7 # as that yielded by a signal-caused core dump. So we are going to change
8 # the strategy to sending a SEGV signal to the asterisk process,
9 # and have it 'burn to the ground', leaving behind a core file.
10 # the main difference is that you cannot control where the
11 # core file will end up. We will assume that safe_asterisk was
12 # used to start asterisk, and the core file should therefore end
13 # up in /tmp (because safe_asterisk cd's there before starting asterisk).
14 # if this is not the case, set DUMPDIR to the place where the core
17 DATE
=`date +%Y%m%d%H%M`
20 ADMINEMAIL
="root@localhost"
22 #the following should be improved
23 if [ -e /etc
/asterisk
/asterisk.conf
]; then
24 RUNDIR
=`awk -F"=>" '/astrundir/ {print $2}' /etc/asterisk/asterisk.conf`
25 PID
=`cat ${RUNDIR}/asterisk.pid`
26 elif [ -e /var
/run
/asterisk.pid
] ; then
27 PID
=`cat /var/run/asterisk.pid`
29 echo Could not
find an asterisk.conf definition
for astrundir
, using
\'ps
\'
30 echo to try and determine process ID. This is not reliable.
31 PID
=`ps auxwf|grep asterisk|grep vv|head -1|awk '{print $2}'`
34 echo Snarfing asterisk core
, this could take a few seconds depending
35 echo on how much memory is
in use.
37 echo \
*\
*\
* WARNING \
*\
*\
* If the system is not already locked this will cause the
38 echo \
*\
*\
* WARNING \
*\
*\
* process to STOP
while memory is dumped to disk.
43 echo Snarfed
! ${DUMPDIR}/core.
${PID}
47 echo Trying
for a backtrace of the captured core.
48 /usr
/bin
/gdb
/usr
/sbin
/asterisk
${DUMPDIR}/core.${PID} > ${DUMPDIR}/gdb_dump.${PID}.txt
2> /dev
/null
<< EOF
51 echo --------------------------------------------------------------------------------\n
54 echo --------------------------------------------------------------------------------\n
55 echo THREAD APPLY ALL BT
57 echo --------------------------------------------------------------------------------\n
58 echo THREAD APPLY ALL BT FULL
59 thread apply all bt full
62 echo Done trying
for a bt.
65 echo Notifying admins of the core.
66 /usr
/bin
/mail -s "${HOSTNAME} core dumped at ${DUMPDIR}/core.${PID}" ${ADMINEMAIL} < ${DUMPDIR}/gdb_dump.${PID}.txt
69 echo Reproducible deadlocks should be posted with a full backtrace and instructions
70 echo to reproduce the issue at http://bugs.digium.com/ Thanks!