Add Jitsi to services
parent
ba434f4fb5
commit
15a900d009
|
@ -3,6 +3,7 @@
|
||||||
import typing
|
import typing
|
||||||
from selfprivacy_api.services.bitwarden import Bitwarden
|
from selfprivacy_api.services.bitwarden import Bitwarden
|
||||||
from selfprivacy_api.services.gitea import Gitea
|
from selfprivacy_api.services.gitea import Gitea
|
||||||
|
from selfprivacy_api.services.jitsi import Jitsi
|
||||||
from selfprivacy_api.services.mailserver import MailServer
|
from selfprivacy_api.services.mailserver import MailServer
|
||||||
from selfprivacy_api.services.nextcloud import Nextcloud
|
from selfprivacy_api.services.nextcloud import Nextcloud
|
||||||
from selfprivacy_api.services.pleroma import Pleroma
|
from selfprivacy_api.services.pleroma import Pleroma
|
||||||
|
@ -17,6 +18,7 @@ services: list[Service] = [
|
||||||
Nextcloud(),
|
Nextcloud(),
|
||||||
Pleroma(),
|
Pleroma(),
|
||||||
Ocserv(),
|
Ocserv(),
|
||||||
|
Jitsi(),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,18 +61,6 @@ def get_all_required_dns_records() -> list[ServiceDnsRecord]:
|
||||||
content=ip6,
|
content=ip6,
|
||||||
ttl=3600,
|
ttl=3600,
|
||||||
),
|
),
|
||||||
ServiceDnsRecord(
|
|
||||||
type="A",
|
|
||||||
name="meet",
|
|
||||||
content=ip4,
|
|
||||||
ttl=3600,
|
|
||||||
),
|
|
||||||
ServiceDnsRecord(
|
|
||||||
type="AAAA",
|
|
||||||
name="meet",
|
|
||||||
content=ip6,
|
|
||||||
ttl=3600,
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
for service in get_enabled_services():
|
for service in get_enabled_services():
|
||||||
dns_records += service.get_dns_records()
|
dns_records += service.get_dns_records()
|
||||||
|
|
|
@ -26,3 +26,35 @@ def get_service_status(service: str) -> ServiceStatus:
|
||||||
if b"ActiveState=reloading" in service_status:
|
if b"ActiveState=reloading" in service_status:
|
||||||
return ServiceStatus.RELOADING
|
return ServiceStatus.RELOADING
|
||||||
return ServiceStatus.OFF
|
return ServiceStatus.OFF
|
||||||
|
|
||||||
|
|
||||||
|
def get_service_status_from_several_units(services: list[str]) -> ServiceStatus:
|
||||||
|
"""
|
||||||
|
Fetch all service statuses for all services and return the worst status.
|
||||||
|
Statuses from worst to best:
|
||||||
|
- OFF
|
||||||
|
- FAILED
|
||||||
|
- RELOADING
|
||||||
|
- ACTIVATING
|
||||||
|
- DEACTIVATING
|
||||||
|
- INACTIVE
|
||||||
|
- ACTIVE
|
||||||
|
"""
|
||||||
|
service_statuses = []
|
||||||
|
for service in services:
|
||||||
|
service_statuses.append(get_service_status(service))
|
||||||
|
if ServiceStatus.OFF in service_statuses:
|
||||||
|
return ServiceStatus.OFF
|
||||||
|
if ServiceStatus.FAILED in service_statuses:
|
||||||
|
return ServiceStatus.FAILED
|
||||||
|
if ServiceStatus.RELOADING in service_statuses:
|
||||||
|
return ServiceStatus.RELOADING
|
||||||
|
if ServiceStatus.ACTIVATING in service_statuses:
|
||||||
|
return ServiceStatus.ACTIVATING
|
||||||
|
if ServiceStatus.DEACTIVATING in service_statuses:
|
||||||
|
return ServiceStatus.DEACTIVATING
|
||||||
|
if ServiceStatus.INACTIVE in service_statuses:
|
||||||
|
return ServiceStatus.INACTIVE
|
||||||
|
if ServiceStatus.ACTIVE in service_statuses:
|
||||||
|
return ServiceStatus.ACTIVE
|
||||||
|
return ServiceStatus.OFF
|
||||||
|
|
|
@ -0,0 +1,142 @@
|
||||||
|
"""Class representing Jitsi service"""
|
||||||
|
import base64
|
||||||
|
import subprocess
|
||||||
|
import typing
|
||||||
|
|
||||||
|
from selfprivacy_api.jobs import Job, Jobs
|
||||||
|
from selfprivacy_api.services.generic_service_mover import FolderMoveNames, move_service
|
||||||
|
from selfprivacy_api.services.generic_size_counter import get_storage_usage
|
||||||
|
from selfprivacy_api.services.generic_status_getter import (
|
||||||
|
get_service_status,
|
||||||
|
get_service_status_from_several_units,
|
||||||
|
)
|
||||||
|
from selfprivacy_api.services.service import Service, ServiceDnsRecord, ServiceStatus
|
||||||
|
from selfprivacy_api.utils import ReadUserData, WriteUserData, get_domain
|
||||||
|
from selfprivacy_api.utils.block_devices import BlockDevice
|
||||||
|
from selfprivacy_api.utils.huey import huey
|
||||||
|
import selfprivacy_api.utils.network as network_utils
|
||||||
|
from selfprivacy_api.services.jitsi.icon import JITSI_ICON
|
||||||
|
|
||||||
|
|
||||||
|
class Jitsi(Service):
|
||||||
|
"""Class representing Jitsi service"""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_id() -> str:
|
||||||
|
"""Return service id."""
|
||||||
|
return "jitsi"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_display_name() -> str:
|
||||||
|
"""Return service display name."""
|
||||||
|
return "Jitsi"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_description() -> str:
|
||||||
|
"""Return service description."""
|
||||||
|
return "Jitsi is a free and open-source video conferencing solution."
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_svg_icon() -> str:
|
||||||
|
"""Read SVG icon from file and return it as base64 encoded string."""
|
||||||
|
return base64.b64encode(JITSI_ICON.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_url() -> typing.Optional[str]:
|
||||||
|
"""Return service url."""
|
||||||
|
domain = get_domain()
|
||||||
|
return f"https://meet.{domain}"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def is_movable() -> bool:
|
||||||
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def is_required() -> bool:
|
||||||
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def is_enabled() -> bool:
|
||||||
|
with ReadUserData() as user_data:
|
||||||
|
return user_data.get("jitsi", {}).get("enable", False)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_status() -> ServiceStatus:
|
||||||
|
return get_service_status_from_several_units(
|
||||||
|
["jitsi-videobridge.service", "jicofo.service"]
|
||||||
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def enable():
|
||||||
|
"""Enable Jitsi service."""
|
||||||
|
with WriteUserData() as user_data:
|
||||||
|
if "jitsi" not in user_data:
|
||||||
|
user_data["jitsi"] = {}
|
||||||
|
user_data["jitsi"]["enable"] = True
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def disable():
|
||||||
|
"""Disable Gitea service."""
|
||||||
|
with WriteUserData() as user_data:
|
||||||
|
if "jitsi" not in user_data:
|
||||||
|
user_data["jitsi"] = {}
|
||||||
|
user_data["jitsi"]["enable"] = False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def stop():
|
||||||
|
subprocess.run(["systemctl", "stop", "jitsi-videobridge.service"])
|
||||||
|
subprocess.run(["systemctl", "stop", "jicofo.service"])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def start():
|
||||||
|
subprocess.run(["systemctl", "start", "jitsi-videobridge.service"])
|
||||||
|
subprocess.run(["systemctl", "start", "jicofo.service"])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def restart():
|
||||||
|
subprocess.run(["systemctl", "restart", "jitsi-videobridge.service"])
|
||||||
|
subprocess.run(["systemctl", "restart", "jicofo.service"])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_configuration():
|
||||||
|
return {}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def set_configuration(config_items):
|
||||||
|
return super().set_configuration(config_items)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_logs():
|
||||||
|
return ""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_storage_usage() -> int:
|
||||||
|
storage_usage = 0
|
||||||
|
storage_usage += get_storage_usage("/var/lib/jitsi-meet")
|
||||||
|
return storage_usage
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_location() -> str:
|
||||||
|
return "sda1"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
||||||
|
ip4 = network_utils.get_ip4()
|
||||||
|
ip6 = network_utils.get_ip6()
|
||||||
|
return [
|
||||||
|
ServiceDnsRecord(
|
||||||
|
type="A",
|
||||||
|
name="meet",
|
||||||
|
content=ip4,
|
||||||
|
ttl=3600,
|
||||||
|
),
|
||||||
|
ServiceDnsRecord(
|
||||||
|
type="AAAA",
|
||||||
|
name="meet",
|
||||||
|
content=ip6,
|
||||||
|
ttl=3600,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
def move_to_volume(self, volume: BlockDevice) -> Job:
|
||||||
|
raise NotImplementedError("jitsi service is not movable")
|
|
@ -0,0 +1,5 @@
|
||||||
|
JITSI_ICON = """
|
||||||
|
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M26.6665 2.66663H5.33317C3.8665 2.66663 2.67984 3.86663 2.67984 5.33329L2.6665 29.3333L7.99984 24H26.6665C28.1332 24 29.3332 22.8 29.3332 21.3333V5.33329C29.3332 3.86663 28.1332 2.66663 26.6665 2.66663ZM26.6665 21.3333H6.89317L5.33317 22.8933V5.33329H26.6665V21.3333ZM18.6665 14.1333L22.6665 17.3333V9.33329L18.6665 12.5333V9.33329H9.33317V17.3333H18.6665V14.1333Z" fill="black"/>
|
||||||
|
</svg>
|
||||||
|
"""
|
|
@ -7,7 +7,10 @@ import typing
|
||||||
from selfprivacy_api.jobs import Job, JobStatus, Jobs
|
from selfprivacy_api.jobs import Job, JobStatus, Jobs
|
||||||
from selfprivacy_api.services.generic_service_mover import FolderMoveNames, move_service
|
from selfprivacy_api.services.generic_service_mover import FolderMoveNames, move_service
|
||||||
from selfprivacy_api.services.generic_size_counter import get_storage_usage
|
from selfprivacy_api.services.generic_size_counter import get_storage_usage
|
||||||
from selfprivacy_api.services.generic_status_getter import get_service_status
|
from selfprivacy_api.services.generic_status_getter import (
|
||||||
|
get_service_status,
|
||||||
|
get_service_status_from_several_units,
|
||||||
|
)
|
||||||
from selfprivacy_api.services.service import Service, ServiceDnsRecord, ServiceStatus
|
from selfprivacy_api.services.service import Service, ServiceDnsRecord, ServiceStatus
|
||||||
import selfprivacy_api.utils as utils
|
import selfprivacy_api.utils as utils
|
||||||
from selfprivacy_api.utils.block_devices import BlockDevice
|
from selfprivacy_api.utils.block_devices import BlockDevice
|
||||||
|
@ -54,37 +57,9 @@ class MailServer(Service):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_status() -> ServiceStatus:
|
def get_status() -> ServiceStatus:
|
||||||
imap_status = get_service_status("dovecot2.service")
|
return get_service_status_from_several_units(
|
||||||
smtp_status = get_service_status("postfix.service")
|
["dovecot2.service", "postfix.service"]
|
||||||
|
)
|
||||||
if imap_status == ServiceStatus.ACTIVE and smtp_status == ServiceStatus.ACTIVE:
|
|
||||||
return ServiceStatus.ACTIVE
|
|
||||||
elif imap_status == ServiceStatus.FAILED or smtp_status == ServiceStatus.FAILED:
|
|
||||||
return ServiceStatus.FAILED
|
|
||||||
elif (
|
|
||||||
imap_status == ServiceStatus.RELOADING
|
|
||||||
or smtp_status == ServiceStatus.RELOADING
|
|
||||||
):
|
|
||||||
return ServiceStatus.RELOADING
|
|
||||||
elif (
|
|
||||||
imap_status == ServiceStatus.ACTIVATING
|
|
||||||
or smtp_status == ServiceStatus.ACTIVATING
|
|
||||||
):
|
|
||||||
return ServiceStatus.ACTIVATING
|
|
||||||
elif (
|
|
||||||
imap_status == ServiceStatus.DEACTIVATING
|
|
||||||
or smtp_status == ServiceStatus.DEACTIVATING
|
|
||||||
):
|
|
||||||
return ServiceStatus.DEACTIVATING
|
|
||||||
elif (
|
|
||||||
imap_status == ServiceStatus.INACTIVE
|
|
||||||
or smtp_status == ServiceStatus.INACTIVE
|
|
||||||
):
|
|
||||||
return ServiceStatus.INACTIVE
|
|
||||||
elif imap_status == ServiceStatus.OFF or smtp_status == ServiceStatus.OFF:
|
|
||||||
return ServiceStatus.OFF
|
|
||||||
else:
|
|
||||||
return ServiceStatus.FAILED
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def enable():
|
def enable():
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
MAILSERVER_ICON = """
|
MAILSERVER_ICON = """
|
||||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
<path d="M13.3333 2.66675H2.66665C1.93331 2.66675 1.33998 3.26675 1.33998 4.00008L1.33331 12.0001C1.33331 12.7334 1.93331 13.3334 2.66665 13.3334H13.3333C14.0666 13.3334 14.6666 12.7334 14.6666 12.0001V4.00008C14.6666 3.26675 14.0666 2.66675 13.3333 2.66675ZM13.3333 12.0001H2.66665V5.33341L7.99998 8.66675L13.3333 5.33341V12.0001ZM7.99998 7.33341L2.66665 4.00008H13.3333L7.99998 7.33341Z" fill="#201A19"/>
|
<path d="M13.3333 2.66675H2.66665C1.93331 2.66675 1.33998 3.26675 1.33998 4.00008L1.33331 12.0001C1.33331 12.7334 1.93331 13.3334 2.66665 13.3334H13.3333C14.0666 13.3334 14.6666 12.7334 14.6666 12.0001V4.00008C14.6666 3.26675 14.0666 2.66675 13.3333 2.66675ZM13.3333 12.0001H2.66665V5.33341L7.99998 8.66675L13.3333 5.33341V12.0001ZM7.99998 7.33341L2.66665 4.00008H13.3333L7.99998 7.33341Z" fill="black"/>
|
||||||
</svg>
|
</svg>
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -41,6 +41,9 @@
|
||||||
"pleroma": {
|
"pleroma": {
|
||||||
"enable": true
|
"enable": true
|
||||||
},
|
},
|
||||||
|
"jitsi": {
|
||||||
|
"enable": true
|
||||||
|
},
|
||||||
"autoUpgrade": {
|
"autoUpgrade": {
|
||||||
"enable": true,
|
"enable": true,
|
||||||
"allowReboot": true
|
"allowReboot": true
|
||||||
|
|
Loading…
Reference in New Issue