Add web server deployment
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,82 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# 缠论分析系统生产环境部署脚本
|
||||||
|
|
||||||
|
# 显示执行的命令
|
||||||
|
set -x
|
||||||
|
|
||||||
|
# 确保脚本在错误时停止
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# 项目根目录
|
||||||
|
PROJECT_DIR=$(pwd)
|
||||||
|
echo "项目将部署在: $PROJECT_DIR"
|
||||||
|
|
||||||
|
# 创建虚拟环境
|
||||||
|
echo "创建Python虚拟环境..."
|
||||||
|
python3 -m venv venv
|
||||||
|
source venv/bin/activate
|
||||||
|
|
||||||
|
# 安装依赖
|
||||||
|
echo "安装依赖包..."
|
||||||
|
pip install --upgrade pip
|
||||||
|
pip install flask pandas matplotlib ccxt pytz talib-binary gunicorn
|
||||||
|
|
||||||
|
# 安装任何额外的系统依赖
|
||||||
|
# sudo apt-get update
|
||||||
|
# sudo apt-get install -y python3-dev
|
||||||
|
|
||||||
|
# 检查目录结构
|
||||||
|
echo "检查目录结构..."
|
||||||
|
mkdir -p web/templates
|
||||||
|
|
||||||
|
# 创建日志目录
|
||||||
|
mkdir -p logs
|
||||||
|
|
||||||
|
# 创建启动脚本
|
||||||
|
echo "创建启动脚本..."
|
||||||
|
cat > start_service.sh << 'EOF'
|
||||||
|
#!/bin/bash
|
||||||
|
# 缠论分析系统启动脚本
|
||||||
|
|
||||||
|
# 项目根目录
|
||||||
|
PROJECT_DIR=$(pwd)
|
||||||
|
cd $PROJECT_DIR
|
||||||
|
|
||||||
|
# 激活虚拟环境
|
||||||
|
source venv/bin/activate
|
||||||
|
|
||||||
|
# 启动服务
|
||||||
|
cd web
|
||||||
|
echo "启动缠论分析系统服务..."
|
||||||
|
gunicorn app:app --bind=0.0.0.0:8123 --workers=4 --timeout=120 --log-level=info --log-file=logs/chanlun.log --daemon
|
||||||
|
|
||||||
|
echo "服务已启动,端口8123"
|
||||||
|
echo "日志文件位置: $PROJECT_DIR/web/logs/chanlun.log"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# 创建停止脚本
|
||||||
|
echo "创建停止脚本..."
|
||||||
|
cat > stop_service.sh << 'EOF'
|
||||||
|
#!/bin/bash
|
||||||
|
# 停止缠论分析系统服务
|
||||||
|
|
||||||
|
echo "停止缠论分析系统服务..."
|
||||||
|
pkill -f "gunicorn app:app"
|
||||||
|
echo "服务已停止"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# 添加执行权限
|
||||||
|
chmod +x start_service.sh
|
||||||
|
chmod +x stop_service.sh
|
||||||
|
|
||||||
|
# 修改app.py中的调试模式(生产环境应关闭调试模式)
|
||||||
|
if [ -f web/app.py ]; then
|
||||||
|
echo "配置app.py为生产环境模式..."
|
||||||
|
sed -i 's/app.run(debug=True, host='\''0.0.0.0'\'', port=8123)/# 在生产环境中,使用gunicorn启动服务\n# app.run(debug=False, host='\''0.0.0.0'\'', port=8124)/' user_data/Chan/web/app.py
|
||||||
|
else
|
||||||
|
echo "警告: 未找到app.py文件"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "部署完成!"
|
||||||
|
echo "使用 ./start_service.sh 启动服务"
|
||||||
|
echo "使用 ./stop_service.sh 停止服务"
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
cd /path/to/your/project/user_data/Chan/web
|
||||||
|
source /path/to/your/virtualenv/bin/activate # 如果使用虚拟环境
|
||||||
|
exec gunicorn app:app -b 0.0.0.0:8123 --workers=4 --timeout 120
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# 缠论分析系统启动脚本
|
||||||
|
|
||||||
|
# 项目根目录
|
||||||
|
PROJECT_DIR=$(pwd)
|
||||||
|
cd $PROJECT_DIR
|
||||||
|
|
||||||
|
# 激活虚拟环境
|
||||||
|
source venv/bin/activate
|
||||||
|
|
||||||
|
# 启动服务
|
||||||
|
cd web
|
||||||
|
echo "启动缠论分析系统服务..."
|
||||||
|
gunicorn app:app --bind=0.0.0.0:8123 --workers=4 --timeout=120 --log-level=info --log-file=logs/chanlun.log --daemon
|
||||||
|
|
||||||
|
echo "服务已启动,端口8123"
|
||||||
|
echo "日志文件位置: $PROJECT_DIR/web/logs/chanlun.log"
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Chan Lun Trading Analysis
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=your_username
|
||||||
|
Group=your_groupname
|
||||||
|
WorkingDirectory=/path/to/your/project/user_data/Chan/web
|
||||||
|
ExecStart=/path/to/your/project/gunicorn_start.sh
|
||||||
|
Restart=always
|
||||||
|
RestartSec=10
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# copy chanlun.service to:
|
||||||
|
/etc/systemd/system/chanlun.service
|
||||||
|
# run command:
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable chanlun
|
||||||
|
sudo systemctl start chanlun
|
||||||
|
|
||||||
|
# check status:
|
||||||
|
sudo systemctl status chanlun
|
||||||
|
|
||||||
|
# check logs:
|
||||||
|
sudo journalctl -u chanlun -f
|
||||||
Reference in New Issue
Block a user