From 6bab6d8b09af1b965cb8a66cdfd0ce70da864a20 Mon Sep 17 00:00:00 2001 From: mshe <666666666@666666666.666666666> Date: Mon, 8 Jun 2026 15:37:14 +0800 Subject: [PATCH] update start.sh --- app.py | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/app.py b/app.py index 9e00023..f3a42ba 100755 --- a/app.py +++ b/app.py @@ -29,51 +29,20 @@ async def run_spider_in_vnc(index: int) -> str: Args: index: VNC 显示编号 - username: 用户名(默认 user{index}) """ - - if username is None: - username = f"user{index}" - try: - # 创建临时脚本 - with tempfile.NamedTemporaryFile(mode='w', suffix='.sh', delete=False) as f: - f.write(f"""#!/bin/bash -PUBLIC_DIR="/shared" -username="{username}" -export DISPLAY=:{index} - -echo "启动 VNC 服务" -sudo su - "$username" -c "vncserver :{index} -geometry 1280x800 -depth 24 -localhost no" -sudo su - "$username" -c "export DISPLAY=:{index} && xhost +" 2>/dev/null -sleep 3 - -cd $PUBLIC_DIR/learn-spider -sudo -E ./run.sh - -sudo su - "$username" -c "vncserver -kill :{index}" 2>/dev/null -""") - script_path = f.name - - # 执行脚本 - os.chmod(script_path, 0o755) - + # 调用外部 start.sh 脚本,传入 index 作为参数 process = await asyncio.create_subprocess_exec( - script_path, + "/home/dgs/vnc-server/start.sh", + str(index), stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) - stdout, stderr = await process.communicate() - - # 清理临时文件 - os.unlink(script_path) - if process.returncode == 0: return f"✅ 爬虫执行成功\n输出:\n{stdout.decode()}" else: return f"❌ 爬虫执行失败\n错误:\n{stderr.decode()}" - except Exception as e: return f"❌ 执行出错: {str(e)}"