Изменен алгоритм добавления и удаления выполняемого скрипта для удаления данных реплицируемых пользователей, теперь используется директория /etc/cron.weekly.

git-svn-id: http://svn.calculate.ru/calculate2/calculate-server/trunk@1244 c91db197-33c1-4113-bf15-f8a5c547ca64
develop
asamoukin 15 years ago
parent 8219e419c0
commit b319f10bf1

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
#Copyright 2008 Calculate Pack, http://www.calculate-linux.ru
#Copyright 2009 Calculate Pack, http://www.calculate-linux.ru
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -5841,7 +5841,7 @@ outdated. If the backup is obsolete, use cl-backup."))
# другого компьютера
replServices = []
if options.has_key("repl"):
# Находим имена сервисов репликации для этого сервера
# Находим имена сервисов р<EFBFBD>пликации для этого сервера
# и инициализируем переменные
replServices = self.getArchReplServices()
if not replServices:
@ -9831,56 +9831,48 @@ in the LDAP branch 'Worked'")%userName
return True
def cronReplicationON(self):
"""Включает в cron обработку файла replcron"""
replCronFile = os.path.join("/usr/bin",self.replCronFile)
fileNameCron = tempfile.mktemp(".cron")
warning = _("Please do not remove the line, it was added by the \
"""Включаем выполнение скрипта крона - replcron, для репликации"""
# Очищаем crontab (для совместимости с предыдущей версией)
if not self.crontabClear():
return False
cronWeeklyFile = os.path.join("/etc/cron.weekly",self.replCronFile)
# Предупреждение
warning = _("Please do not delete this file, it was created \
calculate-server")
textCronInsert = "30 3 * * 1 %s"%replCronFile
listCronLines = self.execProg("crontab -l",False,False)
# Удаляем из элементов переводы строк
listCronLinesSrc = map(lambda x: x.split('\n')[0],listCronLines)
# Удаляем из элементов все начиная с #
listCronLines = map(lambda x: x.split("#")[0].strip(),listCronLinesSrc)
foundCronLine = False
listCronLinesOut = []
i = 0
for textCron in listCronLines:
if not textCron.strip():
i += 1
continue
elemLine=re.split(\
"[^\t ]+\s+[^\t ]+\s+[^\t ]+\s+[^\t ]+\s+[^\t ]+\s+" ,textCron)
if len(elemLine) == 2 and elemLine[1] == replCronFile:
foundCronLine = True
break
listCronLinesOut.append(listCronLinesSrc[i])
i +=1
if foundCronLine:
return True
else:
if not os.path.exists("/var/spool/cron/crontabs/root"):
listCronLinesOut = []
if listCronLinesOut:
self.createUserFile(fileNameCron,
"\n".join(listCronLinesOut) + "\n"+\
"%s # %s\n"%(textCronInsert,warning),
0,0)
else:
self.createUserFile(fileNameCron,
"%s # %s\n"%(textCronInsert,warning),
0,0)
textLine = self.execProg("crontab %s"%fileNameCron)
if not (textLine == None):
self.printERROR(_("Can not add crontab file"))
if os.path.exists(fileNameCron):
os.remove(fileNameCron)
# содержимое файла запускающегося по крону
replCronFileContent = "#!/bin/bash\n# %s\n%s\n"\
%(warning, os.path.join("/usr/bin",self.replCronFile))
if os.path.exists(cronWeeklyFile):
try:
FD = open(cronWeeklyFile,"w")
FD.write(replCronFileContent)
FD.close()
except:
self.printERROR(_("Can not write %s")%cronWeeklyFile)
return False
if os.path.exists(fileNameCron):
os.remove(fileNameCron)
return True
if not self.createUserFile(cronWeeklyFile, replCronFileContent,
0, 0, 0744):
return False
return True
def cronReplicationOFF(self):
"""Отключаем выполнение скрипта крона - replcron, для репликации"""
# Очищаем crontab (для совместимости с предыдущей версией)
if not self.crontabClear():
return False
cronWeeklyFile = os.path.join("/etc/cron.weekly",self.replCronFile)
if os.path.exists(cronWeeklyFile):
# Удаляем файл из /etc/cron.weekly
try:
os.remove(cronWeeklyFile)
except:
self.printERROR(_("Can not delete %s") %cronWeeklyFile)
return False
return True
def crontabClear(self):
"""Отключает в crontab обработку файла replcron"""
replCronFile = os.path.join("/usr/bin",self.replCronFile)
fileNameCron = tempfile.mktemp(".cron")

Loading…
Cancel
Save