| 1 | #!/bin/shscip-shell filesystem . . `/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=`datescip-shell system . . date. +%Y%m%d%H%M` |
| 18 | DUMPDIR=/tmpscip-shell filesystem . . `/tmp`. |
| 19 | HOSTNAME=`hostnamescip-shell system . . hostname.` |
| 20 | ADMINEMAIL="root@localhost" |
| 21 | |
| 22 | #the following should be improved |
| 23 | if [scip-shell system . . `[`. -e /etc/asterisk/asterisk.confscip-shell filesystem . . `/etc/asterisk/asterisk.conf`. ]; then |
| 24 | RUNDIR=`awkscip-shell system . . awk. -F"=>" '/astrundir/ {print $2}scip-shell filesystem . . `/astrundir/ {print $2}`.' /etc/asterisk/asterisk.confscip-shell filesystem . . `/etc/asterisk/asterisk.conf`.` |
| 25 | PID=`catscip-shell system . . cat. ${RUNDIR}/asterisk.pid` |
| 26 | elif [scip-shell system . . `[`. -e /var/run/asterisk.pidscip-shell filesystem . . `/var/run/asterisk.pid`. ] ; then |
| 27 | PID=`catscip-shell system . . cat. /var/run/asterisk.pidscip-shell filesystem . . `/var/run/asterisk.pid`.` |
| 28 | else |
| 29 | echoscip-shell system . . echo. Could not find an asterisk.conf definition for astrundir, using \'ps\' |
| 30 | echoscip-shell system . . echo. to try and determine process ID. This is not reliable. |
| 31 | PID=`psscip-shell system . . ps. auxwf|grepscip-shell system . . grep. asterisk|grepscip-shell system . . grep. vv|headscip-shell system . . head. -1|awkscip-shell system . . awk. '{print $2}'` |
| 32 | fi |
| 33 | |
| 34 | echoscip-shell system . . echo. Snarfing asterisk core, this could take a few seconds depending |
| 35 | echoscip-shell system . . echo. on how much memory is in use. |
| 36 | echoscip-shell system . . echo. |
| 37 | echoscip-shell system . . echo. \*\*\* WARNING \*\*\* If the system is not already locked this will cause the |
| 38 | echoscip-shell system . . echo. \*\*\* WARNING \*\*\* process to STOP while memory is dumped to disk. |
| 39 | echoscip-shell system . . echo. |
| 40 | |
| 41 | /bin/killscip-shell filesystem . . `/bin/kill`. -11 ${PID} |
| 42 | |
| 43 | echoscip-shell system . . echo. Snarfed! ${DUMPDIR}/core.${PID} |
| 44 | echoscip-shell system . . echo. |
| 45 | |
| 46 | |
| 47 | echoscip-shell system . . echo. Trying for a backtrace of the captured core. |
| 48 | /usr/bin/gdbscip-shell filesystem . . `/usr/bin/gdb`. /usr/sbin/asteriskscip-shell filesystem . . `/usr/sbin/asterisk`. ${DUMPDIR}/core.${PID} > ${DUMPDIR}/gdb_dump.${PID}.txt 2> /dev/nullscip-shell filesystem . . `/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 | echoscip-shell system . . echo. Done trying for a bt. |
| 63 | |
| 64 | |
| 65 | echoscip-shell system . . echo. Notifying admins of the core. |
| 66 | /usr/bin/mailscip-shell filesystem . . `/usr/bin/mail`. -s "${HOSTNAME} core dumped at ${DUMPDIR}/core.${PID}" ${ADMINEMAIL} < ${DUMPDIR}/gdb_dump.${PID}.txt |
| 67 | echoscip-shell system . . echo. Done. |
| 68 | echoscip-shell system . . echo. |
| 69 | echoscip-shell system . . echo. Reproducible deadlocks should be posted with a full backtrace and instructions |
| 70 | echoscip-shell system . . echo. to reproduce the issue at https://github.com/asterisk/asterisk/issues/ Thanks! |