更新安装脚本

This commit is contained in:
2026-04-12 03:20:48 +08:00
parent 7058da47da
commit 257cccd463
4 changed files with 99 additions and 46 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -5,7 +5,7 @@
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SESE 爬取管理</title>
<script type="module" crossorigin src="/assets/index-Df7HB0Xa.js"></script>
<script type="module" crossorigin src="/assets/index-lohFrjJm.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-c8sW61xI.css">
</head>
<body>
+96 -43
View File
@@ -1,72 +1,125 @@
#!/bin/bash
set -e
# =============================================
# SESE 安装脚本
# =============================================
APP_NAME="SESE"
APP_PATH="/opt/$APP_NAME"
SERVICE_FILE="/etc/systemd/system/$APP_NAME.service"
LOG_PATH="/var/log/$APP_NAME"
echo "正在安装 $APP_NAME..."
# 检测是否在工程目录内
if [ -d ".git" ] && [ -f "main.go" ]; then
echo "==> 检测到工程目录,直接使用当前代码"
PROJECT_DIR="$(pwd)"
else
echo "==> 拉取工程代码..."
cd /opt
if [ -d "$APP_NAME" ]; then
echo "工程已存在,更新代码..."
cd "$APP_NAME"
PROJECT_DIR="$(pwd)"
git pull origin master
git submodule update --init --recursive
else
git clone https://git.lmve.net/kevin/sese-engine-go.git "$APP_NAME"
cd "$APP_NAME"
PROJECT_DIR="$(pwd)"
git submodule update --init --recursive
fi
fi
# 编译前端
echo "编译前端..."
cd sese-engine-ui
echo "==> 检查并停止旧版本..."
if systemctl is-active --quiet "$APP_NAME" 2>/dev/null; then
echo "停止旧服务..."
systemctl stop "$APP_NAME"
systemctl disable "$APP_NAME" 2>/dev/null || true
fi
# 清理旧进程
pkill -f "$APP_PATH/$APP_NAME" 2>/dev/null || true
echo "==> 安装依赖..."
# 安装必要工具
if command -v apt-get &> /dev/null; then
apt-get update
apt-get install -y git nodejs npm golang-go make
elif command -v yum &> /dev/null; then
yum install -y git nodejs npm golang make
elif command -v pacman &> /dev/null; then
pacman -Sy --noconfirm git nodejs npm go make
fi
echo "==> 创建目录..."
mkdir -p "$APP_PATH"
mkdir -p "$(dirname "$LOG_PATH")"
echo "==> 编译前端..."
cd "$PROJECT_DIR/sese-engine-ui"
npm install
npm run build
cd ..
cp -r sese-engine-ui/dist ./dist
# 编译应用
echo "编译应用..."
CGO_ENABLED=0 GOOS=linux go build -o $APP_NAME -ldflags="-s -w" main.go
echo "==> 编译后端..."
cd "$PROJECT_DIR"
go mod download
CGO_ENABLED=0 go build -o "$APP_NAME" .
# 先停止服务
sudo systemctl stop $APP_NAME
sudo systemctl disable $APP_NAME
echo "==> 部署到 $APP_PATH..."
mkdir -p "$APP_PATH"
cp "$PROJECT_DIR/$APP_NAME" "$APP_PATH/"
cp -r "$PROJECT_DIR/dist" "$APP_PATH/"
# 创建目录
echo "创建目录..."
sudo mkdir -p $APP_PATH
sudo mkdir -p $LOG_PATH
echo "==> 配置用户..."
if id -u www &> /dev/null; then
echo "用户 www 已存在,跳过创建"
else
echo "创建用户 www..."
useradd -r -s /usr/sbin/nologin -d /var/www -M www
fi
# 复制文件
echo "复制文件..."
sudo cp $APP_NAME $APP_PATH/
sudo cp -r dist $APP_PATH/
echo "==> 配置权限..."
chown -R www:www "$APP_PATH"
chown -R www:www "$LOG_PATH"
chmod +x "$APP_PATH/$APP_NAME"
# 创建服务文件
echo "创建服务文件..."
sudo tee $SERVICE_FILE > /dev/null <<EOF
echo "==> 创建 systemd 服务..."
cat > "$SERVICE_FILE" <<EOF
[Unit]
Description=My Gin Application
Description=SESE Engine - Web Crawler & Search Engine
Documentation=https://git.lmve.net/kevin/sese-engine-go.git
After=network.target
[Service]
Type=simple
User=www-data
User=www
Group=www
WorkingDirectory=$APP_PATH
ExecStart=$APP_PATH/$APP_NAME
Restart=always
RestartSec=5
StandardOutput=append:$LOG_PATH/access.log
StandardError=append:$LOG_PATH/error.log
Environment=GIN_MODE=release
StandardOutput=append:$LOG_PATH/stdout.log
StandardError=append:$LOG_PATH/stderr.log
# 安全加固
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=$APP_PATH $LOG_PATH
[Install]
WantedBy=multi-user.target
EOF
# 设置权限
echo "设置权限..."
sudo chown -R www-data:www-data $APP_PATH
sudo chown -R www-data:www-data $LOG_PATH
sudo chmod 750 $APP_PATH/$APP_NAME
echo "==> 重新加载 systemd 并启动服务..."
systemctl daemon-reload
systemctl enable "$APP_NAME"
systemctl restart "$APP_NAME"
# 重载并启动
echo "启动服务..."
sudo systemctl daemon-reload
sudo systemctl enable $APP_NAME
sudo systemctl start $APP_NAME
echo "安装完成!"
echo "使用以下命令管理服务:"
echo " sudo systemctl status $APP_NAME"
echo " sudo journalctl -u $APP_NAME -f"
echo ""
echo "==> 安装完成!"
echo " 服务状态: systemctl status $APP_NAME"
echo " 日志查看: journalctl -u $APP_NAME -f"
echo " 应用日志: tail -f $LOG_PATH/stdout.log"