added logrotate for ahenk log and delete ahenk list source file on packages.py

This commit is contained in:
Tuncay ÇOLAK 2021-01-05 12:17:17 +03:00
parent 9602b41284
commit de88b17719
5 changed files with 17 additions and 7 deletions

View file

@ -12,7 +12,7 @@ keys=file
class=logging.FileHandler class=logging.FileHandler
level=DEBUG level=DEBUG
formatter=default formatter=default
args=("/var/log/ahenk.log", "w") args=("/var/log/ahenk.log", "a")
[loggers] [loggers]
keys=root keys=root

View file

@ -12,7 +12,7 @@ keys=file
class=logging.FileHandler class=logging.FileHandler
level=DEBUG level=DEBUG
formatter=default formatter=default
args=("/var/log/ahenk.log", "w") args=("/var/log/ahenk.log", "a")
[loggers] [loggers]
keys=root keys=root

View file

@ -1,11 +1,10 @@
/var/log/ahenk.log { /var/log/ahenk.log {
weekly daily
missingok missingok
notifempty notifempty
rotate 5 rotate 10
compress compress
delaycompress delaycompress
copytruncate copytruncate
minsize 1000k
create 0766 root root create 0766 root root
} }

View file

@ -47,7 +47,7 @@ class DeleteNetwork(AbstractPlugin):
self.content = '#auto {0}\n'.format(self.name) self.content = '#auto {0}\n'.format(self.name)
if line.startswith(self.content): if line.startswith(self.content):
counter = 3 counter = 4
else: else:
print(str(line).strip()) print(str(line).strip())

View file

@ -97,18 +97,24 @@ class Packages(AbstractPlugin):
message='{0}\n Paket kaldırılırken ' message='{0}\n Paket kaldırılırken '
'hata oluştu. Hata Mesajı: {1}'.format( 'hata oluştu. Hata Mesajı: {1}'.format(
cn, str(p_err))) cn, str(p_err)))
except Exception as e: except Exception as e:
self.logger.error('Unpredictable error exists. Error Message: {0}'.format(str(e))) self.logger.error('Unpredictable error exists. Error Message: {0}'.format(str(e)))
self.delete_source_file()
self.context.create_response(code=self.message_code.TASK_ERROR.value, self.context.create_response(code=self.message_code.TASK_ERROR.value,
message='{0}.\nÖngörülemeyen bir hata oluştu.Hata mesajı:{1}'.format( message='{0}.\nÖngörülemeyen bir hata oluştu.Hata mesajı:{1}'.format(
cn, str(e))) cn, str(e)))
return return
self.delete_source_file()
self.logger.debug('Task handled successfully') self.logger.debug('Task handled successfully')
self.context.create_response(code=self.message_code.TASK_PROCESSED.value, self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
message='{0} ahenginde, {1} paketi({2}) {3} işlemi başarı ile gerçekleştirildi.'.format(cn,item['packageName'], item['version'], item['tag'])) message='{0} ahenginde, {1} paketi({2}) {3} işlemi başarı ile gerçekleştirildi.'.format(cn,item['packageName'], item['version'], item['tag']))
except Exception as e: except Exception as e:
self.logger.error('Unpredictable error exists. Error Message: {0}'.format(str(e))) self.logger.error('Unpredictable error exists. Error Message: {0}'.format(str(e)))
self.delete_source_file()
self.context.create_response(code=self.message_code.TASK_ERROR.value, self.context.create_response(code=self.message_code.TASK_ERROR.value,
message='{0}\nGörev çalıştırılırken beklenmedik bir hata oluştu. Hata Mesajı: {1}'.format( message='{0}\nGörev çalıştırılırken beklenmedik bir hata oluştu. Hata Mesajı: {1}'.format(
cn, cn,
@ -127,6 +133,11 @@ class Packages(AbstractPlugin):
def add_source(self, source): def add_source(self, source):
self.write_file('/etc/apt/sources.list.d/ahenk.list', source+'\n', 'a+') self.write_file('/etc/apt/sources.list.d/ahenk.list', source+'\n', 'a+')
def delete_source_file(self):
if self.is_exist('/etc/apt/sources.list.d/ahenk.list'):
self.delete_file('/etc/apt/sources.list.d/ahenk.list')
self.logger.info("Delete ahenk.list source file")
def handle_task(task, context): def handle_task(task, context):
plugin = Packages(task, context) plugin = Packages(task, context)