feat(dbus): Add dphys-swapfile configuration functionality
Implemented `configure_dphys_swapfile` to manage the dphys-swapfile service, including automatic swapfile removal when the service is disabled. Updated feature registry to support dphys-swapfile configuration.
This commit is contained in:
@@ -5,7 +5,13 @@
|
||||
from collections import namedtuple
|
||||
from logging import getLogger
|
||||
|
||||
from .revpi_config import ConfigActions, configure_avahi_daemon, configure_gui, simple_systemd
|
||||
from .revpi_config import (
|
||||
ConfigActions,
|
||||
configure_avahi_daemon,
|
||||
configure_dphys_swapfile,
|
||||
configure_gui,
|
||||
simple_systemd,
|
||||
)
|
||||
from ..dbus_helper import DbusInterface
|
||||
|
||||
log = getLogger(__name__)
|
||||
@@ -73,7 +79,7 @@ def get_feature(feature: str) -> FeatureFunction:
|
||||
AVAILABLE_FEATURES = {
|
||||
"gui": FeatureFunction(configure_gui, []),
|
||||
"revpi-con-can": False,
|
||||
"dphys-swapfile": False,
|
||||
"dphys-swapfile": FeatureFunction(configure_dphys_swapfile, []),
|
||||
"pimodbus-master": FeatureFunction(simple_systemd, ["pimodbus-master.service"]),
|
||||
"pimodbus-slave": FeatureFunction(simple_systemd, ["pimodbus-slave.service"]),
|
||||
"systemd-timesyncd": FeatureFunction(simple_systemd, ["systemd-timesyncd.service"]),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# SPDX-FileCopyrightText: 2025 KUNBUS GmbH
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
import subprocess
|
||||
from enum import Enum, IntEnum
|
||||
from logging import getLogger
|
||||
from os import X_OK, access
|
||||
@@ -105,6 +106,21 @@ def configure_avahi_daemon(action: ConfigActions):
|
||||
return return_value
|
||||
|
||||
|
||||
def configure_dphys_swapfile(action: ConfigActions):
|
||||
return_value = simple_systemd(action, "dphys-swapfile.service")
|
||||
|
||||
# Post actions for dphys-swapfile
|
||||
if action is ConfigActions.DISABLE:
|
||||
# Remove swapfile afer disabling the service unit
|
||||
subprocess.call(
|
||||
["/sbin/dphys-swapfile", "uninstall"],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
|
||||
return return_value
|
||||
|
||||
|
||||
def configure_gui(action: ConfigActions):
|
||||
gui_available = access("/usr/bin/startx", X_OK)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user