mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
nextcloud: Implement enable/disable container
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
f8ddc774b0
commit
f1276d736a
@ -11,6 +11,8 @@ import subprocess
|
|||||||
import tempfile
|
import tempfile
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
|
import augeas
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
UWSGI_ENABLED_PATH = '/etc/uwsgi/apps-enabled/{config_name}.ini'
|
UWSGI_ENABLED_PATH = '/etc/uwsgi/apps-enabled/{config_name}.ini'
|
||||||
@ -553,6 +555,46 @@ WantedBy=default.target
|
|||||||
service_daemon_reload()
|
service_daemon_reload()
|
||||||
|
|
||||||
|
|
||||||
|
def _podman_augeus(container_name: str):
|
||||||
|
"""Return an augues instance to edit container configuration file."""
|
||||||
|
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
|
||||||
|
augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||||
|
container = f'/etc/containers/systemd/{container_name}.container'
|
||||||
|
aug.transform('Systemd', container)
|
||||||
|
aug.set('/augeas/context', '/files' + container)
|
||||||
|
aug.load()
|
||||||
|
return aug
|
||||||
|
|
||||||
|
|
||||||
|
def podman_is_enabled(container_name: str) -> bool:
|
||||||
|
"""Return whether the container to start on boot."""
|
||||||
|
aug = _podman_augeus(container_name)
|
||||||
|
aug = _podman_augeus(container_name)
|
||||||
|
value = 'default.target'
|
||||||
|
key = 'Install/WantedBy'
|
||||||
|
return any(
|
||||||
|
(aug.get(match_ + '/value') == value for match_ in aug.match(key)))
|
||||||
|
|
||||||
|
|
||||||
|
def podman_enable(container_name: str):
|
||||||
|
"""Enable container to start on boot."""
|
||||||
|
aug = _podman_augeus(container_name)
|
||||||
|
value = 'default.target'
|
||||||
|
key = 'Install/WantedBy'
|
||||||
|
found = any(
|
||||||
|
(aug.get(match_ + '/value') == value for match_ in aug.match(key)))
|
||||||
|
if not found:
|
||||||
|
aug.set(f'{key}[last() +1]/value', value)
|
||||||
|
aug.save()
|
||||||
|
|
||||||
|
|
||||||
|
def podman_disable(container_name: str):
|
||||||
|
"""Disable container to start on boot."""
|
||||||
|
aug = _podman_augeus(container_name)
|
||||||
|
aug.remove('Install/WantedBy')
|
||||||
|
aug.save()
|
||||||
|
|
||||||
|
|
||||||
def podman_uninstall(container_name: str, volume_name: str, image_name: str,
|
def podman_uninstall(container_name: str, volume_name: str, image_name: str,
|
||||||
volume_path: str):
|
volume_path: str):
|
||||||
"""Remove a podman container's components and systemd unit."""
|
"""Remove a podman container's components and systemd unit."""
|
||||||
|
|||||||
@ -105,7 +105,7 @@ class NextcloudApp(app_module.App):
|
|||||||
daemon = SharedDaemon('shared-daemon-nextcloud-mysql', 'mysql')
|
daemon = SharedDaemon('shared-daemon-nextcloud-mysql', 'mysql')
|
||||||
self.add(daemon)
|
self.add(daemon)
|
||||||
|
|
||||||
daemon = Daemon('daemon-nextcloud', 'nextcloud-freedombox')
|
daemon = NextcloudDaemon('daemon-nextcloud', 'nextcloud-freedombox')
|
||||||
self.add(daemon)
|
self.add(daemon)
|
||||||
|
|
||||||
daemon = Daemon('daemon-nextcloud-timer',
|
daemon = Daemon('daemon-nextcloud-timer',
|
||||||
@ -145,6 +145,24 @@ class NextcloudApp(app_module.App):
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
class NextcloudDaemon(Daemon):
|
||||||
|
"""Component to manage Nextcloud container service."""
|
||||||
|
|
||||||
|
def is_enabled(self):
|
||||||
|
"""Return if the daemon/unit is enabled."""
|
||||||
|
return privileged.is_enabled()
|
||||||
|
|
||||||
|
def enable(self):
|
||||||
|
"""Run operations to enable the daemon/unit."""
|
||||||
|
super().enable()
|
||||||
|
privileged.enable()
|
||||||
|
|
||||||
|
def disable(self):
|
||||||
|
"""Run operations to disable the daemon/unit."""
|
||||||
|
super().disable()
|
||||||
|
privileged.disable()
|
||||||
|
|
||||||
|
|
||||||
class NextcloudBackupRestore(BackupRestore):
|
class NextcloudBackupRestore(BackupRestore):
|
||||||
"""Component to backup/restore Nextcloud."""
|
"""Component to backup/restore Nextcloud."""
|
||||||
|
|
||||||
|
|||||||
@ -86,6 +86,24 @@ def _run_occ(*args, **kwargs) -> subprocess.CompletedProcess:
|
|||||||
return _run_in_container('/var/www/html/occ', *args, **kwargs)
|
return _run_in_container('/var/www/html/occ', *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@privileged
|
||||||
|
def is_enabled() -> bool:
|
||||||
|
"""Return if the systemd container service is enabled."""
|
||||||
|
return action_utils.podman_is_enabled(CONTAINER_NAME)
|
||||||
|
|
||||||
|
|
||||||
|
@privileged
|
||||||
|
def enable():
|
||||||
|
"""Enable the systemd container service."""
|
||||||
|
action_utils.podman_enable(CONTAINER_NAME)
|
||||||
|
|
||||||
|
|
||||||
|
@privileged
|
||||||
|
def disable():
|
||||||
|
"""Disable the systemd container service."""
|
||||||
|
action_utils.podman_disable(CONTAINER_NAME)
|
||||||
|
|
||||||
|
|
||||||
@privileged
|
@privileged
|
||||||
def get_domain():
|
def get_domain():
|
||||||
"""Return domain name set in Nextcloud."""
|
"""Return domain name set in Nextcloud."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user