Commit 57c302b7 authored by Nicolas Wavrant's avatar Nicolas Wavrant

resilient: adds cleanup for the takeover cgi script

parent 4fadb21e
...@@ -96,7 +96,7 @@ output = ${buildout:directory}/instance-frozen.cfg ...@@ -96,7 +96,7 @@ output = ${buildout:directory}/instance-frozen.cfg
[resilient-web-takeover-cgi-script-download] [resilient-web-takeover-cgi-script-download]
recipe = slapos.recipe.build:download recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/resilient-web-takeover-cgi-script.py.in url = ${:_profile_base_location_}/resilient-web-takeover-cgi-script.py.in
md5sum = c46c8e3e4ce4376c98ad2fc0e2ff0fe4 md5sum = 56bfa23b31196743a19c4f0b008cd2f6
mode = 0644 mode = 0644
destination = ${buildout:directory}/resilient-web-takeover-cgi-script.py.in destination = ${buildout:directory}/resilient-web-takeover-cgi-script.py.in
......
...@@ -25,8 +25,10 @@ def getLatestBackupDate(): ...@@ -25,8 +25,10 @@ def getLatestBackupDate():
""" """
Get the date of the latest successful backup. Get the date of the latest successful backup.
""" """
# Clean previous runs which may have possibly fail
[shutil.rmtree(file) for file in os.listdir('.') if file.endswith('.tmp')]
# Create a copy of the db (locked by equeue process) # Create a copy of the db (locked by equeue process)
temporary_directory = tempfile.mkdtemp() temporary_directory = tempfile.mkdtemp(prefix="cgi-script-data", suffix=".tmp", dir='.')
equeue_database_copy = os.path.join(temporary_directory, 'equeue.db') equeue_database_copy = os.path.join(temporary_directory, 'equeue.db')
shutil.copyfile(equeue_database, equeue_database_copy) shutil.copyfile(equeue_database, equeue_database_copy)
db = gdbm.open(equeue_database_copy) db = gdbm.open(equeue_database_copy)
...@@ -42,7 +44,6 @@ def getLatestBackupDate(): ...@@ -42,7 +44,6 @@ def getLatestBackupDate():
if timestamp < last_backup: if timestamp < last_backup:
last_backup = timestamp last_backup = timestamp
result = datetime.datetime.fromtimestamp(last_backup) result = datetime.datetime.fromtimestamp(last_backup)
db.close()
shutil.rmtree(temporary_directory) shutil.rmtree(temporary_directory)
return result return result
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment