pybackive/backive/backive_service

54 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""
Service startup script.
"""
import sys
import os
import asyncio
import logging
from backive.core.events import EventInterface
from backive.config.config import Config
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.")
class Backive:
def __init__(self):
self._config = Config()
self._events = None
async def callback(self, data=None):
print("Callback: {}".format(str(data)))
def serve(self):
loop = asyncio.get_event_loop()
self._events = EventInterface(self.callback, None, loop)
loop.run_forever()
pass
def __del__(self):
del self._events
if __name__ == "__main__":
backive = None
try:
backive = Backive()
backive.serve()
except Exception as e:
raise e
finally:
logging.info("Backive exited.")
del backive