chore(services): clean up the config service

This commit is contained in:
Houkime 2024-09-06 13:31:19 +00:00
parent 408284a69f
commit 6eca44526a
2 changed files with 25 additions and 27 deletions

View file

@ -137,19 +137,6 @@ class ServiceManager(Service):
def get_backup_description() -> str: def get_backup_description() -> str:
return "How did we get here?" return "How did we get here?"
@classmethod
def status_file(cls) -> str:
dir = cls.folders[0]
# We do not want to store our state in our declared folders
# Because they are moved and tossed in tests wildly
parent = Path(dir).parent
return path.join(parent, "service_status")
@classmethod
def set_status(cls, status: ServiceStatus):
pass
@classmethod @classmethod
def get_status(cls) -> ServiceStatus: def get_status(cls) -> ServiceStatus:
return ServiceStatus.ACTIVE return ServiceStatus.ACTIVE
@ -160,7 +147,7 @@ class ServiceManager(Service):
return True return True
@classmethod @classmethod
def merge_settings(cls, restored_settings_folder: str): def merge_settings(cls):
# For now we will just copy settings EXCEPT the locations of services # For now we will just copy settings EXCEPT the locations of services
# Stash locations as they are set by user right now # Stash locations as they are set by user right now
locations = {} locations = {}
@ -179,23 +166,28 @@ class ServiceManager(Service):
@classmethod @classmethod
def stop(cls): def stop(cls):
# simulate a failing service unable to stop """
if not cls.get_status() == ServiceStatus.FAILED: We are always active
cls.set_status(ServiceStatus.DEACTIVATING) """
cls.change_status_with_async_delay( raise ValueError("tried to stop an always active service")
ServiceStatus.INACTIVE, cls.startstop_delay
)
@classmethod @classmethod
def start(cls): def start(cls):
"""
We are always active
"""
pass pass
@classmethod @classmethod
def restart(cls): def restart(cls):
"""
We are always active
"""
pass pass
@staticmethod @staticmethod
def get_logs(): def get_logs():
# TODO: maybe return the logs for api itself
return "" return ""
@classmethod @classmethod
@ -209,8 +201,7 @@ class ServiceManager(Service):
@classmethod @classmethod
def stash_for(cls, p: str) -> str: def stash_for(cls, p: str) -> str:
basename = path.basename(p) basename = path.basename(p)
tempdir = cls.folders[0] stashed_file_location = join(cls.dump_dir(), basename)
stashed_file_location = join(tempdir, basename)
return stashed_file_location return stashed_file_location
@classmethod @classmethod
@ -234,7 +225,7 @@ class ServiceManager(Service):
@classmethod @classmethod
def pre_backup(cls): def pre_backup(cls):
tempdir = cls.folders[0] tempdir = cls.dump_dir()
if not path.exists(tempdir): if not path.exists(tempdir):
makedirs(tempdir) makedirs(tempdir)
@ -245,11 +236,17 @@ class ServiceManager(Service):
for p in [USERDATA_FILE, SECRETS_FILE, DKIM_DIR]: for p in [USERDATA_FILE, SECRETS_FILE, DKIM_DIR]:
cls.stash_a_path(p) cls.stash_a_path(p)
@classmethod
def dump_dir(cls) -> str:
"""
A directory we dump our settings into
"""
return cls.folders[0]
@classmethod @classmethod
def post_restore(cls): def post_restore(cls):
tempdir = cls.folders[0] cls.merge_settings()
cls.merge_settings(tempdir) rmtree(cls.dump_dir(), ignore_errors=True)
rmtree(tempdir, ignore_errors=True)
services: list[Service] = [ services: list[Service] = [

View file

@ -54,7 +54,8 @@ class BlockDevice:
def update_from_dict(self, device_dict: dict): def update_from_dict(self, device_dict: dict):
self.name = device_dict["name"] self.name = device_dict["name"]
self.path = device_dict["path"] self.path = device_dict["path"]
# why is it string? # lsblk gives us json with strings. Awkwardly.
# TODO: maybe parse it more fully?
self.fsavail = str(device_dict["fsavail"]) self.fsavail = str(device_dict["fsavail"])
self.fssize = str(device_dict["fssize"]) self.fssize = str(device_dict["fssize"])
self.fstype = device_dict["fstype"] self.fstype = device_dict["fstype"]