From 1125af4de267c5363e4126e84edb6ce528b779d5 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Fri, 6 Dec 2019 09:45:03 +0100 Subject: [PATCH] copr: be: support --kill-also-unused in cleanup-vms-aws --- roles/copr/backend/files/cleanup-vms-aws | 64 ++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/roles/copr/backend/files/cleanup-vms-aws b/roles/copr/backend/files/cleanup-vms-aws index 17c2039ee9..34df325394 100755 --- a/roles/copr/backend/files/cleanup-vms-aws +++ b/roles/copr/backend/files/cleanup-vms-aws @@ -2,7 +2,54 @@ set -e -test "$UID" != "0" || { echo "execute as copr user" && exit 1 ; } +help_output() +{ + cat >&2 <....) +- and are not in our redis database. +Such leftover VM usually occurs by manual spawning of bulider, during image +creation. But bug in VM spawner can cause this, etc. That's why we run this +mode periodically in cron job. + +The --kill-also-unused mode is useful when we need to re-distribute new +mock/rpmbuild configuration to all builders. All unused builders are +terminated (so we don't kill running builds) and respawned. +EOF +} + +die () +{ + echo >&2 "$*" + echo >&2 + help_output + exit 1 +} + +test "$UID" != "0" || die "execute as copr user" + +kill_unused=false + +for arg; do + case $arg in + -h|--help) + help_output + exit 1 + ;; + --kill-also-unused) + kill_unused=true + ;; + *) + die "unknown arg $arg" + ;; + esac +done something_found=false @@ -18,6 +65,12 @@ tracked() test -n "$name" } +used() +{ + task=$(redis-cli hget "copr:backend:vm_instance:hset::$1" task_id) + test -n "$task" +} + old_enough() { # give them 1 hour @@ -49,11 +102,14 @@ while read -r aws_id vm_name launch_time; do copr-$prefix-builder*) something_found=true - # skip known VMs - tracked "$vm_name" && continue + if tracked "$vm_name"; then + # skip known VMs + ! $kill_unused && continue + used "$vm_name" && continue + fi # skip recently started VMs - if ! old_enough "$launch_time"; then + if ! $kill_unused && ! old_enough "$launch_time"; then echo >&2 "$vm_name is not yet old enough: $launch_time" continue fi