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-02-08 19:03:38 +02:00
|
|
|
from base.config.ConfigManager import ConfigManager
|
2016-02-25 17:24:07 +02:00
|
|
|
from base.deamon.BaseDeamon import BaseDaemon
|
|
|
|
from base.logger.AhenkLogger import Logger
|
2016-02-21 03:56:08 +02:00
|
|
|
from base.Scope import Scope
|
2016-03-07 17:59:02 +02:00
|
|
|
from base.messaging.Messaging import Messaging
|
2016-03-02 18:31:29 +02:00
|
|
|
from base.messaging.MessageReceiver import MessageReceiver
|
|
|
|
from base.messaging.MessageSender import MessageSender
|
|
|
|
from base.registration.Registration import Registration
|
2016-03-02 17:20:42 +02:00
|
|
|
from base.messaging.MessageResponseQueue import MessageResponseQueue
|
2016-03-04 18:01:47 +02:00
|
|
|
from base.event.EventManager import EventManager
|
2016-03-02 17:20:42 +02:00
|
|
|
from base.plugin.PluginManager import PluginManager
|
|
|
|
from base.task.TaskManager import TaskManager
|
2016-03-01 12:41:55 +02:00
|
|
|
from multiprocessing import Process
|
|
|
|
from threading import Thread
|
2016-03-02 17:20:42 +02:00
|
|
|
import sys,logging,queue,time
|
2016-02-01 17:49:17 +02:00
|
|
|
|
2016-02-08 19:03:38 +02:00
|
|
|
|
2016-02-25 17:24:07 +02:00
|
|
|
class AhenkDeamon(BaseDaemon):
|
2016-02-08 19:03:38 +02:00
|
|
|
"""docstring for AhenkDeamon"""
|
2016-02-21 03:56:08 +02:00
|
|
|
|
2016-03-04 18:01:47 +02:00
|
|
|
def reload(self,msg):
|
|
|
|
# reload service here
|
|
|
|
pass
|
|
|
|
|
2016-02-21 03:56:08 +02:00
|
|
|
def run(self):
|
2016-02-29 10:48:00 +02:00
|
|
|
print ("merhaba dunya")
|
2016-03-02 18:31:29 +02:00
|
|
|
|
2016-02-25 01:46:27 +02:00
|
|
|
globalscope = Scope()
|
|
|
|
globalscope.setInstance(globalscope)
|
|
|
|
|
2016-02-21 03:56:08 +02:00
|
|
|
configFilePath='/etc/ahenk/ahenk.conf'
|
|
|
|
configfileFolderPath='/etc/ahenk/config.d/'
|
|
|
|
|
|
|
|
#configuration manager must be first load
|
|
|
|
configManager = ConfigManager(configFilePath,configfileFolderPath)
|
|
|
|
config = configManager.read()
|
|
|
|
globalscope.setConfigurationManager(config)
|
|
|
|
|
2016-03-02 17:20:42 +02:00
|
|
|
# Logger must be second
|
2016-02-21 03:56:08 +02:00
|
|
|
logger = Logger()
|
2016-03-02 17:20:42 +02:00
|
|
|
logger.info("this is info log")
|
2016-02-21 03:56:08 +02:00
|
|
|
globalscope.setLogger(logger)
|
2016-02-08 19:03:38 +02:00
|
|
|
|
2016-03-04 18:01:47 +02:00
|
|
|
eventManager = EventManager()
|
|
|
|
globalscope.setEventManager(eventManager)
|
|
|
|
|
2016-03-07 17:59:02 +02:00
|
|
|
messageManager = Messaging()
|
|
|
|
globalscope.setMessageManager(messageManager)
|
|
|
|
|
|
|
|
|
2016-03-02 17:20:42 +02:00
|
|
|
pluginManager = PluginManager()
|
|
|
|
pluginManager.loadPlugins()
|
|
|
|
globalscope.setPluginManager(pluginManager)
|
2016-02-21 03:56:08 +02:00
|
|
|
|
2016-03-02 17:20:42 +02:00
|
|
|
taskManger = TaskManager()
|
|
|
|
globalscope.setTaskManager(taskManger)
|
2016-03-01 12:41:55 +02:00
|
|
|
|
2016-03-04 19:23:21 +02:00
|
|
|
registration=Registration()
|
|
|
|
globalscope.setRegistration(registration)
|
|
|
|
|
2016-03-07 12:55:14 +02:00
|
|
|
while registration.is_registered() is False:
|
|
|
|
registration.registration_request()
|
2016-03-04 19:23:21 +02:00
|
|
|
|
2016-03-07 17:59:02 +02:00
|
|
|
#eventManager.register_event('registration_ok',self.reload)
|
|
|
|
|
|
|
|
#registration.unregister()
|
2016-03-04 19:23:21 +02:00
|
|
|
|
|
|
|
|
2016-03-07 17:59:02 +02:00
|
|
|
"""
|
2016-03-02 18:31:29 +02:00
|
|
|
message_receiver = MessageReceiver()
|
|
|
|
rec_process = Process(target=message_receiver.connect_to_server)
|
|
|
|
rec_process.start()
|
2016-03-02 17:20:42 +02:00
|
|
|
"""
|
|
|
|
|
2016-03-07 17:59:02 +02:00
|
|
|
#rec_process.terminate()
|
|
|
|
|
|
|
|
|
|
|
|
#message_sender=MessageSender(None,'/home/volkan/Desktop/batman.png')
|
|
|
|
#message_sender.connect_to_server()
|
|
|
|
|
|
|
|
|
2016-03-07 12:55:14 +02:00
|
|
|
|
2016-03-02 17:20:42 +02:00
|
|
|
"""
|
|
|
|
this is must be created after message services
|
|
|
|
responseQueue = queue.Queue()
|
|
|
|
messageResponseQueue = MessageResponseQueue(responseQueue)
|
|
|
|
messageResponseQueue.setDaemon(True)
|
|
|
|
messageResponseQueue.start()
|
|
|
|
globalscope.setResponseQueue(responseQueue)
|
|
|
|
"""
|
2016-03-01 12:41:55 +02:00
|
|
|
|
2016-03-04 19:23:21 +02:00
|
|
|
|
2016-02-21 03:56:08 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
pidfilePath='/var/run/ahenk.pid'
|
|
|
|
|
2016-02-25 17:24:07 +02:00
|
|
|
ahenkdaemon = AhenkDeamon(pidfilePath)
|
2016-02-21 03:56:08 +02:00
|
|
|
|
2016-02-29 10:48:00 +02:00
|
|
|
print (sys.argv)
|
2016-03-01 12:41:55 +02:00
|
|
|
|
2016-02-08 19:03:38 +02:00
|
|
|
if len(sys.argv) == 2:
|
|
|
|
if sys.argv[1] == "start":
|
2016-02-29 10:48:00 +02:00
|
|
|
print ("starting")
|
2016-03-01 12:41:55 +02:00
|
|
|
ahenkdaemon.run()
|
|
|
|
#print (ahenkdaemon.get_pid())
|
2016-02-08 19:03:38 +02:00
|
|
|
elif sys.argv[1] == 'stop':
|
2016-02-25 17:24:07 +02:00
|
|
|
ahenkdaemon.stop()
|
2016-02-08 19:03:38 +02:00
|
|
|
elif sys.argv[1] == 'restart':
|
2016-02-25 17:24:07 +02:00
|
|
|
ahenkdaemon.restart()
|
2016-02-08 19:03:38 +02:00
|
|
|
elif sys.argv[1] == 'status':
|
2016-02-29 10:48:00 +02:00
|
|
|
# print (status)
|
2016-02-08 19:03:38 +02:00
|
|
|
pass
|
|
|
|
else:
|
2016-02-29 10:48:00 +02:00
|
|
|
print ('Unknown command. Usage : %s start|stop|restart|status' % sys.argv[0])
|
2016-02-08 19:03:38 +02:00
|
|
|
sys.exit(2)
|
|
|
|
sys.exit(0)
|
|
|
|
else:
|
2016-02-29 10:48:00 +02:00
|
|
|
print ('Usage : %s start|stop|restart|status' % sys.argv[0])
|
2016-02-08 19:03:38 +02:00
|
|
|
sys.exit(2)
|