added restart task to login-manager

This commit is contained in:
Tuncay ÇOLAK 2020-04-27 16:42:54 +03:00
parent 0f09fb0525
commit 1e9c4af168
2 changed files with 33 additions and 4 deletions

View file

@ -0,0 +1,31 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Author:Tuncay ÇOLAK <tuncay.colak@tubitak.gov.tr>
## restart agents
from base.plugin.abstract_plugin import AbstractPlugin
class Restart(AbstractPlugin):
def __init__(self, task, context):
super(AbstractPlugin, self).__init__()
self.task = task
self.context = context
self.logger = self.get_logger()
self.message_code = self.get_message_code()
self.command_restart = 'reboot'
self.logger.debug('Parameters were initialized.')
def handle_task(self):
try:
result_code, p_out, p_err = self.execute(self.command_restart)
self.logger.info("restart agent success")
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
message='İstemci yeniden başarıyla başlatıldı. .')
except Exception as e:
self.logger.error('A problem occured while handling Login-Manager task: {0}'.format(str(e)))
self.context.create_response(code=self.message_code.TASK_ERROR.value,
message='İstemci yeniden başlatılırken bir hata oluştu.')
def handle_task(task, context):
manage = Restart(task, context)
manage.handle_task()

View file

@ -5,16 +5,14 @@
from base.plugin.abstract_plugin import AbstractPlugin
class LoginManager(AbstractPlugin):
class Shutdown(AbstractPlugin):
def __init__(self, task, context):
super(AbstractPlugin, self).__init__()
self.task = task
self.context = context
self.logger = self.get_logger()
self.message_code = self.get_message_code()
self.command_shutdown = 'shutdown -h now'
self.logger.debug('Parameters were initialized.')
def handle_task(self):
@ -29,5 +27,5 @@ class LoginManager(AbstractPlugin):
message='İstemci kapatılırken bir hata oluştu.')
def handle_task(task, context):
manage = LoginManager(task, context)
manage = Shutdown(task, context)
manage.handle_task()