新增 doctor 诊断自救功能

This commit is contained in:
jxxghp
2026-06-12 15:55:24 +08:00
parent 10dcb3727e
commit 735a1ebf27
23 changed files with 1635 additions and 56 deletions

View File

@@ -1,7 +1,10 @@
import subprocess
import tempfile
from unittest import TestCase
from unittest.mock import patch
from app.helper.system import SystemHelper
from app.core.config import settings
from app.utils.system import SystemUtils
@@ -42,3 +45,32 @@ class SystemUtilsTest(TestCase):
self.assertFalse(success)
self.assertIn("返回码2", message)
self.assertIn("无标准输出或错误输出", message)
class SystemHelperRestartTest(TestCase):
def test_docker_restart_policy_marks_intent_before_sigterm(self):
"""
Docker 内置重启走优雅退出时,应写入意图标记,避免 entrypoint 误进入 doctor 保活。
"""
with tempfile.TemporaryDirectory() as temp_dir:
original_config_dir = settings.CONFIG_DIR
original_intent_file = SystemHelper._SystemHelper__docker_restart_intent_file
settings.CONFIG_DIR = temp_dir
SystemHelper._SystemHelper__docker_restart_intent_file = (
settings.TEMP_PATH / "moviepilot.intentional_restart"
)
try:
with patch("app.helper.system.SystemUtils.is_docker", return_value=True), \
patch.object(SystemHelper, "_check_restart_policy", return_value=True), \
patch.object(SystemHelper, "_start_graceful_shutdown_monitor"), \
patch("app.helper.system.os.kill") as kill_mock:
ret, msg = SystemHelper.restart()
self.assertTrue(ret)
self.assertEqual(msg, "")
self.assertTrue((settings.TEMP_PATH / "moviepilot.intentional_restart").exists())
kill_mock.assert_called_once()
finally:
SystemHelper._SystemHelper__docker_restart_intent_file = original_intent_file
settings.CONFIG_DIR = original_config_dir