[sr-dev] git:master:97ec8555: kamctl: added pstrap command

Daniel-Constantin Mierla miconda at gmail.com
Tue Jul 7 18:58:21 CEST 2020


Module: kamailio
Branch: master
Commit: 97ec85559f1e33405fff2320443dc86d2df13456
URL: https://github.com/kamailio/kamailio/commit/97ec85559f1e33405fff2320443dc86d2df13456

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-07-07T18:57:27+02:00

kamctl: added pstrap command

- use ps to get list of PIDs for Kamailio instance, instead of RPC
core.psx

---

Modified: utils/kamctl/kamctl
Modified: utils/kamctl/kamctl.base

---

Diff:  https://github.com/kamailio/kamailio/commit/97ec85559f1e33405fff2320443dc86d2df13456.diff
Patch: https://github.com/kamailio/kamailio/commit/97ec85559f1e33405fff2320443dc86d2df13456.patch

---

diff --git a/utils/kamctl/kamctl b/utils/kamctl/kamctl
index 211e0cf042..a7a63c64a3 100755
--- a/utils/kamctl/kamctl
+++ b/utils/kamctl/kamctl
@@ -2909,7 +2909,7 @@ extcmd() {
 }
 
 ##### ================================================ #####
-### trap with gdb kamailio processes
+### trap with gdb kamailio processes using RPC core.psx
 #
 
 kamailio_trap() {
@@ -2935,6 +2935,35 @@ kamailio_trap() {
 	echo "."
 }
 
+##### ================================================ #####
+### trap with gdb kamailio processes using ps command
+#
+
+kamailio_pstrap() {
+	if [ -z "$GDB" ] ; then
+		merr "'gdb' tool not found: set GDB variable to correct tool path"
+		exit
+	fi
+	DATE=`/bin/date +%Y%m%d_%H%M%S`
+	LOG_FILE=/tmp/gdb_kamailio_${DATE}.txt
+	minfo "Trap file: $LOG_FILE"
+	ps axw | grep kamailio | grep -v grep | sort > $LOG_FILE
+	echo "" >> $LOG_FILE
+	echo "" >> $LOG_FILE
+	echo -n "Trapping Kamailio with gdb: "
+	PID_TIMESTAMP_VECTOR=`ps axw | grep kamailio | grep -v grep | sort | awk '{print $1}'`
+	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 2>&1
+		echo "---end $PID -------------------------------------------------------" >> $LOG_FILE
+	done
+	echo "."
+}
+
 #
 ##### ================================================ #####
 ### main command switch
@@ -3147,6 +3176,10 @@ case $1 in
 		kamailio_trap
 		;;
 
+	pstrap)
+		kamailio_pstrap
+		;;
+
 	start)
 		kamailio_start
 		;;
diff --git a/utils/kamctl/kamctl.base b/utils/kamctl/kamctl.base
index 6dd3686b39..bc8f212f7b 100644
--- a/utils/kamctl/kamctl.base
+++ b/utils/kamctl/kamctl.base
@@ -368,7 +368,8 @@ usage_base() {
 	mecho " -- command 'start|stop|restart|trap'"
 	echo
 cat <<EOF
- trap ............................... trap with gdb Kamailio processes
+ trap ............................... trap with gdb Kamailio processes using RPC
+ pstrap ............................. trap with gdb Kamailio processes using ps
  restart ............................ restart Kamailio
  start .............................. start Kamailio
  stop ............................... stop Kamailio




More information about the sr-dev mailing list