feat: SSL 保存后自动退出进程,利用 systemd Restart=always 重启
This commit is contained in:
@ -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
|
||||
|
||||
@ -700,14 +700,24 @@
|
||||
if (data.success) {
|
||||
document.getElementById('sslStatus').innerHTML = '<i class="fas fa-check-circle" style="color:#22c55e"></i> ' + (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 = '<i class="fas fa-exclamation-triangle" style="color:#ff6b6b"></i> ' + (data.error || '保存失败');
|
||||
}
|
||||
} catch (e) {
|
||||
document.getElementById('sslStatus').innerHTML = '<i class="fas fa-exclamation-triangle" style="color:#ff6b6b"></i> 网络错误';
|
||||
// 服务重启时连接会断开,这是预期行为
|
||||
document.getElementById('sslStatus').innerHTML = '<i class="fas fa-sync-alt fa-spin" style="color:var(--primary-color,#4488ff)"></i> 服务正在重启… 页面将自动刷新';
|
||||
btn.textContent = '服务重启中…';
|
||||
btn.style.background = 'var(--warning-color, #f59e0b)';
|
||||
setTimeout(() => { window.location.reload(); }, 4000);
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
btn.textContent = '保 存 HTTPS 配 置';
|
||||
// 不重置按钮文案,保持重启中的视觉状态
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user