diff options
Diffstat (limited to 'backend/helpers.py')
| -rw-r--r-- | backend/helpers.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/backend/helpers.py b/backend/helpers.py index 8d329560..5e26f163 100644 --- a/backend/helpers.py +++ b/backend/helpers.py @@ -2,11 +2,15 @@ import certifi import ssl import uuid import re +import subprocess from aiohttp.web import middleware, Response from subprocess import check_output from time import sleep + +REMOTE_DEBUGGER_UNIT = "steam-web-debug-portforward.service" + # global vars csrf_token = str(uuid.uuid4()) ssl_ctx = ssl.create_default_context(cafile=certifi.where()) @@ -63,3 +67,17 @@ def get_user_group() -> str: if group == None: raise ValueError("helpers.get_user_group method called before group variable was set. Run helpers.set_user_group first.") return group + +async def is_systemd_unit_active(unit_name: str) -> bool: + res = subprocess.run(["systemctl", "is-active", unit_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + return res.returncode == 0 + +async def stop_systemd_unit(unit_name: str) -> subprocess.CompletedProcess: + cmd = ["systemctl", "stop", unit_name] + + return subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + +async def start_systemd_unit(unit_name: str) -> subprocess.CompletedProcess: + cmd = ["systemctl", "start", unit_name] + + return subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
