pybackive/backive/backive_service

61 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Service startup script.
"""
import sys
import os
import asyncio
import logging
import json
from backive.core.events import EventInterface
from backive.core.scheduler import Scheduler
from backive.config.config import Config
rootlogger = logging.getLogger()
rootlogger.setLevel(logging.DEBUG)
consoleHandler = logging.StreamHandler(sys.stdout)
fileHandler = logging.FileHandler("backive.log")
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):
data_dict = json.loads(data)
uuid = data_dict.get("ID_FS_UUID", None)
print("UUID: %s" % uuid)
if uuid:
backups = self._config.get_backups_by_device(uuid)
for backup in backups:
backup.run()
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