Skip to content

Commit

Permalink
add support for openrc
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjelinek committed Apr 8, 2022
1 parent 50b5eef commit 73c7da3
Show file tree
Hide file tree
Showing 9 changed files with 388 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Add warning regarding move constraints to `pcs status` ([rhbz#2058247])
- Support for output formats `json` and `cmd` to `pcs resource config` and `pcs
stonith config` commands ([rhbz#2058251], [rhbz#2058252])
- Support systems with OpenRC init system ([ghissue#266])

### Fixed
- Booth ticket name validation ([rhbz#2053177])
Expand All @@ -24,6 +25,7 @@
- Preventing fence-loop caused when stonith-watchdog-timeout is set
with wrong value ([rhbz#2058246])

[ghissue#266]: https://github.com/ClusterLabs/pcs/issues/266
[rhbz#2024522]: https://bugzilla.redhat.com/show_bug.cgi?id=2024522
[rhbz#2053177]: https://bugzilla.redhat.com/show_bug.cgi?id=2053177
[rhbz#2054671]: https://bugzilla.redhat.com/show_bug.cgi?id=2054671
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ if test "x$SYSTEMCTL" = "x"; then
AC_MSG_ERROR([Unable to find systemctl or service in $PATH])
fi
fi
AC_PATH_PROG([RC_CONFIG], [rc-config])
AC_PATH_PROG([RC_SERVICE], [rc-service])

if test "x$tests_only" != "xyes"; then
AC_PATH_PROG([KILLALL], [killall])
Expand Down
1 change: 1 addition & 0 deletions pcs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ EXTRA_DIST = \
common/resource_agent/dto.py \
common/services/common.py \
common/services/drivers/__init__.py \
common/services/drivers/openrc.py \
common/services/drivers/systemd.py \
common/services/drivers/sysvinit_rhel.py \
common/services_dto.py \
Expand Down
1 change: 1 addition & 0 deletions pcs/common/services/drivers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .openrc import OpenRcDriver
from .systemd import SystemdDriver
from .sysvinit_rhel import SysVInitRhelDriver
97 changes: 97 additions & 0 deletions pcs/common/services/drivers/openrc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import os.path
from typing import (
List,
Optional,
)

from .. import errors
from ..interfaces import (
ExecutorInterface,
ServiceManagerInterface,
)


class OpenRcDriver(ServiceManagerInterface):
def __init__(
self,
executor: ExecutorInterface,
rc_service_bin: str,
rc_config_bin: str,
):
"""
executor -- external commands used by this class are executed using
this object
rc_service_bin -- path to an executable used for starting and stopping
services and to check if a service is running
rc_config_bin -- path to an executable used for enabling, disabling and
listing available service and to check if service is enabled
"""
self._executor = executor
self._rc_service_bin = rc_service_bin
self._rc_config_bin = rc_config_bin
self._available_services: List[str] = []

def start(self, service: str, instance: Optional[str] = None) -> None:
result = self._executor.run([self._rc_service_bin, service, "start"])
if result.retval != 0:
raise errors.StartServiceError(service, result.joined_output)

def stop(self, service: str, instance: Optional[str] = None) -> None:
result = self._executor.run([self._rc_service_bin, service, "stop"])
if result.retval != 0:
raise errors.StopServiceError(service, result.joined_output)

def enable(self, service: str, instance: Optional[str] = None) -> None:
result = self._executor.run(
[self._rc_config_bin, "add", service, "default"]
)
if result.retval != 0:
raise errors.EnableServiceError(service, result.joined_output)

def disable(self, service: str, instance: Optional[str] = None) -> None:
if not self.is_installed(service):
return
result = self._executor.run(
[self._rc_config_bin, "delete", service, "default"]
)
if result.retval != 0:
raise errors.DisableServiceError(service, result.joined_output)

def is_enabled(self, service: str, instance: Optional[str] = None) -> bool:
result = self._executor.run([self._rc_config_bin, "list", "default"])
for line in result.stdout.splitlines()[1:]:
if service == line.strip():
return True
return False

def is_running(self, service: str, instance: Optional[str] = None) -> bool:
return (
self._executor.run([self._rc_service_bin, service, "status"]).retval
== 0
)

def is_installed(self, service: str) -> bool:
return service in self.get_available_services()

def get_available_services(self) -> List[str]:
if not self._available_services:
self._available_services = self._get_available_services()
return self._available_services

def _get_available_services(self) -> List[str]:
result = self._executor.run([self._rc_config_bin, "list"])
if result.retval != 0:
return []

service_list = []
for service in result.stdout.splitlines()[1:]:
service = service.strip().split(" ")[0]
if service:
service_list.append(service)
return service_list

def is_current_system_supported(self) -> bool:
return all(
os.path.isfile(binary)
for binary in (self._rc_service_bin, self._rc_config_bin)
)
3 changes: 3 additions & 0 deletions pcs/lib/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def get_service_manager(
services.drivers.SystemdDriver(
executor, settings.systemctl_binary, settings.systemd_unit_path
),
services.drivers.OpenRcDriver(
executor, settings.rc_service_binary, settings.rc_config_binary
),
services.drivers.SysVInitRhelDriver(
executor, settings.service_binary, settings.chkconfig_binary
),
Expand Down
4 changes: 4 additions & 0 deletions pcs/settings.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ systemctl_binary = "@SYSTEMCTL@"
systemd_unit_path = "@SYSTEMD_UNIT_PATH@".split(":")
chkconfig_binary = "/sbin/chkconfig"
service_binary = "@SERVICE@"
rc_config_binary = "@RC_CONFIG@"
rc_service_binary = "@RC_SERVICE@"
# Used only in utils.py in deprecated funcion
pacemaker_binaries = "@PCMKEXECPREFIX@/sbin"
corosync_binaries = "@COROEXECPREFIX@/sbin"
Expand Down Expand Up @@ -118,6 +120,7 @@ pcs_data_dir = "@LIB_DIR@/pcs/data/"
_ocf_1_0_schema_filename = "ocf-1.0.rng"
_ocf_1_1_schema_filename = "ocf-1.1.rng"


class _PathManager:
@property
def ocf_1_0_schema(self):
Expand All @@ -131,4 +134,5 @@ class _PathManager:
def pcs_data_dir(self):
return pcs_data_dir


path = _PathManager()
1 change: 1 addition & 0 deletions pcs_test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ EXTRA_DIST = \
tier0/common/reports/test_item.py \
tier0/common/reports/test_messages.py \
tier0/common/services/drivers/__init__.py \
tier0/common/services/drivers/test_openrc.py \
tier0/common/services/drivers/test_systemd.py \
tier0/common/services/drivers/test_sysvinit_rhel.py \
tier0/common/services/__init__.py \
Expand Down
Loading

0 comments on commit 73c7da3

Please sign in to comment.