mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
Removed kvmd-cleanup
Systemd kills all orphaned children when using KillMode=mixed
This commit is contained in:
parent
ca639f6be8
commit
44e58d8d06
@ -11,7 +11,6 @@ RestartSec=3
|
|||||||
AmbientCapabilities=CAP_NET_RAW
|
AmbientCapabilities=CAP_NET_RAW
|
||||||
|
|
||||||
ExecStart=/usr/bin/kvmd --run
|
ExecStart=/usr/bin/kvmd --run
|
||||||
ExecStopPost=/usr/bin/kvmd-cleanup --run
|
|
||||||
TimeoutStopSec=10
|
TimeoutStopSec=10
|
||||||
KillMode=mixed
|
KillMode=mixed
|
||||||
|
|
||||||
|
|||||||
@ -1,75 +0,0 @@
|
|||||||
# ========================================================================== #
|
|
||||||
# #
|
|
||||||
# KVMD - The main PiKVM daemon. #
|
|
||||||
# #
|
|
||||||
# Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
|
|
||||||
# #
|
|
||||||
# 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")
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
# ========================================================================== #
|
|
||||||
# #
|
|
||||||
# KVMD - The main PiKVM daemon. #
|
|
||||||
# #
|
|
||||||
# Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
|
|
||||||
# #
|
|
||||||
# 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()
|
|
||||||
2
setup.py
2
setup.py
@ -95,7 +95,6 @@ def main() -> None:
|
|||||||
"kvmd.apps.htpasswd",
|
"kvmd.apps.htpasswd",
|
||||||
"kvmd.apps.totp",
|
"kvmd.apps.totp",
|
||||||
"kvmd.apps.edidconf",
|
"kvmd.apps.edidconf",
|
||||||
"kvmd.apps.cleanup",
|
|
||||||
"kvmd.apps.ipmi",
|
"kvmd.apps.ipmi",
|
||||||
"kvmd.apps.vnc",
|
"kvmd.apps.vnc",
|
||||||
"kvmd.apps.vnc.rfb",
|
"kvmd.apps.vnc.rfb",
|
||||||
@ -123,7 +122,6 @@ def main() -> None:
|
|||||||
"kvmd-htpasswd = kvmd.apps.htpasswd:main",
|
"kvmd-htpasswd = kvmd.apps.htpasswd:main",
|
||||||
"kvmd-totp = kvmd.apps.totp:main",
|
"kvmd-totp = kvmd.apps.totp:main",
|
||||||
"kvmd-edidconf = kvmd.apps.edidconf:main",
|
"kvmd-edidconf = kvmd.apps.edidconf:main",
|
||||||
"kvmd-cleanup = kvmd.apps.cleanup:main",
|
|
||||||
"kvmd-ipmi = kvmd.apps.ipmi:main",
|
"kvmd-ipmi = kvmd.apps.ipmi:main",
|
||||||
"kvmd-vnc = kvmd.apps.vnc:main",
|
"kvmd-vnc = kvmd.apps.vnc:main",
|
||||||
"kvmd-nginx-mkconf = kvmd.apps.ngxmkconf:main",
|
"kvmd-nginx-mkconf = kvmd.apps.ngxmkconf:main",
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
# ========================================================================== #
|
|
||||||
# #
|
|
||||||
# KVMD - The main PiKVM daemon. #
|
|
||||||
# #
|
|
||||||
# Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
|
|
||||||
# #
|
|
||||||
# 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/>. #
|
|
||||||
# #
|
|
||||||
# ========================================================================== #
|
|
||||||
@ -1,52 +0,0 @@
|
|||||||
# ========================================================================== #
|
|
||||||
# #
|
|
||||||
# KVMD - The main PiKVM daemon. #
|
|
||||||
# #
|
|
||||||
# Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
|
|
||||||
# #
|
|
||||||
# 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()
|
|
||||||
Loading…
x
Reference in New Issue
Block a user