35 lines
940 B
Bash
35 lines
940 B
Bash
#!/bin/bash
|
||
|
||
# 创建必要的目录
|
||
mkdir -p logs email_data db
|
||
|
||
# 检查环境变量文件是否存在,不存在则创建
|
||
if [ ! -f .env ]; then
|
||
echo "创建.env文件..."
|
||
cat > .env << EOF
|
||
FLASK_ENV=production
|
||
SECRET_KEY=$(openssl rand -hex 16)
|
||
MAIL_DOMAINS=example.com,mail.example.com
|
||
EOF
|
||
echo ".env文件已创建"
|
||
fi
|
||
|
||
# 初始化数据库
|
||
echo "初始化数据库..."
|
||
python -c "from app.models import init_db; init_db()"
|
||
|
||
# 启动服务
|
||
echo "启动服务..."
|
||
if [ "$1" == "docker" ]; then
|
||
# 使用Docker启动
|
||
docker-compose up -d
|
||
echo "服务已在Docker中启动"
|
||
else
|
||
# 直接启动
|
||
echo "直接启动应用..."
|
||
# 检查是否以root权限运行(25端口需要)
|
||
if [ "$(id -u)" -ne 0 ] && [ "$SMTP_PORT" -lt 1024 ]; then
|
||
echo "警告: 在端口 $SMTP_PORT 运行SMTP服务需要root权限"
|
||
fi
|
||
python run.py --host 0.0.0.0 --port 5000 --smtp-port ${SMTP_PORT:-25}
|
||
fi |