Skip to content

Commit

Permalink
Merge pull request #16 from plesk/fix-check-a-little
Browse files Browse the repository at this point in the history
Fix subprocess call arguments for getting required services
  • Loading branch information
SandakovMM authored Mar 19, 2024
2 parents 3fbca95 + 413bca1 commit 28ab45b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import typing
import subprocess

from . import dist, util
from . import dist, log, util

SYSTEMCTL_BIN_PATH = "/usr/bin/systemctl"
if dist._is_deb_based(dist.get_distro()):
Expand All @@ -25,11 +25,16 @@ def is_service_active(service: str):


def get_required_services(service: str) -> typing.List[str]:
res = subprocess.run([SYSTEMCTL_BIN_PATH, 'cat', service], capture_output=True, text=True)
output = res.stdout.strip()
res = subprocess.run(
[SYSTEMCTL_BIN_PATH, 'cat', service],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=True,
universal_newlines=True
)

required_services = []
for line in output.split('\n'):
for line in res.stdout.splitlines():
if line.startswith('Requires='):
required_services = line.split('s=')[1].split()
break
Expand All @@ -43,6 +48,7 @@ def is_service_can_be_started(service: str) -> bool:
required_services = get_required_services(service)
for required_service in required_services:
if not is_service_exists(required_service):
log.debug("Service '{}' can't be started because required service '{}' doesn't exist".format(service, required_service))
return False
return True

Expand Down

0 comments on commit 28ab45b

Please sign in to comment.