2019-02-22 21:26:01 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
"""
|
|
|
|
Service startup script.
|
|
|
|
"""
|
2020-01-06 13:26:52 +01:00
|
|
|
import sys
|
|
|
|
import os
|
2020-01-05 13:17:46 +01:00
|
|
|
import asyncio
|
2020-01-06 13:26:52 +01:00
|
|
|
import logging
|
2019-05-03 20:36:09 +02:00
|
|
|
from backive.core.events import EventInterface
|
2019-05-03 21:36:44 +02:00
|
|
|
from backive.config.config import Config
|
2019-05-03 20:36:09 +02:00
|
|
|
|
2019-02-24 22:42:36 +01:00
|
|
|
|
2020-01-06 13:26:52 +01:00
|
|
|
rootlogger = logging.getLogger()
|
|
|
|
rootlogger.setLevel(logging.DEBUG)
|
|
|
|
consoleHandler = logging.StreamHandler(sys.stdout)
|
|
|
|
fileHandler = logging.FileHandler("/var/log/backive/backive.log")
|
|
|
|
if not os.path.exists("/var/log/backive"):
|
|
|
|
os.makedirs("/var/log/backive")
|
|
|
|
rootlogger.addHandler(consoleHandler)
|
|
|
|
rootlogger.addHandler(fileHandler)
|
|
|
|
|
|
|
|
logging.info("Backive starting.")
|
|
|
|
|
|
|
|
|
2019-02-24 22:42:36 +01:00
|
|
|
class Backive:
|
|
|
|
def __init__(self):
|
2019-05-03 21:36:44 +02:00
|
|
|
self._config = Config()
|
2019-05-03 20:36:09 +02:00
|
|
|
self._events = None
|
2019-02-24 22:42:36 +01:00
|
|
|
|
2020-01-05 13:17:46 +01:00
|
|
|
async def callback(self, data=None):
|
|
|
|
print("Callback: {}".format(str(data)))
|
|
|
|
|
2019-02-24 22:42:36 +01:00
|
|
|
def serve(self):
|
2020-01-05 13:17:46 +01:00
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
self._events = EventInterface(self.callback, None, loop)
|
|
|
|
loop.run_forever()
|
2019-02-24 22:42:36 +01:00
|
|
|
pass
|
|
|
|
|
2020-01-06 13:26:52 +01:00
|
|
|
def __del__(self):
|
|
|
|
del self._events
|
|
|
|
|
2019-02-24 22:42:36 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-01-06 13:26:52 +01:00
|
|
|
backive = None
|
|
|
|
try:
|
|
|
|
backive = Backive()
|
|
|
|
backive.serve()
|
|
|
|
except Exception as e:
|
|
|
|
raise e
|
|
|
|
finally:
|
|
|
|
logging.info("Backive exited.")
|
|
|
|
del backive
|