Files
xianyan/server/install.sh
Developer 283950ea07 chore: 批量代码优化与功能迭代更新
本次提交包含大量代码优化、功能新增与服务端配置更新:
1. 修复分析报告统计数据,调整CMake策略设置
2. 优化APP权限配置、编辑器与聊天界面组件
3. 更新依赖库版本与pubspec配置
4. 新增文件传输服务端、信令服务器相关配置与脚本
5. 完善用户注销功能与数据库迁移脚本
6. 优化多处动画效果、代码风格与日志输出
7. 新增多种调试与部署脚本,修复已知BUG
2026-05-12 06:28:04 +08:00

226 lines
6.8 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# ============================================================
# 闲言APP — 文件传输服务端部署脚本
# 创建时间: 2026-05-10
# 更新时间: 2026-05-10
# 作用: 安装依赖、配置Nginx、启动信令服务
# 上次更新: 初始版本
# ============================================================
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; }
check_root() {
if [ "$EUID" -ne 0 ]; then
error "请使用root权限运行此脚本: sudo bash install.sh"
fi
}
check_php() {
if ! command -v php &> /dev/null; then
error "PHP未安装请先安装PHP 7.4+"
fi
PHP_VERSION=$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;")
info "PHP版本: $PHP_VERSION"
}
check_composer() {
if ! command -v composer &> /dev/null; then
warn "Composer未安装正在安装..."
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
fi
info "Composer版本: $(composer --version 2>/dev/null | head -1)"
}
install_dependencies() {
info "安装PHP依赖..."
if [ -f "composer.json" ]; then
composer install --no-dev --optimize-autoloader
info "PHP依赖安装完成"
else
warn "composer.json不存在跳过依赖安装"
fi
}
create_dirs() {
info "创建必要目录..."
mkdir -p "$SCRIPT_DIR/logs"
mkdir -p "$SCRIPT_DIR/data"
chmod 755 "$SCRIPT_DIR/logs"
chmod 755 "$SCRIPT_DIR/data"
info "目录创建完成"
}
configure_supervisord() {
info "配置Supervisord进程管理..."
SUPERVISOR_CONF="/etc/supervisor/conf.d/xianyan-signaling.conf"
if command -v supervisorctl &> /dev/null; then
mkdir -p /etc/supervisor/conf.d
cat > "$SUPERVISOR_CONF" <<EOF
[program:xianyan-signaling]
command=php ${SCRIPT_DIR}/signaling_server.php
directory=${SCRIPT_DIR}
user=www-data
autostart=true
autorestart=true
startretries=5
redirect_stderr=true
stdout_logfile=${SCRIPT_DIR}/logs/supervisor.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=3
environment=PATH="/usr/bin:/usr/local/bin"
EOF
supervisorctl reread
supervisorctl update
info "Supervisord配置完成"
else
warn "Supervisord未安装使用systemd替代..."
configure_systemd
fi
}
configure_systemd() {
info "配置Systemd服务..."
SYSTEMD_CONF="/etc/systemd/system/xianyan-signaling.service"
cat > "$SYSTEMD_CONF" <<EOF
[Unit]
Description=XianYan File Transfer Signaling Server
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/php ${SCRIPT_DIR}/signaling_server.php
WorkingDirectory=${SCRIPT_DIR}
User=www-data
Restart=always
RestartSec=5
StandardOutput=append:${SCRIPT_DIR}/logs/systemd.log
StandardError=append:${SCRIPT_DIR}/logs/systemd_error.log
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable xianyan-signaling
info "Systemd服务配置完成"
}
configure_nginx() {
info "配置Nginx反向代理..."
NGINX_CONF="/etc/nginx/conf.d/xianyan-signaling.conf"
if ! command -v nginx &> /dev/null; then
warn "Nginx未安装跳过配置"
return
fi
read -p "请输入域名 (默认: tools.wktyl.com): " DOMAIN
DOMAIN=${DOMAIN:-tools.wktyl.com}
cat > "$NGINX_CONF" <<EOF
# 闲言APP 文件传输信令服务 Nginx配置
# 创建时间: 2026-05-10
# WebSocket信令服务反向代理
server {
listen 9443 ssl http2;
server_name ${DOMAIN};
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
proxy_pass http://127.0.0.1:9443;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}
}
EOF
nginx -t && nginx -s reload
info "Nginx配置完成"
}
start_signaling() {
info "启动信令服务..."
if command -v supervisorctl &> /dev/null; then
supervisorctl start xianyan-signaling
elif command -v systemctl &> /dev/null; then
systemctl start xianyan-signaling
else
nohup php "$SCRIPT_DIR/signaling_server.php" > "$SCRIPT_DIR/logs/nohup.log" 2>&1 &
echo $! > "$SCRIPT_DIR/signaling.pid"
info "信令服务已启动 (PID: $(cat "$SCRIPT_DIR/signaling.pid"))"
fi
}
verify_installation() {
info "验证安装..."
sleep 2
if curl -s http://127.0.0.1:9443/health | grep -q "ok"; then
info "✅ 信令服务运行正常"
else
warn "⚠️ 信令服务可能未正常启动,请检查日志"
fi
if curl -s https://${DOMAIN:-tools.wktyl.com}/api/file_transfer/health | grep -q "ok"; then
info "✅ REST API运行正常"
else
warn "⚠️ REST API可能未正常响应"
fi
}
print_summary() {
echo ""
echo "╔══════════════════════════════════════════════════╗"
echo "║ 闲言APP 文件传输服务端部署完成 ║"
echo "╠══════════════════════════════════════════════════╣"
echo "║ 信令服务: ws://127.0.0.1:9443 ║"
echo "║ 健康检查: http://127.0.0.1:9443/health ║"
echo "║ REST API: https://${DOMAIN:-tools.wktyl.com}/api/file_transfer/ ║"
echo "║ 日志目录: ${SCRIPT_DIR}/logs/ ║"
echo "║ 数据目录: ${SCRIPT_DIR}/data/ ║"
echo "╚══════════════════════════════════════════════════╝"
echo ""
info "常用命令:"
echo " 启动: supervisorctl start xianyan-signaling"
echo " 停止: supervisorctl stop xianyan-signaling"
echo " 重启: supervisorctl restart xianyan-signaling"
echo " 日志: tail -f ${SCRIPT_DIR}/logs/signaling.log"
}
main() {
info "开始部署闲言APP文件传输服务端..."
check_root
check_php
check_composer
install_dependencies
create_dirs
configure_supervisord
configure_nginx
start_signaling
verify_installation
print_summary
}
main "$@"