更新安装脚本
This commit is contained in:
File diff suppressed because one or more lines are too long
Vendored
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>SESE 爬取管理</title>
|
<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">
|
<link rel="stylesheet" crossorigin href="/assets/index-c8sW61xI.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
+96
-43
@@ -1,72 +1,125 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# =============================================
|
||||||
|
# SESE 安装脚本
|
||||||
|
# =============================================
|
||||||
|
|
||||||
APP_NAME="SESE"
|
APP_NAME="SESE"
|
||||||
APP_PATH="/opt/$APP_NAME"
|
APP_PATH="/opt/$APP_NAME"
|
||||||
SERVICE_FILE="/etc/systemd/system/$APP_NAME.service"
|
SERVICE_FILE="/etc/systemd/system/$APP_NAME.service"
|
||||||
LOG_PATH="/var/log/$APP_NAME"
|
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 "==> 检查并停止旧版本..."
|
||||||
echo "编译前端..."
|
if systemctl is-active --quiet "$APP_NAME" 2>/dev/null; then
|
||||||
cd sese-engine-ui
|
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
|
npm run build
|
||||||
cd ..
|
|
||||||
cp -r sese-engine-ui/dist ./dist
|
|
||||||
|
|
||||||
# 编译应用
|
echo "==> 编译后端..."
|
||||||
echo "编译应用..."
|
cd "$PROJECT_DIR"
|
||||||
CGO_ENABLED=0 GOOS=linux go build -o $APP_NAME -ldflags="-s -w" main.go
|
go mod download
|
||||||
|
CGO_ENABLED=0 go build -o "$APP_NAME" .
|
||||||
|
|
||||||
# 先停止服务
|
echo "==> 部署到 $APP_PATH..."
|
||||||
sudo systemctl stop $APP_NAME
|
mkdir -p "$APP_PATH"
|
||||||
sudo systemctl disable $APP_NAME
|
cp "$PROJECT_DIR/$APP_NAME" "$APP_PATH/"
|
||||||
|
cp -r "$PROJECT_DIR/dist" "$APP_PATH/"
|
||||||
|
|
||||||
# 创建目录
|
echo "==> 配置用户..."
|
||||||
echo "创建目录..."
|
if id -u www &> /dev/null; then
|
||||||
sudo mkdir -p $APP_PATH
|
echo "用户 www 已存在,跳过创建"
|
||||||
sudo mkdir -p $LOG_PATH
|
else
|
||||||
|
echo "创建用户 www..."
|
||||||
|
useradd -r -s /usr/sbin/nologin -d /var/www -M www
|
||||||
|
fi
|
||||||
|
|
||||||
# 复制文件
|
echo "==> 配置权限..."
|
||||||
echo "复制文件..."
|
chown -R www:www "$APP_PATH"
|
||||||
sudo cp $APP_NAME $APP_PATH/
|
chown -R www:www "$LOG_PATH"
|
||||||
sudo cp -r dist $APP_PATH/
|
chmod +x "$APP_PATH/$APP_NAME"
|
||||||
|
|
||||||
# 创建服务文件
|
echo "==> 创建 systemd 服务..."
|
||||||
echo "创建服务文件..."
|
cat > "$SERVICE_FILE" <<EOF
|
||||||
sudo tee $SERVICE_FILE > /dev/null <<EOF
|
|
||||||
[Unit]
|
[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
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
User=www-data
|
User=www
|
||||||
|
Group=www
|
||||||
WorkingDirectory=$APP_PATH
|
WorkingDirectory=$APP_PATH
|
||||||
ExecStart=$APP_PATH/$APP_NAME
|
ExecStart=$APP_PATH/$APP_NAME
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
StandardOutput=append:$LOG_PATH/access.log
|
StandardOutput=append:$LOG_PATH/stdout.log
|
||||||
StandardError=append:$LOG_PATH/error.log
|
StandardError=append:$LOG_PATH/stderr.log
|
||||||
Environment=GIN_MODE=release
|
|
||||||
|
# 安全加固
|
||||||
|
NoNewPrivileges=true
|
||||||
|
ProtectSystem=strict
|
||||||
|
ProtectHome=true
|
||||||
|
ReadWritePaths=$APP_PATH $LOG_PATH
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# 设置权限
|
echo "==> 重新加载 systemd 并启动服务..."
|
||||||
echo "设置权限..."
|
systemctl daemon-reload
|
||||||
sudo chown -R www-data:www-data $APP_PATH
|
systemctl enable "$APP_NAME"
|
||||||
sudo chown -R www-data:www-data $LOG_PATH
|
systemctl restart "$APP_NAME"
|
||||||
sudo chmod 750 $APP_PATH/$APP_NAME
|
|
||||||
|
|
||||||
# 重载并启动
|
echo ""
|
||||||
echo "启动服务..."
|
echo "==> 安装完成!"
|
||||||
sudo systemctl daemon-reload
|
echo " 服务状态: systemctl status $APP_NAME"
|
||||||
sudo systemctl enable $APP_NAME
|
echo " 日志查看: journalctl -u $APP_NAME -f"
|
||||||
sudo systemctl start $APP_NAME
|
echo " 应用日志: tail -f $LOG_PATH/stdout.log"
|
||||||
|
|
||||||
echo "安装完成!"
|
|
||||||
echo "使用以下命令管理服务:"
|
|
||||||
echo " sudo systemctl status $APP_NAME"
|
|
||||||
echo " sudo journalctl -u $APP_NAME -f"
|
|
||||||
|
|||||||
+1
-1
Submodule sese-engine-ui updated: 5777561d9f...52c1b9de99
Reference in New Issue
Block a user