| 1 | #!/bin/sh |
| 2 | # $Id$ |
| 3 | # lame quickie script to snarf a core of a hung asterisk process. |
| 4 | # bugs to ast_grab_core, blinky-lights.org (derrick daugherty) |
| 5 | |
| 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 |
| 15 | # file can be found. |
| 16 | |
| 17 | DATE=`date +%Y%m%d%H%M` |
| 18 | DUMPDIR=/tmp |
| 19 | HOSTNAME=`hostname` |
| 20 | ADMINEMAIL="root@localhost" |
| 21 | |
| 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` |
| 28 | else |
| 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}'` |
| 32 | fi |
| 33 | |
| 34 | echo Snarfing asterisk core, this could take a few seconds depending |
| 35 | echo on how much memory is in use. |
| 36 | echo |
| 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. |
| 39 | echo |
| 40 | |
| 41 | /bin/kill -11 ${PID} |
| 42 | |
| 43 | echo Snarfed! ${DUMPDIR}/core.${PID} |
| 44 | echo |
| 45 | |
| 46 | |
| 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 |
| 49 | set prompt \n |
| 50 | set print pretty\n |
| 51 | echo --------------------------------------------------------------------------------\n |
| 52 | echo INFO THREAD |
| 53 | info thread |
| 54 | echo --------------------------------------------------------------------------------\n |
| 55 | echo THREAD APPLY ALL BT |
| 56 | thread apply all bt |
| 57 | echo --------------------------------------------------------------------------------\n |
| 58 | echo THREAD APPLY ALL BT FULL |
| 59 | thread apply all bt full |
| 60 | quit |
| 61 | EOF |
| 62 | echo Done trying for a bt. |
| 63 | |
| 64 | |
| 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 |
| 67 | echo Done. |
| 68 | echo |
| 69 | echo Reproducible deadlocks should be posted with a full backtrace and instructions |
| 70 | echo to reproduce the issue at https://github.com/asterisk/asterisk/issues/ Thanks! |