2022-07-25 14:08:31 +00:00
|
|
|
"""Class representing Nextcloud service."""
|
2024-07-26 19:59:44 +00:00
|
|
|
|
2022-07-25 14:08:31 +00:00
|
|
|
import base64
|
|
|
|
import subprocess
|
2024-07-26 15:33:04 +00:00
|
|
|
from typing import List
|
2024-02-18 23:58:00 +00:00
|
|
|
|
2024-03-05 08:55:52 +00:00
|
|
|
from selfprivacy_api.utils.systemd import get_service_status
|
2024-03-01 00:21:31 +00:00
|
|
|
from selfprivacy_api.services.service import Service, ServiceStatus
|
2024-02-18 23:58:00 +00:00
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
from selfprivacy_api.services.nextcloud.icon import NEXTCLOUD_ICON
|
2024-07-26 15:33:04 +00:00
|
|
|
from selfprivacy_api.services.config_item import (
|
|
|
|
StringServiceConfigItem,
|
|
|
|
ServiceConfigItem,
|
|
|
|
)
|
|
|
|
from selfprivacy_api.utils.regex_strings import SUBDOMAIN_REGEX
|
2022-07-25 14:08:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Nextcloud(Service):
|
|
|
|
"""Class representing Nextcloud service."""
|
|
|
|
|
2024-07-26 15:33:04 +00:00
|
|
|
config_items: dict[str, ServiceConfigItem] = {
|
|
|
|
"subdomain": StringServiceConfigItem(
|
|
|
|
id="subdomain",
|
|
|
|
default_value="cloud",
|
|
|
|
description="Subdomain",
|
|
|
|
regex=SUBDOMAIN_REGEX,
|
|
|
|
widget="subdomain",
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_id() -> str:
|
2022-07-25 14:08:31 +00:00
|
|
|
"""Return service id."""
|
|
|
|
return "nextcloud"
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_display_name() -> str:
|
2022-07-25 14:08:31 +00:00
|
|
|
"""Return service display name."""
|
|
|
|
return "Nextcloud"
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_description() -> str:
|
2022-07-25 14:08:31 +00:00
|
|
|
"""Return service description."""
|
|
|
|
return "Nextcloud is a cloud storage service that offers a web interface and a desktop client."
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_svg_icon() -> str:
|
2022-07-25 14:08:31 +00:00
|
|
|
"""Read SVG icon from file and return it as base64 encoded string."""
|
2022-08-25 17:03:56 +00:00
|
|
|
return base64.b64encode(NEXTCLOUD_ICON.encode("utf-8")).decode("utf-8")
|
2022-07-25 14:08:31 +00:00
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def is_movable() -> bool:
|
|
|
|
return True
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_required() -> bool:
|
|
|
|
return False
|
|
|
|
|
2023-06-29 11:27:08 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_backup_description() -> str:
|
|
|
|
return "All the files and other data stored in Nextcloud."
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_status() -> ServiceStatus:
|
2022-07-25 14:08:31 +00:00
|
|
|
"""
|
|
|
|
Return Nextcloud status from systemd.
|
|
|
|
Use command return code to determine status.
|
|
|
|
|
|
|
|
Return code 0 means service is running.
|
|
|
|
Return code 1 or 2 means service is in error stat.
|
|
|
|
Return code 3 means service is stopped.
|
|
|
|
Return code 4 means service is off.
|
|
|
|
"""
|
2022-08-25 17:03:56 +00:00
|
|
|
return get_service_status("phpfpm-nextcloud.service")
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def stop():
|
2022-07-25 14:08:31 +00:00
|
|
|
"""Stop Nextcloud service."""
|
|
|
|
subprocess.Popen(["systemctl", "stop", "phpfpm-nextcloud.service"])
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def start():
|
2022-07-25 14:08:31 +00:00
|
|
|
"""Start Nextcloud service."""
|
|
|
|
subprocess.Popen(["systemctl", "start", "phpfpm-nextcloud.service"])
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def restart():
|
2022-07-25 14:08:31 +00:00
|
|
|
"""Restart Nextcloud service."""
|
|
|
|
subprocess.Popen(["systemctl", "restart", "phpfpm-nextcloud.service"])
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_logs():
|
2022-07-25 14:08:31 +00:00
|
|
|
"""Return Nextcloud logs."""
|
|
|
|
return ""
|
|
|
|
|
2023-04-17 13:47:49 +00:00
|
|
|
@staticmethod
|
2024-03-01 00:21:31 +00:00
|
|
|
def get_folders() -> List[str]:
|
2023-04-17 13:47:49 +00:00
|
|
|
return ["/var/lib/nextcloud"]
|