feat: add dashboard restart action and improve text button contrast
This commit is contained in:
@@ -3,6 +3,7 @@ from .auth import login_required
|
||||
from loguru import logger
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
import platform
|
||||
import psutil
|
||||
@@ -153,3 +154,32 @@ def get_current_user_info():
|
||||
dashboard_server = current_app.dashboard_server
|
||||
result = dashboard_server.get_current_user_info()
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
@system_bp.route('/api/restart_service', methods=['POST'])
|
||||
@login_required
|
||||
def restart_service():
|
||||
"""调用项目根目录下的 restart.sh 重启服务"""
|
||||
try:
|
||||
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
|
||||
script_path = os.path.join(project_root, 'restart.sh')
|
||||
|
||||
if not os.path.exists(script_path):
|
||||
return jsonify({"success": False, "message": f"未找到脚本: {script_path}"}), 404
|
||||
|
||||
subprocess.Popen(
|
||||
['bash', script_path],
|
||||
cwd=project_root,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
start_new_session=True
|
||||
)
|
||||
|
||||
logger.warning(f"后台触发服务重启脚本: {script_path}")
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"message": "已触发重启脚本,服务将在短时间内重启"
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"触发服务重启失败: {e}")
|
||||
return jsonify({"success": False, "message": str(e)}), 500
|
||||
|
||||
Reference in New Issue
Block a user