resilient stack: show in takeover script if backup is in progress.

parent 9413f53b
...@@ -92,7 +92,7 @@ output = ${buildout:directory}/instance-frozen.cfg ...@@ -92,7 +92,7 @@ output = ${buildout:directory}/instance-frozen.cfg
[resilient-web-takeover-cgi-script-download] [resilient-web-takeover-cgi-script-download]
recipe = slapos.recipe.download recipe = slapos.recipe.download
url = ${:_profile_base_location_}/resilient-web-takeover-cgi-script.py.in url = ${:_profile_base_location_}/resilient-web-takeover-cgi-script.py.in
md5sum = 4e9599736dbbba9eb466cd0e4d78368d md5sum = 5c90dae56885eeb490cc5d7f82d2dc5b
mode = 0644 mode = 0644
destination = ${buildout:directory}/resilient-web-takeover-cgi-script.py.in destination = ${buildout:directory}/resilient-web-takeover-cgi-script.py.in
......
#!${buildout:executable} #!${buildout:executable}
equeue_database = '${equeue:database}' equeue_database = '${equeue:database}'
equeue_lockfile = '${equeue:lockfile}'
import cgi import cgi
import cgitb import cgitb
...@@ -32,6 +33,14 @@ def getLatestBackupDate(): ...@@ -32,6 +33,14 @@ def getLatestBackupDate():
last_backup = timestamp last_backup = timestamp
return datetime.datetime.fromtimestamp(last_backup) return datetime.datetime.fromtimestamp(last_backup)
def isBackupInProgress():
"""
Check if backup is in progress (importer script is running)
by checking if equeue lockfile exists.
"""
# XXX: check if file is valid
return os.path.exists(equeue_lockfile)
print "Content-Type: text/html" print "Content-Type: text/html"
print print
...@@ -44,12 +53,13 @@ if "password" not in form: ...@@ -44,12 +53,13 @@ if "password" not in form:
<p><b>Warning: submit the form only if you understand what you are doing.</b></p> <p><b>Warning: submit the form only if you understand what you are doing.</b></p>
<p>Note: the password asked here can be found within the parameters of your SlapOS instance page.</p> <p>Note: the password asked here can be found within the parameters of your SlapOS instance page.</p>
<p>Last valid backup: %s</p> <p>Last valid backup: %s</p>
<p>Importer script(s) of backup in progress: %s</p>
<form action="/"> <form action="/">
Password: <input type="text" name="password"> Password: <input type="text" name="password">
<input type="submit" value="Take over" style="background: red;"> <input type="submit" value="Take over" style="background: red;">
</form> </form>
</body> </body>
</html>""" % getLatestBackupDate().strftime('%Y-%m-%d %H:%M:%S') </html>""" % (getLatestBackupDate().strftime('%Y-%m-%d %H:%M:%S'), isBackupInProgress())
sys.exit(0) sys.exit(0)
if form['password'].value != '${:password}': if form['password'].value != '${:password}':
......
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