update start.sh
This commit is contained in:
parent
59c9da1623
commit
1308f99eff
40
app.py
40
app.py
|
|
@ -9,7 +9,7 @@ logging.basicConfig(level=logging.INFO)
|
||||||
# 日志会输出到 stderr,不会污染 stdout
|
# 日志会输出到 stderr,不会污染 stdout
|
||||||
logging.info("服务器启动")
|
logging.info("服务器启动")
|
||||||
|
|
||||||
|
VNC_SERVER_HOST = "https://10.10.40.19:6080"
|
||||||
# @mcp.tool()
|
# @mcp.tool()
|
||||||
def mail_qq_spider(account: str) -> str:
|
def mail_qq_spider(account: str) -> str:
|
||||||
"""qq邮箱爬虫,第一个参数是用户名"""
|
"""qq邮箱爬虫,第一个参数是用户名"""
|
||||||
|
|
@ -21,6 +21,7 @@ async def start_vnc_server(display: int) -> str:
|
||||||
Args:
|
Args:
|
||||||
display: VNC 显示编号
|
display: VNC 显示编号
|
||||||
"""
|
"""
|
||||||
|
data={"display": display}
|
||||||
try:
|
try:
|
||||||
# 调用外部 start_vnc_server.sh 脚本,传入 index 作为参数
|
# 调用外部 start_vnc_server.sh 脚本,传入 index 作为参数
|
||||||
process = await asyncio.create_subprocess_exec(
|
process = await asyncio.create_subprocess_exec(
|
||||||
|
|
@ -30,12 +31,17 @@ async def start_vnc_server(display: int) -> str:
|
||||||
stderr=asyncio.subprocess.PIPE
|
stderr=asyncio.subprocess.PIPE
|
||||||
)
|
)
|
||||||
stdout, stderr = await process.communicate()
|
stdout, stderr = await process.communicate()
|
||||||
|
data["message"] = stdout.decode()
|
||||||
|
data["status"] = 200 if process.returncode == 0 else 500
|
||||||
|
|
||||||
if process.returncode == 0:
|
if process.returncode == 0:
|
||||||
return f"✅ VNC服务启动成功\n输出:\n{stdout.decode()}"
|
data["vnc_url"] = f"{VNC_SERVER_HOST}/vnc_lite.html?path=?token=user{display}"
|
||||||
|
return json.dumps(data, ensure_ascii=False)
|
||||||
else:
|
else:
|
||||||
return f"❌ VNC服务启动失败\n错误:\n{stderr.decode()}"
|
return json.dumps(data, ensure_ascii=False)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"❌ 执行出错: {str(e)}"
|
data["status"] = 500
|
||||||
|
return json.dumps(data, ensure_ascii=False)
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
async def start_spider(spider_code: str,display: str) -> str:
|
async def start_spider(spider_code: str,display: str) -> str:
|
||||||
|
|
@ -45,6 +51,7 @@ async def start_spider(spider_code: str,display: str) -> str:
|
||||||
spider_code: 爬虫代码
|
spider_code: 爬虫代码
|
||||||
display: 显示桌面编号
|
display: 显示桌面编号
|
||||||
"""
|
"""
|
||||||
|
data={"display": display}
|
||||||
try:
|
try:
|
||||||
# 调用外部 start_spider.sh 脚本,传入 spider_code 作为参数
|
# 调用外部 start_spider.sh 脚本,传入 spider_code 作为参数
|
||||||
process = await asyncio.create_subprocess_exec(
|
process = await asyncio.create_subprocess_exec(
|
||||||
|
|
@ -55,12 +62,15 @@ async def start_spider(spider_code: str,display: str) -> str:
|
||||||
stderr=asyncio.subprocess.PIPE
|
stderr=asyncio.subprocess.PIPE
|
||||||
)
|
)
|
||||||
stdout, stderr = await process.communicate()
|
stdout, stderr = await process.communicate()
|
||||||
|
data["message"] = stdout.decode()
|
||||||
|
data["status"] = 200 if process.returncode == 0 else 500
|
||||||
if process.returncode == 0:
|
if process.returncode == 0:
|
||||||
return f"✅ 爬虫启动成功\n输出:\n{stdout.decode()}"
|
return json.dumps(data, ensure_ascii=False)
|
||||||
else:
|
else:
|
||||||
return f"❌ 爬虫启动失败\n错误:\n{stderr.decode()}"
|
return json.dumps(data, ensure_ascii=False)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"❌ 执行出错: {str(e)}"
|
data["status"] = 500
|
||||||
|
return json.dumps(data, ensure_ascii=False)
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
async def close_vnc_server(display: int) -> str:
|
async def close_vnc_server(display: int) -> str:
|
||||||
|
|
@ -68,22 +78,26 @@ async def close_vnc_server(display: int) -> str:
|
||||||
Args:
|
Args:
|
||||||
display: VNC 显示编号
|
display: VNC 显示编号
|
||||||
"""
|
"""
|
||||||
|
data={"display": display}
|
||||||
try:
|
try:
|
||||||
# 调用外部 stop_vnc_server.sh 脚本,传入 display 作为参数
|
# 调用外部 close_vnc_server.sh 脚本,传入 display 作为参数
|
||||||
process = await asyncio.create_subprocess_exec(
|
process = await asyncio.create_subprocess_exec(
|
||||||
"/home/dgs/vnc-server/stop_vnc_server.sh",
|
"/home/dgs/vnc-server/close_vnc_server.sh",
|
||||||
str(display),
|
str(display),
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.PIPE
|
stderr=asyncio.subprocess.PIPE
|
||||||
)
|
)
|
||||||
stdout, stderr = await process.communicate()
|
stdout, stderr = await process.communicate()
|
||||||
|
data["message"] = stdout.decode()
|
||||||
|
data["status"] = 200 if process.returncode == 0 else 500
|
||||||
if process.returncode == 0:
|
if process.returncode == 0:
|
||||||
return f"✅ VNC服务关闭成功\n输出:\n{stdout.decode()}"
|
return json.dumps(data, ensure_ascii=False)
|
||||||
else:
|
else:
|
||||||
return f"❌ VNC服务关闭失败\n错误:\n{stderr.decode()}"
|
return json.dumps(data, ensure_ascii=False)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"❌ 执行出错: {str(e)}"
|
data["status"] = 500
|
||||||
|
return json.dumps(data, ensure_ascii=False)
|
||||||
|
|
||||||
@mcp.resource("data://spider_code")
|
@mcp.resource("data://spider_code")
|
||||||
def get_spider_code_list() -> str:
|
def get_spider_code_list() -> str:
|
||||||
spider_list = [
|
spider_list = [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue