feat(servers): 新服务器接入自动 sudo 配置与路径探测
创建/导入/IP 添加成功后后台 onboard 任务;前端注册进度条与 toast。
This commit is contained in:
@@ -67,38 +67,25 @@ async def _fetch_servers(
|
||||
|
||||
|
||||
async def _detect_one_server(server: Any) -> dict[str, Any]:
|
||||
from server.application.server_batch_common import detect_and_save_target_path
|
||||
from server.application.services.server_batch_service import result_item_dict
|
||||
from server.application.server_batch_common import sudo_wrap, update_server_target_path
|
||||
from server.infrastructure.ssh.asyncssh_pool import exec_ssh_command
|
||||
from server.utils.posix_paths import posix_dirname
|
||||
|
||||
sid = server.id
|
||||
label = server.name or str(sid)
|
||||
try:
|
||||
ssh_user = (server.username or "root").strip()
|
||||
cmd = "find /www/wwwroot -iname 'workerman.bat' -type f -print -quit 2>/dev/null"
|
||||
cmd = sudo_wrap(cmd, ssh_user)
|
||||
r = await exec_ssh_command(server, cmd, timeout=30)
|
||||
if r["exit_code"] != 0 and not r.get("stdout", "").strip():
|
||||
outcome = await detect_and_save_target_path(server)
|
||||
if outcome.get("success"):
|
||||
return result_item_dict(
|
||||
server_id=sid,
|
||||
server_name=label,
|
||||
success=False,
|
||||
error=f"搜索失败 (exit {r['exit_code']})",
|
||||
success=True,
|
||||
stdout=str(outcome.get("stdout") or ""),
|
||||
)
|
||||
found = r["stdout"].strip()
|
||||
if not found:
|
||||
return result_item_dict(
|
||||
server_id=sid, server_name=label, success=False, error="未找到 workerman.bat"
|
||||
)
|
||||
first_match = found.split("\n")[0].strip()
|
||||
target_dir = posix_dirname(first_match)
|
||||
await update_server_target_path(sid, target_dir)
|
||||
return result_item_dict(
|
||||
server_id=sid,
|
||||
server_name=label,
|
||||
success=True,
|
||||
stdout=f"target_path → {target_dir}",
|
||||
success=False,
|
||||
error=str(outcome.get("error") or "探测失败"),
|
||||
)
|
||||
except Exception as e:
|
||||
return result_item_dict(server_id=sid, server_name=label, success=False, error=str(e)[:300])
|
||||
|
||||
Reference in New Issue
Block a user