mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-26 00:02:19 +03:00
pid file managed
This commit is contained in:
parent
9875638e6c
commit
2cc5cc9950
1 changed files with 29 additions and 21 deletions
|
@ -12,23 +12,23 @@ import threading
|
||||||
import time
|
import time
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
|
|
||||||
from base.Scope import Scope
|
from base.scope import Scope
|
||||||
from base.agreement.agreement import Agreement
|
from base.agreement.agreement import Agreement
|
||||||
from base.command.commander import Commander
|
from base.command.commander import Commander
|
||||||
from base.config.ConfigManager import ConfigManager
|
from base.config.config_manager import ConfigManager
|
||||||
from base.database.AhenkDbService import AhenkDbService
|
from base.database.ahenk_db_service import AhenkDbService
|
||||||
from base.deamon.BaseDeamon import BaseDaemon
|
from base.deamon.base_daemon import BaseDaemon
|
||||||
from base.event.EventManager import EventManager
|
from base.event.event_manager import EventManager
|
||||||
from base.execution.ExecutionManager import ExecutionManager
|
from base.execution.execution_manager import ExecutionManager
|
||||||
from base.logger.AhenkLogger import Logger
|
from base.logger.ahenk_logger import Logger
|
||||||
from base.messaging.MessageResponseQueue import MessageResponseQueue
|
from base.messaging.message_response_queue import MessageResponseQueue
|
||||||
from base.messaging.Messaging import Messaging
|
from base.messaging.messaging import Messaging
|
||||||
from base.messaging.Messenger import Messenger
|
from base.messaging.messenger import Messenger
|
||||||
from base.plugin.plugin_manager_factory import PluginManagerFactory
|
from base.plugin.plugin_manager_factory import PluginManagerFactory
|
||||||
from base.registration.Registration import Registration
|
from base.registration.registration import Registration
|
||||||
from base.scheduler.scheduler_factory import SchedulerFactory
|
from base.scheduler.scheduler_factory import SchedulerFactory
|
||||||
from base.system.system import System
|
from base.system.system import System
|
||||||
from base.task.TaskManager import TaskManager
|
from base.task.task_manager import TaskManager
|
||||||
from base.timer.setup_timer import SetupTimer
|
from base.timer.setup_timer import SetupTimer
|
||||||
from base.timer.timer import Timer
|
from base.timer.timer import Timer
|
||||||
from base.util.util import Util
|
from base.util.util import Util
|
||||||
|
@ -212,6 +212,14 @@ class AhenkDaemon(BaseDaemon):
|
||||||
with open(System.Ahenk.pid_path(), 'w+') as f:
|
with open(System.Ahenk.pid_path(), 'w+') as f:
|
||||||
f.write(str(os.getpid()))
|
f.write(str(os.getpid()))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def init_fifo_file():
|
||||||
|
""" docstring"""
|
||||||
|
if Util.is_exist(System.Ahenk.fifo_file()):
|
||||||
|
Util.delete_file(System.Ahenk.fifo_file())
|
||||||
|
Util.create_file(System.Ahenk.fifo_file())
|
||||||
|
Util.set_permission(System.Ahenk.fifo_file(), '600')
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
""" docstring"""
|
""" docstring"""
|
||||||
print('Ahenk running...')
|
print('Ahenk running...')
|
||||||
|
@ -230,6 +238,9 @@ class AhenkDaemon(BaseDaemon):
|
||||||
self.init_pid_file()
|
self.init_pid_file()
|
||||||
self.logger.info('[AhenkDaemon] Pid file was created')
|
self.logger.info('[AhenkDaemon] Pid file was created')
|
||||||
|
|
||||||
|
self.init_fifo_file()
|
||||||
|
self.logger.info('[AhenkDaemon] Pid file was created')
|
||||||
|
|
||||||
self.init_event_manager()
|
self.init_event_manager()
|
||||||
self.logger.info('[AhenkDaemon] Event Manager was set')
|
self.logger.info('[AhenkDaemon] Event Manager was set')
|
||||||
|
|
||||||
|
@ -275,8 +286,6 @@ class AhenkDaemon(BaseDaemon):
|
||||||
|
|
||||||
self.messenger.send_direct_message('test')
|
self.messenger.send_direct_message('test')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
@ -362,7 +371,8 @@ class AhenkDaemon(BaseDaemon):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
if agreement_choice is not None:
|
if agreement_choice is not None:
|
||||||
messenger.send_direct_message(message_manager.agreement_answer_msg(username, agreement_choice))
|
messenger.send_direct_message(
|
||||||
|
message_manager.agreement_answer_msg(username, agreement_choice))
|
||||||
else:
|
else:
|
||||||
agreement_choice = True
|
agreement_choice = True
|
||||||
|
|
||||||
|
@ -370,7 +380,8 @@ class AhenkDaemon(BaseDaemon):
|
||||||
db_service.delete('session', 'username=\'{0}\''.format(username))
|
db_service.delete('session', 'username=\'{0}\''.format(username))
|
||||||
|
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
'[AhenkDaemon] Display is {0}, desktop env is {1} for {2}'.format(display, desktop, username))
|
'[AhenkDaemon] Display is {0}, desktop env is {1} for {2}'.format(display, desktop,
|
||||||
|
username))
|
||||||
|
|
||||||
db_service.update('session', scope.getDbService().get_cols('session'),
|
db_service.update('session', scope.getDbService().get_cols('session'),
|
||||||
[username, display, desktop, Util.timestamp()])
|
[username, display, desktop, Util.timestamp()])
|
||||||
|
@ -453,15 +464,12 @@ class AhenkDaemon(BaseDaemon):
|
||||||
self.logger.debug('[AhenkDaemon] Waiting for progress of plugins...')
|
self.logger.debug('[AhenkDaemon] Waiting for progress of plugins...')
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
if Util.is_exist('/tmp/liderahenk.fifo'):
|
if Util.is_exist(System.Ahenk.fifo_file()):
|
||||||
Util.delete_file('/tmp/liderahenk.fifo')
|
Util.delete_file(System.Ahenk.fifo_file())
|
||||||
ahenk_daemon.stop()
|
ahenk_daemon.stop()
|
||||||
else:
|
else:
|
||||||
self.logger.error('[AhenkDaemon] Unknown command error. Command:' + json_data['event'])
|
self.logger.error('[AhenkDaemon] Unknown command error. Command:' + json_data['event'])
|
||||||
self.logger.debug('[AhenkDaemon] Processing of handled event is completed')
|
self.logger.debug('[AhenkDaemon] Processing of handled event is completed')
|
||||||
# return True
|
|
||||||
# else:
|
|
||||||
# return False
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue