2018-04-02 22:41:10 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
from Config import cnf
|
|
|
|
from lib import Logger, Loader
|
|
|
|
|
|
|
|
class Core:
|
2018-04-02 23:47:50 +00:00
|
|
|
"""Core class, contains core services (like listeners, executors, datapool)"""
|
2018-04-02 22:41:10 +00:00
|
|
|
def __init__(self):
|
2018-07-28 12:21:15 +00:00
|
|
|
self.cnf = cnf.get("core")
|
2018-04-02 22:41:10 +00:00
|
|
|
self.logger = Logger("Core")
|
|
|
|
self.logger.debug("Loading services")
|
|
|
|
|
|
|
|
self._services = []
|
2018-07-28 12:21:15 +00:00
|
|
|
|
|
|
|
for service_name in self.cnf.get("services"):
|
|
|
|
service = Loader.by_id('services', service_name)
|
2018-04-02 22:41:10 +00:00
|
|
|
self._services.append(service)
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
self.logger.info("Starting")
|
|
|
|
for service in self._services:
|
|
|
|
service.start()
|
|
|
|
self.logger.info("Started")
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
self.logger.info("Stopping Core")
|
|
|
|
for service in self._services:
|
|
|
|
service.stop()
|
|
|
|
self.logger.info("Stopped")
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
core = Core()
|
|
|
|
core.start()
|
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
time.sleep(1)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
core.stop()
|