mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-02-04 08:13:38 +00:00
- This will leave /etc/{plinth,freedombox} empty by default making service more
robust to run across various environments and situations. See systemd's
explanation for more details.
- Use Debian maintainer scripts remove all the existing files in
/etc/plinth/modules-enabled.
- Read from /usr/share/freedombox/modules-enabled then from
/etc/plinth/modules-enabled and finally from /etc/freedombox/modules-enabled.
Later read ones override previously read files. Any file pointing to /dev/null
will mean the module must be ignored.
Tests:
- Clean up /etc/plinth, /etc/freedombox and
/usr/share/freedombox/modules-enabled. Run service and notice that files are
getting loaded from development folder using a debug message.
- Run setup.py and notice that files get installed in
/usr/share/freedombox/modules-enabled/ and in the next run they get loaded from
there.
- Create a override file in /etc/plinth/modules-enabled/transmission and notice
that overriden file gets priority over the one in
/usr/share/freedombox/modules-enabled.
- Link the file /etc/plinth/modules-enabled/transmission to /dev/null and notice
that is not loaded.
- Create another file in /etc/freedombox/modules-enabled/transmission and notice
that it overrides the previous two files.
- All affected modules are loaded.
- Build a new Debian package and ensure that upgrading 23.8 to new version
removes are all configuration files.
- Build developer documentation and test that Tutorial -> Full Code and Tutorial
-> Skeleton sections have been updated with references to
-.../modules-enabled/... paths.
- Install quassel and notice that certificates were copied to /var/lib/quassel
directory. Change domain to another domain and notice that certificates were
copied again to that directory.
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
114 lines
3.1 KiB
Python
114 lines
3.1 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""List and handle system services."""
|
|
|
|
from plinth import action_utils
|
|
from plinth import app as app_module
|
|
from plinth import module_loader
|
|
from plinth.actions import privileged
|
|
from plinth.daemon import Daemon, RelatedDaemon
|
|
|
|
|
|
@privileged
|
|
def start(service: str):
|
|
"""Start a service."""
|
|
_assert_service_is_managed_by_plinth(service)
|
|
action_utils.service_start(service)
|
|
|
|
|
|
@privileged
|
|
def stop(service: str):
|
|
"""Stop a running service."""
|
|
_assert_service_is_managed_by_plinth(service)
|
|
action_utils.service_stop(service)
|
|
|
|
|
|
@privileged
|
|
def enable(service: str):
|
|
"""Enable a service so that it start on system boot."""
|
|
_assert_service_is_managed_by_plinth(service)
|
|
action_utils.service_enable(service)
|
|
|
|
|
|
@privileged
|
|
def disable(service: str):
|
|
"""Disable a service so that it does not start on system boot."""
|
|
_assert_service_is_managed_by_plinth(service)
|
|
action_utils.service_disable(service)
|
|
|
|
|
|
@privileged
|
|
def restart(service: str):
|
|
"""Restart a service."""
|
|
_assert_service_is_managed_by_plinth(service)
|
|
action_utils.service_restart(service)
|
|
|
|
|
|
@privileged
|
|
def try_restart(service: str):
|
|
"""Restart a service if it is running."""
|
|
_assert_service_is_managed_by_plinth(service)
|
|
action_utils.service_try_restart(service)
|
|
|
|
|
|
@privileged
|
|
def reload(service: str):
|
|
"""Reload a service."""
|
|
_assert_service_is_managed_by_plinth(service)
|
|
action_utils.service_reload(service)
|
|
|
|
|
|
@privileged
|
|
def mask(service: str):
|
|
"""Mask a service."""
|
|
_assert_service_is_managed_by_plinth(service)
|
|
action_utils.service_mask(service)
|
|
|
|
|
|
@privileged
|
|
def unmask(service: str):
|
|
"""Unmask a service."""
|
|
_assert_service_is_managed_by_plinth(service)
|
|
action_utils.service_unmask(service)
|
|
|
|
|
|
@privileged
|
|
def is_enabled(service: str) -> bool:
|
|
"""Return whether a service is enabled."""
|
|
_assert_service_is_managed_by_plinth(service)
|
|
return action_utils.service_is_enabled(service)
|
|
|
|
|
|
@privileged
|
|
def is_running(service: str) -> bool:
|
|
"""Return whether a service is running."""
|
|
_assert_service_is_managed_by_plinth(service)
|
|
return action_utils.service_is_running(service)
|
|
|
|
|
|
def _get_managed_services():
|
|
"""Get a set of all services managed by FreedomBox."""
|
|
services = set()
|
|
module_loader.load_modules()
|
|
app_module.apps_init()
|
|
for app in app_module.App.list():
|
|
components = app.get_components_of_type(Daemon)
|
|
for component in components:
|
|
services.add(component.unit)
|
|
if component.alias:
|
|
services.add(component.alias)
|
|
|
|
components = app.get_components_of_type(RelatedDaemon)
|
|
for component in components:
|
|
services.add(component.unit)
|
|
|
|
return services
|
|
|
|
|
|
def _assert_service_is_managed_by_plinth(service_name):
|
|
managed_services = _get_managed_services()
|
|
if service_name not in managed_services:
|
|
msg = ("The service '%s' is not managed by FreedomBox. Access is only "
|
|
"permitted for services listed in the Daemon and RelatedDaemon "
|
|
"components of any FreedomBox app.") % service_name
|
|
raise ValueError(msg)
|