mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-31 10:01:53 +08:00
don't remove sockets in kvmd.apps.cleanup
This commit is contained in:
@@ -20,7 +20,6 @@
|
|||||||
# ========================================================================== #
|
# ========================================================================== #
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
import signal
|
import signal
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@@ -56,20 +55,6 @@ def _kill_streamer(config: Section) -> None:
|
|||||||
logger.exception("Can't send SIGKILL to streamer with pid=%d", proc.pid)
|
logger.exception("Can't send SIGKILL to streamer with pid=%d", proc.pid)
|
||||||
|
|
||||||
|
|
||||||
def _remove_sockets(config: Section) -> None:
|
|
||||||
logger = get_logger(0)
|
|
||||||
for (owner, unix_path) in [
|
|
||||||
("KVMD", config.server.unix),
|
|
||||||
("streamer", config.streamer.unix),
|
|
||||||
]:
|
|
||||||
if unix_path and os.path.exists(unix_path):
|
|
||||||
logger.info("Removing %s socket %r ...", owner, unix_path)
|
|
||||||
try:
|
|
||||||
os.remove(unix_path)
|
|
||||||
except Exception: # pragma: nocover
|
|
||||||
logger.exception("Can't remove %s socket %r", owner, unix_path)
|
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
def main(argv: (list[str] | None)=None) -> None:
|
def main(argv: (list[str] | None)=None) -> None:
|
||||||
config = init(
|
config = init(
|
||||||
@@ -82,13 +67,9 @@ def main(argv: (list[str] | None)=None) -> None:
|
|||||||
logger = get_logger(0)
|
logger = get_logger(0)
|
||||||
logger.info("Cleaning up ...")
|
logger.info("Cleaning up ...")
|
||||||
|
|
||||||
for func in [
|
try:
|
||||||
_kill_streamer,
|
_kill_streamer(config)
|
||||||
_remove_sockets,
|
except Exception:
|
||||||
]:
|
pass
|
||||||
try:
|
|
||||||
func(config)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
logger.info("Bye-bye")
|
logger.info("Bye-bye")
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
# ========================================================================== #
|
# ========================================================================== #
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@@ -32,15 +31,10 @@ from kvmd.apps.cleanup import main
|
|||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
def test_ok(tmpdir) -> None: # type: ignore
|
def test_ok() -> None:
|
||||||
_ = Literal # Makes liters happy
|
_ = Literal # Makes liters happy
|
||||||
queue: "multiprocessing.Queue[Literal[True]]" = multiprocessing.Queue()
|
queue: "multiprocessing.Queue[Literal[True]]" = multiprocessing.Queue()
|
||||||
|
|
||||||
ustreamer_sock_path = os.path.abspath(str(tmpdir.join("ustreamer-fake.sock")))
|
|
||||||
open(ustreamer_sock_path, "w").close() # pylint: disable=consider-using-with
|
|
||||||
kvmd_sock_path = os.path.abspath(str(tmpdir.join("kvmd-fake.sock")))
|
|
||||||
open(kvmd_sock_path, "w").close() # pylint: disable=consider-using-with
|
|
||||||
|
|
||||||
def ustreamer_fake() -> None:
|
def ustreamer_fake() -> None:
|
||||||
setproctitle.setproctitle("kvmd/streamer: /usr/bin/ustreamer")
|
setproctitle.setproctitle("kvmd/streamer: /usr/bin/ustreamer")
|
||||||
queue.put(True)
|
queue.put(True)
|
||||||
@@ -52,16 +46,7 @@ def test_ok(tmpdir) -> None: # type: ignore
|
|||||||
assert queue.get(timeout=5)
|
assert queue.get(timeout=5)
|
||||||
|
|
||||||
assert proc.is_alive()
|
assert proc.is_alive()
|
||||||
main([
|
main(["kvmd-cleanup", "--run"])
|
||||||
"kvmd-cleanup",
|
|
||||||
"--set-options",
|
|
||||||
f"kvmd/server/unix={kvmd_sock_path}",
|
|
||||||
f"kvmd/streamer/unix={ustreamer_sock_path}",
|
|
||||||
"--run",
|
|
||||||
])
|
|
||||||
|
|
||||||
assert not os.path.exists(ustreamer_sock_path)
|
|
||||||
assert not os.path.exists(kvmd_sock_path)
|
|
||||||
|
|
||||||
assert not proc.is_alive()
|
assert not proc.is_alive()
|
||||||
proc.join()
|
proc.join()
|
||||||
|
|||||||
Reference in New Issue
Block a user