conga/luci/utils luci_admin
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2006-06-21 17:41:30
Modified files:
luci/utils : luci_admin
Log message:
more cleanup
luci/utils/luci_admin +58 -31
@@ -1,6 +1,6 @@ #!/usr/bin/python -import sys, os, stat, random, crypt, select, string +import sys, os, stat, random, crypt, select, string, pwd from sys import stderr, argv import types import xml
@@ -22,7 +22,8 @@ SSL_PRIVKEY_PATH='/var/lib/luci/var/certs/privkey.pem' SSL_PUBKEY_PATH='/var/lib/luci/var/certs/cacert.pem' SSL_KEYCONFIG_PATH='/var/lib/luci/var/certs/cacert.config' -LUCI_BACKUP_PATH='/var/lib/luci/var/luci_backup.xml' +LUCI_BACKUP_DIR='/var/lib/luci/var' +LUCI_BACKUP_PATH=LUCI_BACKUP_DIR + '/luci_backup.xml' LUCI_DB_PATH='/var/lib/luci/var/Data.fs' LUCI_TEMP='/var/lib/luci/var/temp/'
@@ -50,7 +51,6 @@ inituser.close() try: - import pwd luci = pwd.getpwnam(LUCI_USER)[2:4] os.chown(INITUSER_FILE_PATH, luci[0], luci[1]) except:
@@ -129,7 +129,7 @@ if not portal_mem or not portal_reg: raise except: - sys.stderr.write('Your Luci installation appears to be corrupt.') + sys.stderr.write('Your Luci installation appears to be corrupt.\n') return -1 userList = node.getElementsByTagName('userList')
@@ -193,17 +193,17 @@ if not x: raise except: - sys.stderr.write('Cannot find the Luci storage systems directory. Your Luci installation may be corrupt.') + sys.stderr.write('Cannot find the Luci storage systems directory. Your Luci installation may be corrupt.\n') transaction.abort() return -1 systemList = node.getElementsByTagName('systemList') if not systemList or len(systemList) < 1: - verbose.write('No storage systems to add') + verbose.write('No storage systems to add\n') else: systemList = systemList[0].getElementsByTagName('system') if len(systemList) < 1: - verbose.write('No storage systems to add') + verbose.write('No storage systems to add\n') for s in systemList: id = s.getAttribute('id')
@@ -250,17 +250,17 @@ if not x: raise except: - sys.stderr.write('Cannot find the Luci cluster directory. Your Luci installation may be corrupt.') + sys.stderr.write('Cannot find the Luci cluster directory. Your Luci installation may be corrupt.\n') transaction.abort() return -1 clusterList = node.getElementsByTagName('clusterList') if not clusterList or len(clusterList) < 1: - verbose.write('No clusters to add') + verbose.write('No clusters to add\n') else: clusterList = clusterList[0].getElementsByTagName('cluster') if len(clusterList) < 1: - verbose.write('No clusters to add') + verbose.write('No clusters to add\n') for c in clusterList: id = c.getAttribute('id')
@@ -397,7 +397,7 @@ conn = db.open() except: stderr.write('Unable to open the luci database \"' + dbfn + '\"\n') - return -1 + return None examine_classes = [ 'OFS.Folder.Folder',
@@ -409,11 +409,6 @@ clusters = {} users = {} - if len(argv) > 1: - backupfn = argv[1] - else: - backupfn = LUCI_BACKUP_PATH - # To suppress some useless zope error messages. sys.stderr = null
@@ -560,7 +555,7 @@ certfile.close() except False: sys.stderr.write('Unable to read ' + SSL_PRIVKEY_PATH + '\n') - return -1 + return None try: certfile = file(SSL_PUBKEY_PATH, 'rb')
@@ -578,7 +573,7 @@ certfile.close() except: sys.stderr.write('Unable to read ' + SSL_PUBKEY_PATH + '\n') - return -1 + return None try: certfile = file(SSL_KEYCONFIG_PATH, 'rb')
@@ -598,18 +593,7 @@ sys.stderr.write('Unable to read ' + SSL_KEYCONFIG_PATH + '\n') luciData.appendChild(dataNode) - - # TODO: this needs to backup the backup, if any, and should - # write to a tempfile, then rename. - try: - f = file(backupfn, 'w') - except: - sys.stderr.write('Unable to open \"' + backupfn + '\" to write backup.\n') - return -1 - - f.write(doc.toprettyxml()) - f.flush() - f.close() + return doc def _execWithCaptureErrorStatus(command, argv, searchPath = 0, root = '/', stdin = 0, catchfd = 1, catcherrfd = 2, closefd = -1): if not os.access (root + command, os.X_OK):
@@ -810,13 +794,49 @@ try: os.umask(077) except: pass - if luci_backup(argv[2:]): + doc = luci_backup(argv[2:]) + if not doc: sys.stderr.write('The Luci backup failed.\n') sys.exit(1) + try: + stat = os.stat(LUCI_BACKUP_PATH) + trynum = 1 + basename = '/luci_backup-' + while True: + oldbackup = LUCI_BACKUP_DIR + basename + str(trynum) + '.xml' + if not os.path.exists(oldbackup): + try: + os.rename(LUCI_BACKUP_PATH, oldbackup) + except: + sys.write.stderr('Unable to rename the existing backup file.\n') + sys.exit(1) + break + trynum += 1 + except OSError, e: + #if e[0] == 2: + pass + + try: + f = file(LUCI_BACKUP_PATH, 'w') + except: + sys.stderr.write('Unable to open \"' + LUCI_BACKUP_PATH + '\" to write backup.\n') + return -1 + + f.write(doc.toprettyxml()) + f.flush() + f.close() + print 'Backup was successful. The backup file is',LUCI_BACKUP_PATH try: + luci = pwd.getpwnam(LUCI_USER)[2:4] + os.chown(LUCI_DB_PATH, luci[0], luci[1]) + os.chmod(LUCI_DB_PATH, 0600) + except: + sys.stderr.write('Unable to change ownership of the Luci database back to user \"' + LUCI_USER + '\"\n') + + try: os.chmod(LUCI_BACKUP_PATH, 0600) except OSError, e: print "An error occurred while making",LUCI_BACKUP_PATH,"read-only:",e
@@ -859,6 +879,13 @@ restart_message() try: + luci = pwd.getpwnam(LUCI_USER)[2:4] + os.chown(LUCI_DB_PATH, luci[0], luci[1]) + os.chmod(LUCI_DB_PATH, 0600) + except: + sys.stderr.write('Unable to change ownership of the Luci database back to user \"' + LUCI_USER + '\"\n') + + try: os.unlink(LUCI_TEMP + 'www/ok.gif') os.unlink(LUCI_TEMP + 'images/version.gif') os.removedirs(LUCI_TEMP)