From 20319f48d57267076285a2c33d78c53436625d9e Mon Sep 17 00:00:00 2001 From: root Date: Wed, 29 Apr 2026 11:33:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20SSL=20=E4=BF=9D=E5=AD=98=E5=90=8E?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=80=80=E5=87=BA=E8=BF=9B=E7=A8=8B=EF=BC=8C?= =?UTF-8?q?=E5=88=A9=E7=94=A8=20systemd=20Restart=3Dalways=20=E9=87=8D?= =?UTF-8?q?=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/web_api.py | 5 ++++- ui/templates/settings.html | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/core/web_api.py b/core/web_api.py index f29ecea..a716d4d 100644 --- a/core/web_api.py +++ b/core/web_api.py @@ -632,9 +632,12 @@ def web_ssl_config(): ok = save_web_config(updates) if ok: + # 在后台线程中延迟退出,让进程重启以加载新配置(systemd Restart=always 会自动拉起) + threading.Thread(target=lambda: (time.sleep(1.5), os._exit(0)), daemon=True).start() return jsonify({ "success": True, - "message": "SSL 配置已保存,重启服务后生效", + "message": "SSL 配置已保存,服务自动重启中…", + "restarting": True, **updates }) return jsonify({"success": False, "error": "写入配置文件失败"}), 500 diff --git a/ui/templates/settings.html b/ui/templates/settings.html index c7fa014..5e8fdd2 100644 --- a/ui/templates/settings.html +++ b/ui/templates/settings.html @@ -700,14 +700,24 @@ if (data.success) { document.getElementById('sslStatus').innerHTML = ' ' + (data.message || '配置已保存'); showSuccess('HTTPS 配置已保存'); + if (data.restarting) { + btn.textContent = '服务重启中… 页面将自动刷新'; + btn.style.background = 'var(--warning-color, #f59e0b)'; + // 等待服务重启后自动刷新页面 + setTimeout(() => { window.location.reload(); }, 4000); + } } else { document.getElementById('sslStatus').innerHTML = ' ' + (data.error || '保存失败'); } } catch (e) { - document.getElementById('sslStatus').innerHTML = ' 网络错误'; + // 服务重启时连接会断开,这是预期行为 + document.getElementById('sslStatus').innerHTML = ' 服务正在重启… 页面将自动刷新'; + btn.textContent = '服务重启中…'; + btn.style.background = 'var(--warning-color, #f59e0b)'; + setTimeout(() => { window.location.reload(); }, 4000); } finally { btn.disabled = false; - btn.textContent = '保 存 HTTPS 配 置'; + // 不重置按钮文案,保持重启中的视觉状态 } });