Commit b47506a6 authored by Nicolas Wavrant's avatar Nicolas Wavrant

resilient: makes sure that cgi script deletes temporary files, even on failure

parent 44e8c0e4
...@@ -104,7 +104,7 @@ output = ${buildout:directory}/instance-frozen.cfg ...@@ -104,7 +104,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 = 9d258d41eeef66f44f361adaa15cbd71
mode = 0644 mode = 0644
destination = ${buildout:directory}/resilient-web-takeover-cgi-script.py.in destination = ${buildout:directory}/resilient-web-takeover-cgi-script.py.in
......
...@@ -4,6 +4,7 @@ equeue_database = '${equeue:database}' ...@@ -4,6 +4,7 @@ equeue_database = '${equeue:database}'
equeue_lockfile = '${equeue:lockfile}' equeue_lockfile = '${equeue:lockfile}'
takeover_script = '${resiliency-takeover-script:wrapper-takeover}' takeover_script = '${resiliency-takeover-script:wrapper-takeover}'
import atexit
import cgi import cgi
import cgitb import cgitb
import datetime import datetime
...@@ -21,12 +22,17 @@ else: ...@@ -21,12 +22,17 @@ else:
cgitb.enable() cgitb.enable()
def deleteTemporaryDirectory(path):
if os.path.exists(path):
shutil.rmtree(path)
def getLatestBackupDate(): def getLatestBackupDate():
""" """
Get the date of the latest successful backup. Get the date of the latest successful backup.
""" """
# 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()
atexit.register(deleteTemporaryDirectory, temporary_directory)
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)
......
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