如何解决Azure应用服务部署中startup.sh的“没有这样的文件或目录”错误?

问题描述 投票:0回答:1

问题:

我正在尝试将使用 WebSockets 的 Flask/FastAPI 应用程序部署到 Azure 应用服务。应用程序在本地运行良好,但部署到 Azure 时,无法启动并出现错误: chmod: 无法访问 '/home/site/wwwroot/startup.sh': 没有这样的文件或目录。

项目结构:

我在 GitHub 上的项目存储库的结构如下:

/my-app
├── .github
│   └── workflows
│       └── azure.yml 
├── app.py  
├── requirements.txt
├── folder
├── folder
├── haarcascadeclassifier
└── startup.sh

启动.sh

apt-get update
apt-get install -y libgl1-mesa-glx libglib2.0-0

gunicorn -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000 app:app

Azure 配置: Linux 上的应用服务 Python 3.10

启动命令:

chmod +x /home/site/wwwroot/startup.sh && /home/site/wwwroot/startup.sh 

日志:

来自 Azure 活动日志:

2024-06-26T16:25:28.3624037Z Site's appCommandLine: 'chmod +x /home/site/wwwroot/startup.sh && /home/site/wwwroot/startup.sh'
...
2024-06-26T16:25:29.2838467Z chmod: cannot access '/home/site/wwwroot/startup.sh': No such file or directory
2024-06-26T16:25:29.182.052Z ERROR - Container videoemotion_0_e6593d58 for site videoemotion has exited, failing site start
2024-06-26T16:25:29.064Z ERROR - Container videoemotion_0_e6593d58 didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.

我尝试过的:

验证startup.sh位于GitHub存储库的根目录中。 确保脚本已提交并推送到存储库。 检查 Azure 部署中心和日志流是否有任何其他错误。

问题:

为什么部署时找不到startup.sh脚本? 如何确保脚本被 Azure 应用服务正确识别并执行?

任何帮助或见解将不胜感激!

azure websocket azure-web-app-service fastapi
1个回答
0
投票

您遇到的问题表明 Azure 应用服务在部署期间无法找到

startup.sh
脚本。您可以检查以下几个步骤来解决此问题:

更改启动.sh:

#!/bin/bash
apt-get update
apt-get install  -y  libgl1-mesa-glx  libglib2.0-0
pip install  -r  requirements.txt
uvicorn main:app  --host  0.0.0.0  --port  8000

添加启动命令:

在Azure Web App中标签配置的常规设置中添加启动命令。

uvicorn main:app --host 0.0.0.0 --port 8000

请参阅我的 git,了解我用于快速 api 的 WebSocket 连接的相同代码。

app = FastAPI()

@app.get("/")
async def get(request: Request):
    return HTMLResponse(open("templates/index.html").read())

@app.websocket("/ws")
async def websocket_endpoint(websocket: StarletteWebSocket):
    await websocket.accept()
    protocol = "wss" if request.url.scheme == "https" else "ws"
    while True:
        data = await websocket.receive_text()
        await websocket.send_text(f"Message text was: {data}")

  • 如果已配置
    ws/http
    端点,则
     https
    允许设置应设置为
    off

enter image description here git 中 fast api 的示例文件夹结构: enter image description here

git 中的部署状态:

enter image description here

Azure Web 应用程序输出: enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.