From 50afb7f43c974fae3344ddd3cc22ff9130b8fa16 Mon Sep 17 00:00:00 2001 From: FrantiĊĦek Zatloukal Date: Feb 14 2018 10:17:31 +0000 Subject: Kill zombie VMs from ImageFactory --- diff --git a/roles/taskotron/imagefactory/files/imagefactory-kill-zombie b/roles/taskotron/imagefactory/files/imagefactory-kill-zombie new file mode 100755 index 0000000..038589a --- /dev/null +++ b/roles/taskotron/imagefactory/files/imagefactory-kill-zombie @@ -0,0 +1,20 @@ +#!/bin/bash + +PROCESS_IDENTIFICATOR='/usr/bin/qemu-system-x86_64 -machine accel=kvm -name guest=factory-build' + +if [ "$1" == "" ]; then + echo "Please, specify a time that how long a process has to be running to be killed (in minutes)" + exit +fi + + +# Check if we have any process matching PROCESS_IDENTIFICATOR +while (( $(pgrep -o -f "$PROCESS_IDENTIFICATOR") )); do + # Get PID of the longest (pgrep -o) running matched process + if (( $(ps -o etimes= -p $(pgrep -o -f "$PROCESS_IDENTIFICATOR")) >= $1*60)); then + pgrep -o -f "$PROCESS_IDENTIFICATOR" | xargs kill; + else + # We can exit if the oldest matching process wasn't old enough to be killed :) + exit + fi +done \ No newline at end of file diff --git a/roles/taskotron/imagefactory/tasks/main.yml b/roles/taskotron/imagefactory/tasks/main.yml index 85a5ec8..4788bbb 100644 --- a/roles/taskotron/imagefactory/tasks/main.yml +++ b/roles/taskotron/imagefactory/tasks/main.yml @@ -13,6 +13,9 @@ - name: copy oz.cfg config file copy: src=oz.cfg dest=/etc/oz/oz.cfg owner=root group=root mode=0644 +- name: copy script to kill zombie ImageFactory VMs + copy: src=imagefactory-kill-zombie dest=/usr/local/bin owner=root group=root mode=0744 + - name: hotfix imagefactory's REST api to allow file download copy: src=hotfix_imgfac_RESTv2.py dest=/usr/lib/python2.7/site-packages/imgfac/rest/RESTv2.py owner=root group=root mode=0644 @@ -72,3 +75,9 @@ name: "Prune old builds in ImageFactory" special_time: daily job: '/var/lib/fedoraqa/base_images/prune_images/prune_images.py imgfac-old --config /etc/taskotron_base_images/config_server.ini --keep 3 > /dev/null' + +- name: Create cronjob to kill zombie VMs from ImageFactory + cron: + name: "kill zombie VMs from ImageFactory" + special_time: daily + job: 'imagefactory-kill-zombie'