3 # This script only works on Linux. Please modify (and submit patches)
4 # for other operating systems.
6 [ -n "$CTDB_BASE" ] || \
7 export CTDB_BASE
=$
(cd -P $
(dirname "$0") ; echo "$PWD")
9 .
"$CTDB_BASE/functions"
14 if [ -n "$CTDB_DEBUG_HUNG_SCRIPT_LOGFILE" ] ; then
15 tmp
="${CTDB_DEBUG_HUNG_SCRIPT_LOGFILE}.part"
20 # No use running several of these in parallel if, say, "releaseip"
21 # event hangs for multiple IPs. In that case the output would be
22 # interleaved in the log and would just be confusing.
23 flock
--wait 2 9 ||
exit 1
25 echo "===== Start of hung script debug for PID=\"$1\", event=\"$2\" ====="
27 echo "pstree -p -a ${1}:"
28 out
=$
(pstree
-p -a $1)
31 # Check for processes matching a regular expression and print
32 # stack staces. This could help confirm that certain processes
33 # are stuck in certain places such as the cluster filesystem. The
34 # regexp must separate items with "|" and must not contain
35 # parentheses. The default pattern can be replaced for testing.
36 default_pat
='exportfs|rpcinfo'
37 pat
="${CTDB_DEBUG_HUNG_SCRIPT_STACKPAT:-${default_pat}}"
39 sed -r -n "s@.*-(.*(${pat}).*),([0-9]*).*@\3 \1@p" |
40 while read pid name
; do
41 trace
=$
(cat "/proc/${pid}/stack" 2>/dev
/null
)
42 if [ $?
-eq 0 ] ; then
43 echo "---- Stack trace of interesting process ${pid}[${name}] ----"
48 if [ "$2" != "init" ] ; then
49 echo "---- ctdb scriptstatus ${2}: ----"
50 ctdb scriptstatus
"$2"
53 echo "===== End of hung script debug for PID=\"$1\", event=\"$2\" ====="
55 if [ -n "$CTDB_DEBUG_HUNG_SCRIPT_LOGFILE" ] ; then
56 mv "$tmp" "$CTDB_DEBUG_HUNG_SCRIPT_LOGFILE"
59 ) 9>"${CTDB_VARDIR}/debug-hung-script.lock"