--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import os
+import re
+import pwd
+import sys
+import errno
+import datetime
+import subprocess
+import time
+import fileinput
+import psycopg2
+from common_code import *
+from cidb import *
+
+logger = logger_init()
+
+def liveboot_to_keep(name):
+ con = db_connect()
+ cur = con.cursor()
+ try:
+ cur.execute("SELECT keep_image FROM liveboot WHERE build_name = '%s' and keep_image = true" % (name))
+ except psycopg2.DatabaseError as e:
+ logger.debug("SELECT keep_image FROM liveboot WHERE build_name = '%s' and keep_image = true" % (name))
+ return False
+ if cur.fetchone():
+ return True
+
+def set_liveboot_to_delete(name):
+ con = db_connect()
+ cur = con.cursor()
+ try:
+ cur.execute("UPDATE liveboot SET deleted = true WHERE build_name = '%s'" % (name))
+ con.commit()
+ except psycopg2.DatabaseError as e:
+ logger.debug("UPDATE liveboot SET deleted = true WHERE build_name = '%s'" % (name))
+ return False
+
+if __name__ == '__main__':
+ if len(sys.argv) != 2 or sys.argv[1] not in ('keep', 'delete'):
+ print("usage: %s keep $liveboot_name")
+ print(" will return true or false, depending if 'keep_image' is set for this image")
+ print("usage: %s delete $liveboot_name")
+ print(" will set 'keep_image' to false")
+ sys.exit(1)
+ action = sys.argv[1]
+ name = sys.argv[2]
+ if action = "keep" and not liveboot_to_keep(name):
+ sys.exit(1)
+ if action = "delete":
+ set_liveboot_to_delete(name)
+
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-import os
-import re
-import pwd
-import sys
-import errno
-import datetime
-import subprocess
-import time
-import fileinput
-import psycopg2
-from common_code import *
-from cidb import *
-
-logger = logger_init()
-
-def liveboot_to_keep(name):
- con = db_connect()
- cur = con.cursor()
- try:
- cur.execute("SELECT keep_image FROM liveboot WHERE build_name = '%s' and keep_image = true" % (name))
- except psycopg2.DatabaseError as e:
- logger.debug("SELECT keep_image FROM liveboot WHERE build_name = '%s' and keep_image = true" % (name))
- return False
- if cur.fetchone():
- return True
-
-if __name__ == '__main__':
- if len(sys.argv) != 2:
- print("usage: %s $liveboot_name")
- sys.exit(1)
- name = sys.argv[1]
- if not liveboot_to_keep(name):
- sys.exit(1)
-
#export
# no configuration below this block
-AMOUNT_TO_KEEP=15
+AMOUNT_TO_KEEP=25
LIVEBOOT_IMAGE_PATH="/srv/mirror/liveboot"
echo
FIRST_PASS=$(ls -1r $LIVEBOOT_IMAGE_PATH)
SECOND_PASS=""
for DIRECTORY in $FIRST_PASS ; do
- if $SCRIPT_PATH/keep_liveboot.py "$DIRECTORY" ; then
+ if $SCRIPT_PATH/cleanup_liveboot.py "keep" "$DIRECTORY" ; then
echo -n "$DIRECTORY: "
echo keep flag set, keeping it.
else
let "KEPT=KEPT+1"
else
echo "deleted."
- echo rm -rf "$LIVEBOOT_IMAGE_PATH/$DIRECTORY"
- echo FIXME: still need to remove the liveboot from cidb...
+ $SCRIPT_PATH/cleanup_liveboot.py "delete" "$DIRECTORY"
+ rm -rf "$LIVEBOOT_IMAGE_PATH/$DIRECTORY"
fi
done
echo
echo
echo "Free diskspace on sagunt:"
df -h $LIVEBOOT_IMAGE_PATH
+echo
echo "The liveboot images are copied to other servers which might not have as much space available."
# dc1+2 (mgmt1)
RSYNC_DST5="liveboot@10.1.1.1/liveboot/"
-# TODO: implement better garbage collection, allow to keep images
-# TODO: needs to update the db too
-# FIXME: locking
#
-# cleanup $RSYNC_SRC, keep MAX number of images
+# check if another rsync is running
#
-MAX=15
-cd $RSYNC_SRC
-COUNT=0
-for i in $(ls -atd1 ./liveboot-*) ; do
- let COUNT=COUNT+1
- if [ $COUNT -gt $MAX ] ; then
- sudo rm -rfv ./$i
- else
- echo "keeping $i"
- fi
+while [ $(ps fax | grep rsync | grep -v grep | grep $RSYNC_SRC 2>/dev/null|wc -l) -gt 0 ] ; do
+ echo "Another rsync run in progress, sleeping."
+ sleep 15
done
#