refactor(services): use generic code for enabling and disabling
This commit is contained in:
parent
b8d02231cf
commit
8e551a8fe0
|
@ -58,11 +58,6 @@ class Bitwarden(Service):
|
||||||
def get_backup_description() -> str:
|
def get_backup_description() -> str:
|
||||||
return "Password database, encryption certificate and attachments."
|
return "Password database, encryption certificate and attachments."
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def is_enabled() -> bool:
|
|
||||||
with ReadUserData() as user_data:
|
|
||||||
return user_data.get("bitwarden", {}).get("enable", False)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_status() -> ServiceStatus:
|
def get_status() -> ServiceStatus:
|
||||||
"""
|
"""
|
||||||
|
@ -76,22 +71,6 @@ class Bitwarden(Service):
|
||||||
"""
|
"""
|
||||||
return get_service_status("vaultwarden.service")
|
return get_service_status("vaultwarden.service")
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def enable():
|
|
||||||
"""Enable Bitwarden service."""
|
|
||||||
with WriteUserData() as user_data:
|
|
||||||
if "bitwarden" not in user_data:
|
|
||||||
user_data["bitwarden"] = {}
|
|
||||||
user_data["bitwarden"]["enable"] = True
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def disable():
|
|
||||||
"""Disable Bitwarden service."""
|
|
||||||
with WriteUserData() as user_data:
|
|
||||||
if "bitwarden" not in user_data:
|
|
||||||
user_data["bitwarden"] = {}
|
|
||||||
user_data["bitwarden"]["enable"] = False
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def stop():
|
def stop():
|
||||||
subprocess.run(["systemctl", "stop", "vaultwarden.service"])
|
subprocess.run(["systemctl", "stop", "vaultwarden.service"])
|
||||||
|
|
|
@ -53,11 +53,6 @@ class Nextcloud(Service):
|
||||||
def get_backup_description() -> str:
|
def get_backup_description() -> str:
|
||||||
return "All the files and other data stored in Nextcloud."
|
return "All the files and other data stored in Nextcloud."
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def is_enabled() -> bool:
|
|
||||||
with ReadUserData() as user_data:
|
|
||||||
return user_data.get("nextcloud", {}).get("enable", False)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_status() -> ServiceStatus:
|
def get_status() -> ServiceStatus:
|
||||||
"""
|
"""
|
||||||
|
@ -71,22 +66,6 @@ class Nextcloud(Service):
|
||||||
"""
|
"""
|
||||||
return get_service_status("phpfpm-nextcloud.service")
|
return get_service_status("phpfpm-nextcloud.service")
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def enable():
|
|
||||||
"""Enable Nextcloud service."""
|
|
||||||
with WriteUserData() as user_data:
|
|
||||||
if "nextcloud" not in user_data:
|
|
||||||
user_data["nextcloud"] = {}
|
|
||||||
user_data["nextcloud"]["enable"] = True
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def disable():
|
|
||||||
"""Disable Nextcloud service."""
|
|
||||||
with WriteUserData() as user_data:
|
|
||||||
if "nextcloud" not in user_data:
|
|
||||||
user_data["nextcloud"] = {}
|
|
||||||
user_data["nextcloud"]["enable"] = False
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def stop():
|
def stop():
|
||||||
"""Stop Nextcloud service."""
|
"""Stop Nextcloud service."""
|
||||||
|
|
|
@ -51,29 +51,10 @@ class Ocserv(Service):
|
||||||
def get_backup_description() -> str:
|
def get_backup_description() -> str:
|
||||||
return "Nothing to backup."
|
return "Nothing to backup."
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def is_enabled() -> bool:
|
|
||||||
with ReadUserData() as user_data:
|
|
||||||
return user_data.get("ocserv", {}).get("enable", False)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_status() -> ServiceStatus:
|
def get_status() -> ServiceStatus:
|
||||||
return get_service_status("ocserv.service")
|
return get_service_status("ocserv.service")
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def enable():
|
|
||||||
with WriteUserData() as user_data:
|
|
||||||
if "ocserv" not in user_data:
|
|
||||||
user_data["ocserv"] = {}
|
|
||||||
user_data["ocserv"]["enable"] = True
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def disable():
|
|
||||||
with WriteUserData() as user_data:
|
|
||||||
if "ocserv" not in user_data:
|
|
||||||
user_data["ocserv"] = {}
|
|
||||||
user_data["ocserv"]["enable"] = False
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def stop():
|
def stop():
|
||||||
subprocess.run(["systemctl", "stop", "ocserv.service"], check=False)
|
subprocess.run(["systemctl", "stop", "ocserv.service"], check=False)
|
||||||
|
|
|
@ -50,29 +50,10 @@ class Pleroma(Service):
|
||||||
def get_backup_description() -> str:
|
def get_backup_description() -> str:
|
||||||
return "Your Pleroma accounts, posts and media."
|
return "Your Pleroma accounts, posts and media."
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def is_enabled() -> bool:
|
|
||||||
with ReadUserData() as user_data:
|
|
||||||
return user_data.get("pleroma", {}).get("enable", False)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_status() -> ServiceStatus:
|
def get_status() -> ServiceStatus:
|
||||||
return get_service_status("pleroma.service")
|
return get_service_status("pleroma.service")
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def enable():
|
|
||||||
with WriteUserData() as user_data:
|
|
||||||
if "pleroma" not in user_data:
|
|
||||||
user_data["pleroma"] = {}
|
|
||||||
user_data["pleroma"]["enable"] = True
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def disable():
|
|
||||||
with WriteUserData() as user_data:
|
|
||||||
if "pleroma" not in user_data:
|
|
||||||
user_data["pleroma"] = {}
|
|
||||||
user_data["pleroma"]["enable"] = False
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def stop():
|
def stop():
|
||||||
subprocess.run(["systemctl", "stop", "pleroma.service"])
|
subprocess.run(["systemctl", "stop", "pleroma.service"])
|
||||||
|
|
Loading…
Reference in New Issue