update start.sh

This commit is contained in:
mshe 2026-06-08 15:42:23 +08:00
parent 6bab6d8b09
commit 8739964ef7
5 changed files with 31 additions and 28 deletions

2
app.py
View File

@ -33,7 +33,7 @@ async def run_spider_in_vnc(index: int) -> str:
try:
# 调用外部 start.sh 脚本,传入 index 作为参数
process = await asyncio.create_subprocess_exec(
"/home/dgs/vnc-server/start.sh",
"/home/dgs/vnc-server/start_vnc.sh",
str(index),
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE

5
bin/close_vnc.sh Normal file
View File

@ -0,0 +1,5 @@
#!/bin/bash
INDEX=$1
username="user$INDEX"
sudo su - "$username" -c "vncserver -kill :$INDEX" 2>/dev/null

View File

@ -1,27 +0,0 @@
#!/bin/bash
INDEX=$1
spider_code=$2
PUBLIC_DIR="${3:-/shared}"
username="user$INDEX"
export DISPLAY=:$INDEX
echo "当前显示桌面:$DISPLAY"
echo "正在启动VNC服务"
sudo su - "$username" -c "vncserver :$INDEX -geometry 1280x800 -depth 24 -localhost no"
echo "授权桌面访问"
sudo su - "$username" -c "export DISPLAY=:$INDEX && xhost +" 2>/dev/null
echo "等待 VNC 启动"
sleep 3
start_spider(){
cd $PUBLIC_DIR/learn-spider
echo "$PUBLIC_DIR/learn-spider"
echo "正在启动爬虫$spider_code"
sudo -E ./start_spider.sh $spider_code # -E 保留当前环境变量
}
# echo "启动爬虫"
# start_spider
# echo "爬虫执行完毕,20秒后关闭VNC"
# sleep 20
# sudo su - "$username" -c "vncserver -kill :$INDEX" 2>/dev/null

13
bin/start_spider.sh Normal file
View File

@ -0,0 +1,13 @@
#!/bin/bash
spider_code=$1
PUBLIC_DIR="${2:-/shared}"
start_spider(){
cd $PUBLIC_DIR/learn-spider
echo "$PUBLIC_DIR/learn-spider"
echo "正在启动爬虫$spider_code"
sudo -E ./start_spider.sh $spider_code # -E 保留当前环境变量
}
echo "启动爬虫"
start_spider

12
bin/start_vnc.sh Normal file
View File

@ -0,0 +1,12 @@
#!/bin/bash
INDEX=$1
username="user$INDEX"
export DISPLAY=:$INDEX
echo "当前显示桌面:$DISPLAY"
echo "正在启动VNC服务"
sudo su - "$username" -c "vncserver :$INDEX -geometry 1280x800 -depth 24 -localhost no"
echo "授权桌面访问"
sudo su - "$username" -c "export DISPLAY=:$INDEX && xhost +" 2>/dev/null
echo "等待 VNC 启动"
sleep 3