From 29fcc4bf0ee0a706a016a75e0d47b8f20e4d820f Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Wed, 13 Sep 2023 13:38:52 +0200 Subject: [PATCH] Check if Linux service is running before trying to start or stop it this prevents needless prompts opening up --- backend/localplatformlinux.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/localplatformlinux.py b/backend/localplatformlinux.py index 811db8a62..c85cbcf2a 100644 --- a/backend/localplatformlinux.py +++ b/backend/localplatformlinux.py @@ -129,11 +129,19 @@ async def service_restart(service_name : str) -> bool: return res.returncode == 0 async def service_stop(service_name : str) -> bool: + if not await service_active(service_name): + # Service isn't running. pretend we stopped it + return True + cmd = ["systemctl", "stop", service_name] res = run(cmd, stdout=PIPE, stderr=STDOUT) return res.returncode == 0 async def service_start(service_name : str) -> bool: + if await service_active(service_name): + # Service is running. pretend we started it + return True + cmd = ["systemctl", "start", service_name] res = run(cmd, stdout=PIPE, stderr=STDOUT) return res.returncode == 0