actions/service: Drop use of managed_services for Daemon component

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2021-11-16 14:43:19 -08:00 committed by James Valleroy
parent 1c2a5f0825
commit ba4b58de78
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -6,9 +6,10 @@ Wrapper to list and handle system services
import argparse import argparse
import os import os
from importlib import import_module
from plinth import action_utils, cfg from plinth import action_utils, cfg, module_loader
from plinth.app import App
from plinth.daemon import Daemon, RelatedDaemon
cfg.read() cfg.read()
module_config_path = os.path.join(cfg.config_dir, 'modules-enabled') module_config_path = os.path.join(cfg.config_dir, 'modules-enabled')
@ -85,34 +86,21 @@ def subcommand_is_running(arguments):
print(action_utils.service_is_running(arguments.service)) print(action_utils.service_is_running(arguments.service))
def _get_managed_services_of_module(modulepath):
"""Import a module and return content of its 'managed_services' variable"""
try:
module = import_module(modulepath)
except ImportError:
return []
else:
return getattr(module, 'managed_services', [])
def _get_managed_services(): def _get_managed_services():
""" """Get a set of all services managed by FreedomBox."""
Get a set of all services managed by FreedomBox.
This collects all service-names inside the 'managed_services' variable of
modules inside 'module_config_path'
"""
services = set() services = set()
for filename in os.listdir(module_config_path): module_loader.load_modules()
# Omit hidden files module_loader.apps_init()
if filename.startswith('.'): for app in App.list():
continue components = app.get_components_of_type(Daemon)
for component in components:
services.add(component.unit)
if component.alias:
services.add(component.alias)
filepath = os.path.join(module_config_path, filename) components = app.get_components_of_type(RelatedDaemon)
if os.path.isfile(filepath): for component in components:
with open(filepath, 'r') as f: services.add(component.unit)
modulepath = f.read().strip()
services.update(_get_managed_services_of_module(modulepath))
return services return services