2016-02-29 10:48:00 +02:00
|
|
|
#!/usr/bin/python3
|
2016-02-01 17:49:17 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
2016-03-08 18:09:26 +02:00
|
|
|
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
|
2016-02-01 17:49:17 +02:00
|
|
|
|
2016-03-23 17:15:27 +02:00
|
|
|
import os
|
|
|
|
import queue
|
|
|
|
import signal
|
|
|
|
import sys
|
|
|
|
import threading
|
|
|
|
import time
|
2018-11-14 11:03:32 +03:00
|
|
|
from glob import glob
|
2016-07-18 18:21:03 +03:00
|
|
|
|
|
|
|
from base.agreement.agreement import Agreement
|
2016-09-21 12:01:07 +03:00
|
|
|
from base.command.command_manager import Commander
|
|
|
|
from base.command.command_runner import CommandRunner
|
2016-08-24 18:04:06 +03:00
|
|
|
from base.config.config_manager import ConfigManager
|
|
|
|
from base.database.ahenk_db_service import AhenkDbService
|
|
|
|
from base.deamon.base_daemon import BaseDaemon
|
|
|
|
from base.event.event_manager import EventManager
|
|
|
|
from base.execution.execution_manager import ExecutionManager
|
|
|
|
from base.logger.ahenk_logger import Logger
|
|
|
|
from base.messaging.message_response_queue import MessageResponseQueue
|
|
|
|
from base.messaging.messaging import Messaging
|
|
|
|
from base.messaging.messenger import Messenger
|
2016-04-13 11:55:45 +03:00
|
|
|
from base.plugin.plugin_manager_factory import PluginManagerFactory
|
2016-08-24 18:04:06 +03:00
|
|
|
from base.registration.registration import Registration
|
2016-04-05 17:55:15 +03:00
|
|
|
from base.scheduler.scheduler_factory import SchedulerFactory
|
2016-09-21 12:01:07 +03:00
|
|
|
from base.scope import Scope
|
2016-06-06 12:27:46 +03:00
|
|
|
from base.system.system import System
|
2016-08-24 18:04:06 +03:00
|
|
|
from base.task.task_manager import TaskManager
|
2016-06-27 17:20:26 +03:00
|
|
|
from base.util.util import Util
|
2018-11-02 14:01:49 +03:00
|
|
|
from easygui import msgbox
|
2016-02-01 17:49:17 +02:00
|
|
|
|
2016-09-21 12:01:07 +03:00
|
|
|
sys.path.append('../..')
|
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
ahenk_daemon = None
|
2016-02-08 19:03:38 +02:00
|
|
|
|
2016-03-23 17:15:27 +02:00
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
class AhenkDaemon(BaseDaemon):
|
|
|
|
"""Ahenk service base class which initializes services and maintains events/commands"""
|
2016-02-21 03:56:08 +02:00
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
@staticmethod
|
|
|
|
def reload():
|
|
|
|
""" docstring"""
|
2016-03-11 17:51:26 +02:00
|
|
|
# reload service here
|
|
|
|
pass
|
2016-03-04 18:01:47 +02:00
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
@staticmethod
|
|
|
|
def init_logger():
|
|
|
|
""" docstring"""
|
2016-04-05 17:55:15 +03:00
|
|
|
logger = Logger()
|
2016-09-21 12:01:07 +03:00
|
|
|
logger.info('Log was set')
|
|
|
|
Scope.get_instance().set_logger(logger)
|
2016-04-05 17:55:15 +03:00
|
|
|
return logger
|
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
@staticmethod
|
|
|
|
def init_config_manager(config_file_path, configfile_folder_path):
|
|
|
|
""" docstring"""
|
|
|
|
config_manager = ConfigManager(config_file_path, configfile_folder_path)
|
|
|
|
config = config_manager.read()
|
2016-09-21 12:01:07 +03:00
|
|
|
Scope.get_instance().set_configuration_manager(config)
|
2016-04-05 17:55:15 +03:00
|
|
|
return config
|
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
@staticmethod
|
|
|
|
def init_scheduler():
|
|
|
|
""" docstring"""
|
2016-04-05 17:55:15 +03:00
|
|
|
scheduler_ins = SchedulerFactory.get_intstance()
|
|
|
|
scheduler_ins.initialize()
|
2016-09-21 12:01:07 +03:00
|
|
|
Scope.get_instance().set_scheduler(scheduler_ins)
|
2016-04-05 17:55:15 +03:00
|
|
|
sc_thread = threading.Thread(target=scheduler_ins.run)
|
|
|
|
sc_thread.setDaemon(True)
|
|
|
|
sc_thread.start()
|
2016-04-05 19:12:40 +03:00
|
|
|
return scheduler_ins
|
2016-04-05 17:55:15 +03:00
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
@staticmethod
|
|
|
|
def init_event_manager():
|
|
|
|
""" docstring"""
|
|
|
|
event_manager = EventManager()
|
2016-09-21 12:01:07 +03:00
|
|
|
Scope.get_instance().set_event_manager(event_manager)
|
2016-08-18 21:04:17 +03:00
|
|
|
return event_manager
|
2016-04-05 17:55:15 +03:00
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
@staticmethod
|
|
|
|
def init_ahenk_db():
|
|
|
|
""" docstring"""
|
2016-04-05 17:55:15 +03:00
|
|
|
db_service = AhenkDbService()
|
|
|
|
db_service.connect()
|
|
|
|
db_service.initialize_table()
|
2016-09-21 12:01:07 +03:00
|
|
|
Scope.get_instance().set_sb_service(db_service)
|
2016-04-05 17:55:15 +03:00
|
|
|
return db_service
|
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
@staticmethod
|
|
|
|
def init_messaging():
|
|
|
|
""" docstring"""
|
|
|
|
message_manager = Messaging()
|
2016-09-21 12:01:07 +03:00
|
|
|
Scope.get_instance().set_message_manager(message_manager)
|
2016-08-18 21:04:17 +03:00
|
|
|
return message_manager
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def init_plugin_manager():
|
|
|
|
""" docstring"""
|
|
|
|
plugin_manager = PluginManagerFactory.get_instance()
|
2016-09-21 12:01:07 +03:00
|
|
|
Scope.get_instance().set_plugin_manager(plugin_manager)
|
2016-07-18 18:21:03 +03:00
|
|
|
# order changed, problem?
|
2016-08-18 21:04:17 +03:00
|
|
|
plugin_manager.load_plugins()
|
|
|
|
return plugin_manager
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def init_task_manager():
|
|
|
|
""" docstring"""
|
|
|
|
task_manager = TaskManager()
|
2016-09-21 12:01:07 +03:00
|
|
|
Scope.get_instance().set_task_manager(task_manager)
|
2016-08-18 21:04:17 +03:00
|
|
|
return task_manager
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def init_registration():
|
|
|
|
""" docstring"""
|
2016-04-05 17:55:15 +03:00
|
|
|
registration = Registration()
|
2016-09-21 12:01:07 +03:00
|
|
|
Scope.get_instance().set_registration(registration)
|
2016-04-05 17:55:15 +03:00
|
|
|
return registration
|
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
@staticmethod
|
|
|
|
def init_execution_manager():
|
|
|
|
""" docstring"""
|
2016-04-05 17:55:15 +03:00
|
|
|
execution_manager = ExecutionManager()
|
2016-09-21 12:01:07 +03:00
|
|
|
Scope.get_instance().set_execution_manager(execution_manager)
|
2016-04-05 17:55:15 +03:00
|
|
|
return execution_manager
|
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
@staticmethod
|
|
|
|
def init_messenger():
|
|
|
|
""" docstring"""
|
|
|
|
messenger_ = Messenger()
|
|
|
|
messenger_.connect_to_server()
|
2016-09-21 12:01:07 +03:00
|
|
|
Scope.get_instance().set_messenger(messenger_)
|
2016-08-18 21:04:17 +03:00
|
|
|
return messenger_
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def init_message_response_queue():
|
|
|
|
""" docstring"""
|
|
|
|
response_queue = queue.Queue()
|
|
|
|
message_response_queue = MessageResponseQueue(response_queue)
|
|
|
|
message_response_queue.setDaemon(True)
|
|
|
|
message_response_queue.start()
|
2016-09-21 12:01:07 +03:00
|
|
|
Scope.get_instance().set_response_queue(response_queue)
|
2016-08-18 21:04:17 +03:00
|
|
|
return response_queue
|
2016-04-05 17:55:15 +03:00
|
|
|
|
|
|
|
def check_registration(self):
|
2016-08-18 21:04:17 +03:00
|
|
|
""" docstring"""
|
2018-11-02 14:01:49 +03:00
|
|
|
# max_attempt_number = int(System.Hardware.Network.interface_size()) * 3
|
2020-07-23 16:38:40 +03:00
|
|
|
max_attempt_number = 2
|
2016-08-18 21:04:17 +03:00
|
|
|
# self.logger.debug()
|
|
|
|
# logger = Scope.getInstance().getLogger()
|
2016-09-21 12:01:07 +03:00
|
|
|
registration = Scope.get_instance().get_registration()
|
2016-06-21 17:47:25 +03:00
|
|
|
|
2016-04-08 15:54:26 +03:00
|
|
|
try:
|
2018-11-02 14:01:49 +03:00
|
|
|
#if registration.is_registered() is False:
|
|
|
|
# self.logger.debug('Ahenk is not registered. Attempting for registration')
|
|
|
|
# if registration.registration_request() == False:
|
|
|
|
# self.registration_failed()
|
|
|
|
|
2020-06-24 12:23:34 +03:00
|
|
|
while registration.is_registered() is False:
|
2020-04-06 18:10:41 +03:00
|
|
|
print("Registration attemp")
|
2016-08-18 21:04:17 +03:00
|
|
|
max_attempt_number -= 1
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.debug('Ahenk is not registered. Attempting for registration')
|
2020-07-23 14:35:27 +03:00
|
|
|
# registration.registration_request(self.register_hostname,self.register_user_name,self.register_user_password,self.register_directory_server)
|
|
|
|
registration.registration_request(self.register_hostname,self.register_user_name,self.register_user_password)
|
2020-06-24 12:23:34 +03:00
|
|
|
if max_attempt_number < 0:
|
|
|
|
self.logger.warning('Number of Attempting for registration is over')
|
|
|
|
Util.execute("/etc/init.d/ahenk stop")
|
|
|
|
break
|
2018-11-02 14:01:49 +03:00
|
|
|
#if max_attempt_number < 0:
|
|
|
|
# self.logger.warning('Number of Attempting for registration is over')
|
|
|
|
# self.registration_failed()
|
|
|
|
# break
|
2016-04-08 15:54:26 +03:00
|
|
|
except Exception as e:
|
2018-11-02 14:01:49 +03:00
|
|
|
self.registration_failed()
|
|
|
|
self.logger.error('Registration failed. Error message: {0}'.format(str(e)))
|
2020-06-25 10:37:36 +03:00
|
|
|
#Util.execute("/etc/init.d/ahenk stop")
|
2018-11-02 14:01:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
def is_registered(self):
|
|
|
|
try:
|
|
|
|
registration = Scope.get_instance().get_registration()
|
|
|
|
if registration.is_registered() is False:
|
|
|
|
self.registration_failed()
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
self.registration_failed()
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.error('Registration failed. Error message: {0}'.format(str(e)))
|
2016-05-06 16:34:58 +03:00
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
@staticmethod
|
|
|
|
def shutdown_mode():
|
|
|
|
""" docstring"""
|
2016-09-21 12:01:07 +03:00
|
|
|
scope = Scope().get_instance()
|
|
|
|
plugin_manager = scope.get_plugin_manager()
|
2016-07-13 17:39:44 +03:00
|
|
|
plugin_manager.process_mode('shutdown')
|
|
|
|
|
2016-05-06 16:34:58 +03:00
|
|
|
def registration_failed(self):
|
2016-08-18 21:04:17 +03:00
|
|
|
""" docstring"""
|
2018-11-02 14:01:49 +03:00
|
|
|
self.logger.error('Registration failed. All registration attempts were failed. Ahenk is stopping...')
|
2016-06-21 17:47:25 +03:00
|
|
|
print('Registration failed. Ahenk is stopping..')
|
2016-08-18 21:04:17 +03:00
|
|
|
ahenk_daemon.stop()
|
2016-04-08 15:54:26 +03:00
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
@staticmethod
|
|
|
|
def reload_plugins():
|
|
|
|
""" docstring"""
|
2016-09-21 12:01:07 +03:00
|
|
|
Scope.get_instance().get_plugin_manager().reloadPlugins()
|
2016-04-06 17:40:25 +03:00
|
|
|
|
|
|
|
def reload_configuration(self):
|
|
|
|
# Not implemented yet
|
|
|
|
pass
|
|
|
|
|
|
|
|
def reload_messaging(self):
|
2016-04-11 19:27:26 +03:00
|
|
|
# Not implemented yet
|
2016-04-06 17:40:25 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
def reload_logger(self):
|
2016-04-11 19:27:26 +03:00
|
|
|
# Not implemented yet
|
2016-04-06 17:40:25 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
def update_plugin_manager(self):
|
2016-08-18 21:04:17 +03:00
|
|
|
""" docstring"""
|
2016-04-11 19:27:26 +03:00
|
|
|
# TODO destroy plugin manager here
|
2016-04-06 17:40:25 +03:00
|
|
|
self.init_plugin_manager()
|
|
|
|
|
2016-07-22 10:40:41 +03:00
|
|
|
def init_signal_listener(self):
|
2016-08-18 21:04:17 +03:00
|
|
|
""" docstring"""
|
2016-07-22 10:40:41 +03:00
|
|
|
try:
|
2016-09-21 12:01:07 +03:00
|
|
|
signal.signal(signal.SIGALRM, CommandRunner().run_command_from_fifo)
|
|
|
|
self.logger.info('Signal handler is set up')
|
2016-07-22 10:40:41 +03:00
|
|
|
except Exception as e:
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.error('Signal handler could not set up. Error Message: {0} '.format(str(e)))
|
2016-07-22 10:40:41 +03:00
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
@staticmethod
|
|
|
|
def init_pid_file():
|
|
|
|
""" docstring"""
|
2016-07-22 10:40:41 +03:00
|
|
|
with open(System.Ahenk.pid_path(), 'w+') as f:
|
|
|
|
f.write(str(os.getpid()))
|
|
|
|
|
2016-08-24 18:04:06 +03:00
|
|
|
@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')
|
|
|
|
|
2020-10-05 10:29:12 +03:00
|
|
|
def set_register_user(self, hostName, username, password):
|
2020-04-06 18:10:41 +03:00
|
|
|
self.register_hostname=hostName
|
|
|
|
self.register_user_name=username
|
|
|
|
self.register_user_password=password
|
2020-07-23 14:35:27 +03:00
|
|
|
# self.register_directory_server = directoryServer
|
2018-11-19 13:57:35 +03:00
|
|
|
|
2020-04-06 18:10:41 +03:00
|
|
|
# if user_disabled is when ahenk service restarted TRUE disabled local users
|
|
|
|
def disable_local_users(self):
|
2018-11-19 13:57:35 +03:00
|
|
|
self.logger.info('Local users disable action start..')
|
|
|
|
conf_manager = Scope.get_instance().get_configuration_manager()
|
|
|
|
|
|
|
|
if conf_manager.has_section('MACHINE'):
|
|
|
|
user_disabled = conf_manager.get("MACHINE", "user_disabled")
|
|
|
|
self.logger.info('User disabled value=' + str(user_disabled))
|
2020-04-06 18:10:41 +03:00
|
|
|
if user_disabled == 'true':
|
2018-11-19 13:57:35 +03:00
|
|
|
self.logger.info('local user disabling')
|
|
|
|
Scope.get_instance().get_registration().disable_local_users()
|
2020-04-06 18:10:41 +03:00
|
|
|
conf_manager.set('MACHINE', 'user_disabled', 'disabled')
|
2018-11-19 13:57:35 +03:00
|
|
|
|
|
|
|
with open('/etc/ahenk/ahenk.conf', 'w') as configfile:
|
2020-04-06 18:10:41 +03:00
|
|
|
self.logger.info('opening config file ')
|
2018-11-19 13:57:35 +03:00
|
|
|
conf_manager.write(configfile)
|
|
|
|
|
|
|
|
user_disabled = conf_manager.get("MACHINE", "user_disabled")
|
|
|
|
self.logger.info('User succesfully disabled value=' + str(user_disabled))
|
2020-04-06 18:10:41 +03:00
|
|
|
|
2018-11-19 13:57:35 +03:00
|
|
|
else:
|
2020-04-06 18:10:41 +03:00
|
|
|
self.logger.info('local users will not be disabled because local_user_paramater is FALSE')
|
2018-11-19 13:57:35 +03:00
|
|
|
|
2016-03-11 17:51:26 +02:00
|
|
|
def run(self):
|
2016-08-18 21:04:17 +03:00
|
|
|
""" docstring"""
|
2016-03-22 16:43:47 +02:00
|
|
|
print('Ahenk running...')
|
2016-03-02 18:31:29 +02:00
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
global_scope = Scope()
|
2016-09-21 12:01:07 +03:00
|
|
|
global_scope.set_instance(global_scope)
|
2016-02-25 01:46:27 +02:00
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
config_file_folder_path = '/etc/ahenk/config.d/'
|
2016-02-21 03:56:08 +02:00
|
|
|
|
2016-03-23 17:15:27 +02:00
|
|
|
# configuration manager must be first load
|
2016-08-18 21:04:17 +03:00
|
|
|
self.init_config_manager(System.Ahenk.config_path(), config_file_folder_path)
|
2016-02-21 03:56:08 +02:00
|
|
|
|
2016-03-11 17:51:26 +02:00
|
|
|
# Logger must be second
|
2016-06-06 12:27:46 +03:00
|
|
|
self.logger = self.init_logger()
|
2016-02-08 19:03:38 +02:00
|
|
|
|
2016-07-22 10:40:41 +03:00
|
|
|
self.init_pid_file()
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.info('Pid file was created')
|
2016-07-22 10:40:41 +03:00
|
|
|
|
2016-08-24 18:04:06 +03:00
|
|
|
self.init_fifo_file()
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.info('Fifo file was created')
|
2016-08-24 18:04:06 +03:00
|
|
|
|
2016-04-05 17:55:15 +03:00
|
|
|
self.init_event_manager()
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.info('Event Manager was set')
|
2016-03-04 18:01:47 +02:00
|
|
|
|
2016-04-05 17:55:15 +03:00
|
|
|
self.init_ahenk_db()
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.info('DataBase Service was set')
|
2016-03-18 18:45:06 +02:00
|
|
|
|
2016-04-05 17:55:15 +03:00
|
|
|
self.init_messaging()
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.info('Message Manager was set')
|
2016-03-07 17:59:02 +02:00
|
|
|
|
2016-04-05 17:55:15 +03:00
|
|
|
self.init_plugin_manager()
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.info('Plugin Manager was set')
|
2016-02-21 03:56:08 +02:00
|
|
|
|
2016-06-22 18:20:25 +03:00
|
|
|
self.init_scheduler()
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.info('Scheduler was set')
|
2016-06-22 18:20:25 +03:00
|
|
|
|
2016-04-05 17:55:15 +03:00
|
|
|
self.init_task_manager()
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.info('Task Manager was set')
|
2016-03-01 12:41:55 +02:00
|
|
|
|
2016-04-08 15:54:26 +03:00
|
|
|
self.init_registration()
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.info('Registration was set')
|
2016-03-04 19:23:21 +02:00
|
|
|
|
2016-04-05 17:55:15 +03:00
|
|
|
self.init_execution_manager()
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.info('Execution Manager was set')
|
2016-03-08 18:09:26 +02:00
|
|
|
|
2016-04-08 15:54:26 +03:00
|
|
|
self.check_registration()
|
2018-11-02 14:01:49 +03:00
|
|
|
|
2020-04-06 18:10:41 +03:00
|
|
|
self.is_registered()
|
2018-11-15 12:49:42 +03:00
|
|
|
|
2018-11-19 13:57:35 +03:00
|
|
|
self.disable_local_users()
|
2018-11-14 11:03:32 +03:00
|
|
|
|
2018-11-10 22:28:32 +03:00
|
|
|
#self.logger.info('Ahenk was registered')
|
2016-07-13 17:39:44 +03:00
|
|
|
|
2016-06-20 17:35:59 +03:00
|
|
|
self.messenger = self.init_messenger()
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.info('Messenger was set')
|
2016-07-22 10:40:41 +03:00
|
|
|
|
|
|
|
self.init_signal_listener()
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.info('Signals listeners was set')
|
2016-03-18 18:45:06 +02:00
|
|
|
|
2020-04-06 18:10:41 +03:00
|
|
|
# Agreement().agreement_contract_update()
|
|
|
|
|
2016-09-21 12:01:07 +03:00
|
|
|
global_scope.put_custom_map('ahenk_daemon', ahenk_daemon)
|
2016-04-05 17:55:15 +03:00
|
|
|
self.init_message_response_queue()
|
2016-03-18 18:45:06 +02:00
|
|
|
|
2016-03-23 17:15:27 +02:00
|
|
|
# if registration.is_ldap_registered() is False:
|
2016-09-21 12:01:07 +03:00
|
|
|
# logger.debug('Attempting to registering ldap')
|
2016-03-23 10:04:31 +02:00
|
|
|
# registration.ldap_registration_request() #TODO work on message
|
2016-03-11 17:51:26 +02:00
|
|
|
|
2016-09-21 12:01:07 +03:00
|
|
|
self.logger.info('LDAP registration of Ahenk is completed')
|
2016-03-07 17:59:02 +02:00
|
|
|
|
2016-06-20 17:35:59 +03:00
|
|
|
self.messenger.send_direct_message('test')
|
2016-03-07 17:59:02 +02:00
|
|
|
|
2016-03-22 16:43:47 +02:00
|
|
|
while True:
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
|
2016-03-29 16:11:39 +03:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
2016-08-18 21:04:17 +03:00
|
|
|
ahenk_daemon = AhenkDaemon(System.Ahenk.pid_path())
|
2016-03-29 16:11:39 +03:00
|
|
|
try:
|
2016-07-13 17:39:44 +03:00
|
|
|
if len(sys.argv) == 2 and (sys.argv[1] in ('start', 'stop', 'restart', 'status')):
|
2020-10-05 13:43:30 +03:00
|
|
|
ahenk_daemon.set_register_user(None, None, None)
|
2016-03-29 16:11:39 +03:00
|
|
|
if sys.argv[1] == 'start':
|
2016-06-06 12:27:46 +03:00
|
|
|
if System.Ahenk.is_running() is True:
|
2016-08-18 21:04:17 +03:00
|
|
|
print('There is already running Ahenk service. It will be killed.[{0}]'.format(
|
|
|
|
str(System.Ahenk.get_pid_number())))
|
2016-06-06 12:27:46 +03:00
|
|
|
System.Process.kill_by_pid(int(System.Ahenk.get_pid_number()))
|
|
|
|
else:
|
|
|
|
print('Ahenk starting...')
|
2016-08-18 21:04:17 +03:00
|
|
|
ahenk_daemon.run()
|
2016-03-29 16:11:39 +03:00
|
|
|
elif sys.argv[1] == 'stop':
|
2016-06-06 12:27:46 +03:00
|
|
|
if System.Ahenk.is_running() is True:
|
2016-07-13 17:39:44 +03:00
|
|
|
raise SystemExit
|
2016-06-06 12:27:46 +03:00
|
|
|
else:
|
|
|
|
print('Ahenk not working!')
|
2016-03-29 16:11:39 +03:00
|
|
|
elif sys.argv[1] == 'restart':
|
2016-06-06 12:27:46 +03:00
|
|
|
if System.Ahenk.is_running() is True:
|
|
|
|
print('Ahenk restarting...')
|
2016-08-18 21:04:17 +03:00
|
|
|
ahenk_daemon.restart()
|
2016-06-06 12:27:46 +03:00
|
|
|
else:
|
|
|
|
print('Ahenk starting...')
|
2016-08-18 21:04:17 +03:00
|
|
|
ahenk_daemon.run()
|
2016-03-29 16:11:39 +03:00
|
|
|
elif sys.argv[1] == 'status':
|
2016-06-06 12:27:46 +03:00
|
|
|
print(Commander().status())
|
2016-03-29 16:11:39 +03:00
|
|
|
else:
|
2016-06-06 12:27:46 +03:00
|
|
|
print('Unknown command. Usage : %s start|stop|restart|status|clean' % sys.argv[0])
|
2016-03-29 16:11:39 +03:00
|
|
|
sys.exit(2)
|
2020-06-24 12:23:34 +03:00
|
|
|
elif len(sys.argv) > 2 and (sys.argv[1] in ('start')):
|
2020-04-06 18:10:41 +03:00
|
|
|
params = sys.argv[1]
|
|
|
|
hostName = sys.argv[2]
|
|
|
|
userName = sys.argv[3]
|
|
|
|
password = sys.argv[4]
|
2020-07-23 14:35:27 +03:00
|
|
|
# directoryServer = sys.argv[5]
|
|
|
|
# ahenk_daemon.set_register_user(hostName,userName,password,directoryServer)
|
|
|
|
ahenk_daemon.set_register_user(hostName,userName,password)
|
2020-04-06 18:10:41 +03:00
|
|
|
ahenk_daemon.run()
|
|
|
|
|
2016-03-22 16:43:47 +02:00
|
|
|
else:
|
2016-06-06 12:27:46 +03:00
|
|
|
result = Commander().set_event(sys.argv)
|
|
|
|
if result is None:
|
|
|
|
print('Usage : {0} start|stop|restart|status|clean'.format(sys.argv[0]))
|
|
|
|
sys.exit(2)
|
|
|
|
elif result is True:
|
|
|
|
if System.Ahenk.is_running() is True:
|
|
|
|
os.kill(int(System.Ahenk.get_pid_number()), signal.SIGALRM)
|
2016-03-29 16:11:39 +03:00
|
|
|
except(KeyboardInterrupt, SystemExit):
|
2016-06-06 12:27:46 +03:00
|
|
|
if System.Ahenk.is_running() is True:
|
2016-07-13 17:39:44 +03:00
|
|
|
print('Ahenk stopping...')
|
2016-07-18 18:21:03 +03:00
|
|
|
result = Commander().set_event([None, 'stop'])
|
2016-07-13 17:39:44 +03:00
|
|
|
if result is True:
|
|
|
|
if System.Ahenk.is_running() is True:
|
|
|
|
os.kill(int(System.Ahenk.get_pid_number()), signal.SIGALRM)
|
|
|
|
else:
|
2016-08-18 21:04:17 +03:00
|
|
|
ahenk_daemon.stop()
|