我使用Azure Web应用程序作为Docker容器主机,并且我想配置Docker容器或Web应用程序来响应SIGTERM消息
我只找到了这个:
启动关闭时,容器主机会向您的容器发送SIGTERM消息。在容器中实现的代码可以响应此操作系统级消息以处理终止。
电子邮件:https://learn.microsoft.com/en-us/azure/container-apps/application-lifecycle-management#shutdown
但是我到底需要如何配置Web应用程序或容器?我不明白我试着用这样的东西作为entrypoint.sh
#!/bin/bash
# Function to gracefully stop the processes and clean up
cleanup() {
echo "Received termination signal. Stopping processes gracefully..."
# Stop the app (Python)
echo "Stopping app..."
kill $python_pid
# Stop the Bot (Java)
echo "Stopping Bot"
kill $java_pid
# Wait for the processes to be terminated
wait $python_pid
wait $java_pid
echo "All processes have been stopped. Exiting..."
exit 0
}
# Trap termination signal and call the cleanup function
trap 'cleanup' SIGTERM
# Start ML app
cd /app
echo "Starting app..."
gunicorn --log-level debug --access-logfile - --error-logfile - -b :5000 wsgi:app &
python_pid=$!
# Start Slack Bot
cd /bot
echo "Starting Bot."
java -jar hrbs.jar &
java_pid=$!
# Wait for any of the processes to finish
wait -n $python_pid $java_pid
# Cleanup on error exit (should not reach this point, as we expect termination signal to be sent)
cleanup
字符串
1条答案
按热度按时间xxe27gdn1#
Azure Web App会自动处理SIGTERM信号,以正常关闭容器。
chmod +x entrypoint.sh
内设置执行权限路径目录:
的数据
Dockerfile:
字符串
requirements.txt
**。一旦你的应用程序准备好转换成图像,并发送到容器如下。
的
然后,在portal中创建一个webapp,将publish选项配置为Docker容器,如下所示。
的
一旦部署完成。转到Web App的“设置”部分,选择“容器设置”,并确保启用“正常关机”。检查在docker desktop中创建的容器并运行它。