ast_grab_core 2.5 KB

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