summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2024-07-08 04:53:24 +0300
committerMaxim Devaev <[email protected]>2024-07-19 15:25:14 +0300
commit44e58d8d062bee501fa3016c6464987d741d661f (patch)
tree40faf79254e3cf54412c345a41a1785c8fb23a16
parentca639f6be8c3cf99019215f470b0185a5549b5df (diff)
Removed kvmd-cleanup
Systemd kills all orphaned children when using KillMode=mixed
-rw-r--r--configs/os/services/kvmd.service1
-rw-r--r--kvmd/apps/cleanup/__init__.py75
-rw-r--r--kvmd/apps/cleanup/__main__.py24
-rwxr-xr-xsetup.py2
-rw-r--r--testenv/tests/apps/cleanup/__init__.py20
-rw-r--r--testenv/tests/apps/cleanup/test_main.py52
6 files changed, 0 insertions, 174 deletions
diff --git a/configs/os/services/kvmd.service b/configs/os/services/kvmd.service
index 56092f59..1f4d6550 100644
--- a/configs/os/services/kvmd.service
+++ b/configs/os/services/kvmd.service
@@ -11,7 +11,6 @@ RestartSec=3
AmbientCapabilities=CAP_NET_RAW
ExecStart=/usr/bin/kvmd --run
-ExecStopPost=/usr/bin/kvmd-cleanup --run
TimeoutStopSec=10
KillMode=mixed
diff --git a/kvmd/apps/cleanup/__init__.py b/kvmd/apps/cleanup/__init__.py
deleted file mode 100644
index 9f729ef1..00000000
--- a/kvmd/apps/cleanup/__init__.py
+++ /dev/null
@@ -1,75 +0,0 @@
-# ========================================================================== #
-# #
-# KVMD - The main PiKVM daemon. #
-# #
-# Copyright (C) 2018-2024 Maxim Devaev <[email protected]> #
-# #
-# This program is free software: you can redistribute it and/or modify #
-# it under the terms of the GNU General Public License as published by #
-# the Free Software Foundation, either version 3 of the License, or #
-# (at your option) any later version. #
-# #
-# This program is distributed in the hope that it will be useful, #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
-# GNU General Public License for more details. #
-# #
-# You should have received a copy of the GNU General Public License #
-# along with this program. If not, see <https://www.gnu.org/licenses/>. #
-# #
-# ========================================================================== #
-
-
-import signal
-import time
-
-import psutil
-
-from ...logging import get_logger
-
-from ...yamlconf import Section
-
-from .. import init
-
-
-# =====
-def _kill_streamer(config: Section) -> None:
- logger = get_logger(0)
-
- if config.streamer.process_name_prefix:
- prefix = config.streamer.process_name_prefix + ":"
- logger.info("Trying to find and kill the streamer %r ...", prefix + " <app>")
-
- for proc in psutil.process_iter():
- attrs = proc.as_dict(attrs=["name"])
- if attrs.get("name", "").startswith(prefix):
- try:
- proc.send_signal(signal.SIGTERM)
- except Exception:
- logger.exception("Can't send SIGTERM to streamer with pid=%d", proc.pid)
- time.sleep(3)
- if proc.is_running():
- try:
- proc.send_signal(signal.SIGKILL)
- except Exception:
- logger.exception("Can't send SIGKILL to streamer with pid=%d", proc.pid)
-
-
-# =====
-def main(argv: (list[str] | None)=None) -> None:
- config = init(
- prog="kvmd-cleanup",
- description="Kill KVMD and clear resources",
- check_run=True,
- argv=argv,
- )[2].kvmd
-
- logger = get_logger(0)
- logger.info("Cleaning up ...")
-
- try:
- _kill_streamer(config)
- except Exception:
- pass
-
- logger.info("Bye-bye")
diff --git a/kvmd/apps/cleanup/__main__.py b/kvmd/apps/cleanup/__main__.py
deleted file mode 100644
index 4827fc49..00000000
--- a/kvmd/apps/cleanup/__main__.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# ========================================================================== #
-# #
-# KVMD - The main PiKVM daemon. #
-# #
-# Copyright (C) 2018-2024 Maxim Devaev <[email protected]> #
-# #
-# This program is free software: you can redistribute it and/or modify #
-# it under the terms of the GNU General Public License as published by #
-# the Free Software Foundation, either version 3 of the License, or #
-# (at your option) any later version. #
-# #
-# This program is distributed in the hope that it will be useful, #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
-# GNU General Public License for more details. #
-# #
-# You should have received a copy of the GNU General Public License #
-# along with this program. If not, see <https://www.gnu.org/licenses/>. #
-# #
-# ========================================================================== #
-
-
-from . import main
-main()
diff --git a/setup.py b/setup.py
index 07214132..062a5d8d 100755
--- a/setup.py
+++ b/setup.py
@@ -95,7 +95,6 @@ def main() -> None:
"kvmd.apps.htpasswd",
"kvmd.apps.totp",
"kvmd.apps.edidconf",
- "kvmd.apps.cleanup",
"kvmd.apps.ipmi",
"kvmd.apps.vnc",
"kvmd.apps.vnc.rfb",
@@ -123,7 +122,6 @@ def main() -> None:
"kvmd-htpasswd = kvmd.apps.htpasswd:main",
"kvmd-totp = kvmd.apps.totp:main",
"kvmd-edidconf = kvmd.apps.edidconf:main",
- "kvmd-cleanup = kvmd.apps.cleanup:main",
"kvmd-ipmi = kvmd.apps.ipmi:main",
"kvmd-vnc = kvmd.apps.vnc:main",
"kvmd-nginx-mkconf = kvmd.apps.ngxmkconf:main",
diff --git a/testenv/tests/apps/cleanup/__init__.py b/testenv/tests/apps/cleanup/__init__.py
deleted file mode 100644
index 8d45fdfd..00000000
--- a/testenv/tests/apps/cleanup/__init__.py
+++ /dev/null
@@ -1,20 +0,0 @@
-# ========================================================================== #
-# #
-# KVMD - The main PiKVM daemon. #
-# #
-# Copyright (C) 2018-2024 Maxim Devaev <[email protected]> #
-# #
-# This program is free software: you can redistribute it and/or modify #
-# it under the terms of the GNU General Public License as published by #
-# the Free Software Foundation, either version 3 of the License, or #
-# (at your option) any later version. #
-# #
-# This program is distributed in the hope that it will be useful, #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
-# GNU General Public License for more details. #
-# #
-# You should have received a copy of the GNU General Public License #
-# along with this program. If not, see <https://www.gnu.org/licenses/>. #
-# #
-# ========================================================================== #
diff --git a/testenv/tests/apps/cleanup/test_main.py b/testenv/tests/apps/cleanup/test_main.py
deleted file mode 100644
index 1901b6d4..00000000
--- a/testenv/tests/apps/cleanup/test_main.py
+++ /dev/null
@@ -1,52 +0,0 @@
-# ========================================================================== #
-# #
-# KVMD - The main PiKVM daemon. #
-# #
-# Copyright (C) 2018-2024 Maxim Devaev <[email protected]> #
-# #
-# This program is free software: you can redistribute it and/or modify #
-# it under the terms of the GNU General Public License as published by #
-# the Free Software Foundation, either version 3 of the License, or #
-# (at your option) any later version. #
-# #
-# This program is distributed in the hope that it will be useful, #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
-# GNU General Public License for more details. #
-# #
-# You should have received a copy of the GNU General Public License #
-# along with this program. If not, see <https://www.gnu.org/licenses/>. #
-# #
-# ========================================================================== #
-
-
-import multiprocessing
-import time
-
-from typing import Literal
-
-import setproctitle
-
-from kvmd.apps.cleanup import main
-
-
-# =====
-def test_ok() -> None:
- _ = Literal # Makes liters happy
- queue: "multiprocessing.Queue[Literal[True]]" = multiprocessing.Queue()
-
- def ustreamer_fake() -> None:
- setproctitle.setproctitle("kvmd/streamer: /usr/bin/ustreamer")
- queue.put(True)
- while True:
- time.sleep(1)
-
- proc = multiprocessing.Process(target=ustreamer_fake, daemon=True)
- proc.start()
- assert queue.get(timeout=5)
-
- assert proc.is_alive()
- main(["kvmd-cleanup", "--run"])
-
- assert not proc.is_alive()
- proc.join()