aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2015-06-29 11:35:36 +0200
committerMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2015-07-09 10:18:57 +0200
commit00cb0dccd1f106b3ffe06e4c8f0d755f293e9c1e (patch)
treef506107eb47358a7ec39ed9daac741f128ea4531 /scripts
parent42ae5029a890863561225a88924d0643766f8ae2 (diff)
scripts/clean-schroot-sessions.sh: New script to clean stale schroot sessions
This script supports tcwg-cleanup-tcwg-test-schroots jenkins job, which cleans up stale schroots daily. The reason for stale schroot sessions to appear is in how jenkins handles ssh agent. If a build is cancelled, ssh agent dies immediatelly, and the builder can no longer access the tester to finish the session (and it tries, as part of "trap" cleanup). Therefore, once a day, we stop schroot sessions of tcwg-buildslave that lasted for more than a day. Change-Id: Ib47f7af05ce22b07ed060a09e4a03cc19ed7cbfd
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/clean-schroot-sessions.sh82
1 files changed, 82 insertions, 0 deletions
diff --git a/scripts/clean-schroot-sessions.sh b/scripts/clean-schroot-sessions.sh
new file mode 100755
index 00000000..369a2f72
--- /dev/null
+++ b/scripts/clean-schroot-sessions.sh
@@ -0,0 +1,82 @@
+#!/bin/bash
+
+set -e
+
+usage ()
+{
+ cat <<EOF
+Usage: $0 [-v] [-d DAYS] [machine1 machine2 ...]
+ This scripts stops tcwg-test schroot sessions on given machines
+ that are more than DAYS old.
+
+ -d DAYS: Number of days (default 1)
+ -v: Be verbose
+ -h: Print help
+EOF
+}
+
+verbose="set +x"
+days="1"
+
+while getopts "d:hv" OPTION; do
+ case $OPTION in
+ d) days="$OPTARG" ;;
+ h)
+ usage
+ exit 0
+ ;;
+ v) verbose="set -x" ;;
+ esac
+done
+
+$verbose
+
+shift $((OPTIND-1))
+
+# Semantics of find's mtime "+N" stands for N+1 days old or older.
+days=$(($days-1))
+
+# "if true" is to have same indent as configure-machine.sh hunk from which
+# handling of parallel runs was copied.
+if true; then
+ declare -A pids
+ declare -A results
+
+ todo_machines="$@"
+
+ # Ssh to machines and stop tcwg-test schroot sessions (via
+ # "test-schroot -f") that are more than $days old. Dump output to a temp
+ # file for display at the end.
+ for M in $todo_machines; do
+ (
+ ssh $M find /var/lib/schroot/session -mtime +$days \
+ | sed -e "s#^/var/lib/schroot/session/tcwg-test-##" \
+ | grep "^[0-9]*\$" \
+ | xargs -t -i@ $(dirname $0)/test-schroot.sh -v -f $M:@
+ ) > /tmp/clean-schroot-sessions.$$.$M 2>&1 &
+ pids[$M]=$!
+ done
+
+ for M in $todo_machines; do
+ set +e
+ wait ${pids[$M]}
+ results[$M]=$?
+ set -e
+
+ sed -e "s/^/$M: /" < /tmp/clean-schroot-sessions.$$.$M
+ rm /tmp/clean-schroot-sessions.$$.$M
+ done
+
+ all_ok="0"
+ for M in $todo_machines; do
+ if [ ${results[$M]} = 0 ]; then
+ result="SUCCESS"
+ else
+ result="FAIL"
+ all_ok="1"
+ fi
+ echo "$result: $M"
+ done
+
+ exit $all_ok
+fi