소스 검색

utils/kamctl: new command 'trap'
- useful to get a full bt dump of all kamailio processes
- handy in dead-lock investigatigations

Ovidiu Sas 11 년 전
부모
커밋
71380228bf
3개의 변경된 파일42개의 추가작업 그리고 1개의 파일을 삭제
  1. 28 0
      utils/kamctl/kamctl
  2. 11 1
      utils/kamctl/kamctl.base
  3. 3 0
      utils/kamctl/kamctlrc

+ 28 - 0
utils/kamctl/kamctl

@@ -2644,6 +2644,29 @@ extcmd() {
 	exit 1
 }
 
+##### ================================================ #####
+### trap with gdb kamailio processes
+#
+
+kamailio_trap() {
+	DATE=`/bin/date +%Y%m%d_%H%M%S`
+	LOG_FILE=/tmp/gdb_kamailio_$DATE
+	minfo "Trap file: $LOG_FILE"
+	$SERCTLCMD ps > $LOG_FILE
+	echo -n "Trapping Kamailio with gdb: "
+	PID_TIMESTAMP_VECTOR=`sed -e 's/\([0-9]*\).*/\1/' $LOG_FILE`
+	for pid in $PID_TIMESTAMP_VECTOR
+	do
+		echo -n "."
+		PID=`echo $pid | cut -d '-' -f 1`
+		echo "" >> $LOG_FILE
+		echo "---start $PID -----------------------------------------------------" >> $LOG_FILE
+		$GDB kamailio $PID -batch --eval-command="bt full" &>> $LOG_FILE
+		echo "---end $PID -------------------------------------------------------" >> $LOG_FILE
+	done
+	echo "."
+}
+
 #
 ##### ================================================ #####
 ### main command switch
@@ -2825,6 +2848,11 @@ case $1 in
 		tls_ca "$@"
 		;;
 
+	trap)
+		require_ctlengine
+		kamailio_trap
+		;;
+
 	start)
 		kamailio_start
 		;;

+ 11 - 1
utils/kamctl/kamctl.base

@@ -53,6 +53,15 @@ if [ -z "$AWK" ] ; then
 	fi
 	AWK="$TOOLPATH"
 fi
+if [ -z "$GDB" ] ; then
+	locate_tool gdb
+	if [ -z "$TOOLPATH" ] ; then
+		# now error, but we can look for alternative names if it is the case
+		echo "error: 'gdb' tool not found: set GDB variable to correct tool path"
+		exit
+	fi
+	GDB="$TOOLPATH"
+fi
 if [ -z "$MD5" ]; then
 	locate_tool md5sum md5
 	if [ -z "$TOOLPATH" ] ; then
@@ -340,9 +349,10 @@ DIALPLAN_ATTRS_COLUMN=attrs
 
 usage_base() {
 	echo
-	mecho " -- command 'start|stop|restart'"
+	mecho " -- command 'start|stop|restart|trap'"
 	echo
 cat <<EOF
+ trap ............................... trap with gdb Kamailio processes
  restart ............................ restart Kamailio
  start .............................. start Kamailio
  stop ............................... stop Kamailio

+ 3 - 0
utils/kamctl/kamctlrc

@@ -69,6 +69,9 @@
 # awk tool
 # AWK="awk"
 
+# gdb tool
+# GDB="gdb"
+
 # If you use a system with a grep and egrep that is not 100% gnu grep compatible,
 # e.g. solaris, install the gnu grep (ggrep) and specify this below.
 #