aboutsummaryrefslogtreecommitdiff
path: root/tcwg-cleanup-stale-schroot-sessions.yaml
diff options
context:
space:
mode:
authorMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2015-11-30 10:53:46 +0100
committerMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2015-11-30 10:57:29 +0100
commitd5bdca66e4dd32695957e0aa21a5e055345f3887 (patch)
tree0e07b34e4b225980d990a7d02dafc112196dbb97 /tcwg-cleanup-stale-schroot-sessions.yaml
parent962ce70e90ff1810f6f307f4ee7c4e7f2a23371d (diff)
tcwg-cleanup-stale-schroot-sessions: New job
Change-Id: If045d4b25dd03b69034ef73a4e19cea23400c935 Signed-off-by: Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org>
Diffstat (limited to 'tcwg-cleanup-stale-schroot-sessions.yaml')
-rw-r--r--tcwg-cleanup-stale-schroot-sessions.yaml119
1 files changed, 119 insertions, 0 deletions
diff --git a/tcwg-cleanup-stale-schroot-sessions.yaml b/tcwg-cleanup-stale-schroot-sessions.yaml
new file mode 100644
index 0000000000..641cfb34ff
--- /dev/null
+++ b/tcwg-cleanup-stale-schroot-sessions.yaml
@@ -0,0 +1,119 @@
+- job:
+ name: tcwg-cleanup-stale-schroot-sessions
+ project-type: matrix
+ defaults: global
+ logrotate:
+ daysToKeep: 30
+ numToKeep: 30
+ properties:
+ - authorization:
+ anonymous:
+ - job-read
+ - job-extended-read
+ linaro:
+ - job-build
+ - job-cancel
+ - throttle:
+ max-per-node: 1
+ parameters:
+ - string:
+ name: days
+ default: '5'
+ description: 'Delete schroot sessions more then days old. To effectively disable time check use 0.'
+ - bool:
+ name: dry_run
+ default: 'true'
+ description: 'Whether to do a dry-run'
+ - string:
+ name: schroot_name
+ default: 'tcwg-build-*'
+ description: 'Schroot name. Do not override unless you understand what you are doing.'
+ disabled: false
+ node: tcwg-x86_64-cam
+ concurrent: false
+ display-name: 'TCWG Cleanup stale schroot sessions'
+ triggers:
+ - timed: '@daily'
+ axes:
+ - axis:
+ type: slave
+ name: label
+ values:
+ - tcwg-aarch64-07
+ - tcwg-aarch64-build-01
+ - tcwg-aarch64-build-02
+ - tcwg-aarch64-test-01
+ - tcwg-aarch64-test-02
+ - tcwg-x86_64-build-01
+ - tcwg-x86_64-build-02
+ - tcwg-x86_64-build-03
+ - tcwg-x86_64-build-04
+ - tcwg-x86_64-build-05
+ - tcwg-x86_64-build-06
+ - tcwg-x86_64-dev-01
+ - tcwg-x86_64-ex40build-01
+ - tcwg-x86_64-ex40build-02
+ - tcwg-x86_64-ex40build-04
+ - tcwg-x86_64-ex40build-06
+ - tcwg-x86_64-ex40build-07
+ - tcwg-x86_64-ex40build-08
+ - tcwg-x86_64-ex40build-09
+ execution-strategy:
+ sequential: false
+ wrappers:
+ - timeout:
+ timeout: 600
+ - timestamps
+ - ssh-agent-credentials:
+ # tcwg-buildslave user id
+ users:
+ - 'e0958a95-204f-4c14-a66c-5e2be6c5d50a'
+ - build-name:
+ name: '#${BUILD_NUMBER}'
+ builders:
+ - shell: |
+ #!/bin/bash
+
+ set -e
+ set -x
+
+ if [ "$days" -lt "0" ]; then
+ echo "ERROR: Refusing to delete sessions that are $days days old"
+ exit 1
+ fi
+
+ echo "Sessions report before:"
+ ls -l /var/lib/schroot/session/ || true
+
+ # Semantics of find's mtime "+N" stands for N+1 days old or older.
+ days_1=$(($days-1))
+
+ sessions=($(cd /var/lib/schroot/session && find . -type f -name "$schroot_name" -mtime +$days_1 | sed -e "s#^\./##"))
+
+ rm_sessions=()
+ for session in "${sessions[@]}"; do
+ if grep -q "users=$USER" /var/lib/schroot/session/$session; then
+ rm_sessions=("${rm_sessions[@]}" $session)
+ fi
+ done
+
+ if [ ${#rm_sessions[@]} != 0 ]; then
+ echo "Removing sessions:"
+ (cd /var/lib/schroot/session && ls -l "${rm_sessions[@]}")
+ if ! $dry_run; then
+ for session in "${rm_sessions[@]}"; do
+ echo "Removing session $session"
+ schroot -f -e -c session:$session | true
+ if [ x"${PIPESTATUS[0]}" = x"0" ]; then
+ echo "SUCCESS"
+ else
+ echo "FAILED"
+ fi
+ done
+ else
+ echo "DRY_RUN: NOT REMOVING SESSIONS"
+ fi
+
+ echo "Sessions report after:"
+ ls -l /var/lib/schroot/session/ || true
+ fi