summaryrefslogtreecommitdiff
path: root/script/dotnet-pending-clrtest-killer.sh
diff options
context:
space:
mode:
Diffstat (limited to 'script/dotnet-pending-clrtest-killer.sh')
-rwxr-xr-xscript/dotnet-pending-clrtest-killer.sh92
1 files changed, 92 insertions, 0 deletions
diff --git a/script/dotnet-pending-clrtest-killer.sh b/script/dotnet-pending-clrtest-killer.sh
new file mode 100755
index 0000000..30b378f
--- /dev/null
+++ b/script/dotnet-pending-clrtest-killer.sh
@@ -0,0 +1,92 @@
+#!/bin/bash
+
+QUITE_MODE=
+KILL_LOG_FILE=killed.log
+
+function message
+{
+ if [ ! "$QUITE_MODE" == "1" ]; then
+ echo $1 >> ${KILL_LOG_FILE}
+ fi
+}
+
+function usage
+{
+ echo ""
+ echo "Usage: $(basename $0) [option]"
+ echo ""
+ echo " [option]"
+ echo " --timeout : timeout interval 1 to 9 in hours. if omitted, use 2 as default."
+ echo " --pattern : process search pattern. if omitted, use 'corerun' as default."
+ echo " --quite : run in silent mode."
+ echo ""
+}
+
+if [ $# -lt 1 ]; then
+ usage
+ exit
+fi
+
+KILL_LOG_FILE=killed.log
+PATTERN=corerun
+TIMEOUT=2
+
+# check commandline options
+for i in "$@"
+do
+ if [ $# -le 0 ]; then
+ break
+ fi
+ case $i in
+ -\?|-h|--help)
+ usage
+ exit
+ ;;
+ --quite)
+ QUITE_MODE=1
+ ;;
+ --timeout=*)
+ TIMEOUT=${i#*=}
+ ;;
+ --pattern=*)
+ PATTERN=${i#*=}
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+if [ $TIMEOUT -lt 1 ] || [ $TIMEOUT -gt 9 ]; then
+ echo "ERROR: <timeout interval> out of range."
+ exit 1
+fi
+
+rm ${KILL_LOG_FILE}
+message "Start with pattern '${PATTERN}' and timeout interval as ${TIMEOUT} hours."
+while [ 1 ]
+do
+ PENDING_TESTS=$(ps -xo pid,etime,stat,args | grep -- $PATTERN | grep -e "[${TIMEOUT}-9]:[0-5][0-9]:[0-5][0-9]" | sed -e 's/^[ ]*//g' -e 's/[ ]\+/ /g')
+ PENDING_TESTS_PID=$(ps -xo pid,etime,stat,args | grep -- $PATTERN | grep -e "[${TIMEOUT}-9]:[0-5][0-9]:[0-5][0-9]" | sed -e 's/^[ ]*//g' -e 's/[ ]\+/ /g' | cut -d' ' -f 1 | paste -s | sed -e 's/^[ ]*//g' -e 's/[ ]\+/ /g')
+
+ message "$(date +%m/%d-%H:%M:%S): triggering pending test killer..."
+
+ if [ -n "$PENDING_TESTS_PID" ]; then
+ message ""
+ message "[PENDING_TESTS]"
+ message "$PENDING_TESTS"
+ message ""
+ message "Send kill signal to ${PENDING_TESTS_PID}"
+ message ""
+
+ if [ "$QUITE_MODE" == "1" ]; then
+ kill -9 $PENDING_TESTS_PID > /dev/null
+ else
+ kill -9 $PENDING_TESTS_PID
+ fi
+ fi
+
+ sleep 60
+done