mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
use process_name_prefix to kill ustreamer
This commit is contained in:
parent
74449c81ad
commit
35a40614e5
@ -72,12 +72,13 @@ def _clear_gpio(config: Section) -> None:
|
|||||||
def _kill_streamer(config: Section) -> None:
|
def _kill_streamer(config: Section) -> None:
|
||||||
logger = get_logger(0)
|
logger = get_logger(0)
|
||||||
|
|
||||||
streamer = os.path.basename(config.streamer.cmd[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>")
|
||||||
|
|
||||||
logger.info("Trying to find and kill %r ...", streamer)
|
|
||||||
for proc in psutil.process_iter():
|
for proc in psutil.process_iter():
|
||||||
attrs = proc.as_dict(attrs=["name"])
|
attrs = proc.as_dict(attrs=["name"])
|
||||||
if os.path.basename(attrs.get("name", "")) == streamer:
|
if attrs.get("name", "").startswith(prefix):
|
||||||
try:
|
try:
|
||||||
proc.send_signal(signal.SIGTERM)
|
proc.send_signal(signal.SIGTERM)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import secrets
|
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import multiprocessing.queues
|
import multiprocessing.queues
|
||||||
import time
|
import time
|
||||||
@ -35,16 +34,13 @@ from kvmd.apps.cleanup import main
|
|||||||
def test_ok(tmpdir) -> None: # type: ignore
|
def test_ok(tmpdir) -> None: # type: ignore
|
||||||
queue: multiprocessing.queues.Queue = multiprocessing.Queue()
|
queue: multiprocessing.queues.Queue = multiprocessing.Queue()
|
||||||
|
|
||||||
ustreamer_tmp_path = os.path.abspath(str(tmpdir.join("ustr-" + secrets.token_hex(3))))
|
|
||||||
os.symlink("/usr/bin/ustreamer", ustreamer_tmp_path)
|
|
||||||
|
|
||||||
ustreamer_sock_path = os.path.abspath(str(tmpdir.join("ustreamer-fake.sock")))
|
ustreamer_sock_path = os.path.abspath(str(tmpdir.join("ustreamer-fake.sock")))
|
||||||
open(ustreamer_sock_path, "w").close()
|
open(ustreamer_sock_path, "w").close()
|
||||||
kvmd_sock_path = os.path.abspath(str(tmpdir.join("kvmd-fake.sock")))
|
kvmd_sock_path = os.path.abspath(str(tmpdir.join("kvmd-fake.sock")))
|
||||||
open(kvmd_sock_path, "w").close()
|
open(kvmd_sock_path, "w").close()
|
||||||
|
|
||||||
def ustreamer_fake() -> None:
|
def ustreamer_fake() -> None:
|
||||||
setproctitle.setproctitle(os.path.basename(ustreamer_tmp_path))
|
setproctitle.setproctitle("kvmd/streamer: /usr/bin/ustreamer")
|
||||||
queue.put(True)
|
queue.put(True)
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
@ -57,11 +53,8 @@ def test_ok(tmpdir) -> None: # type: ignore
|
|||||||
main([
|
main([
|
||||||
"kvmd-cleanup",
|
"kvmd-cleanup",
|
||||||
"--set-options",
|
"--set-options",
|
||||||
"kvmd/server/port=0",
|
f"kvmd/server/unix={kvmd_sock_path}",
|
||||||
"kvmd/server/unix=" + kvmd_sock_path,
|
f"kvmd/streamer/unix={ustreamer_sock_path}",
|
||||||
"kvmd/streamer/port=0",
|
|
||||||
"kvmd/streamer/unix=" + ustreamer_sock_path,
|
|
||||||
"kvmd/streamer/cmd=" + ustreamer_tmp_path,
|
|
||||||
])
|
])
|
||||||
|
|
||||||
assert not os.path.exists(ustreamer_sock_path)
|
assert not os.path.exists(ustreamer_sock_path)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user