76 lines
1.6 KiB
Bash
76 lines
1.6 KiB
Bash
#!/bin/bash
|
|
# 部署脚本
|
|
# 路径: /www/wwwroot/coolcoth.com/deploy.sh
|
|
|
|
# 配置项
|
|
SOURCE_DIR="/www/wwwroot/coolcoth.com"
|
|
PUBLIC_DIR="/www/wwwroot/coolcoth.com/public"
|
|
LOG_FILE="/www/wwwroot/coolcoth.com/deploy.log"
|
|
|
|
# 记录日志函数
|
|
log_message() {
|
|
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
|
echo "[$timestamp] $1" >> "$LOG_FILE"
|
|
}
|
|
|
|
# 主逻辑
|
|
log_message("开始部署...")
|
|
|
|
# 进入源码目录
|
|
cd "$SOURCE_DIR" || {
|
|
log_message("错误: 无法进入源码目录 $SOURCE_DIR")
|
|
exit 1
|
|
}
|
|
|
|
# 拉取最新代码
|
|
log_message("拉取最新代码...")
|
|
git pull origin main
|
|
if [ $? -eq 0 ]; then
|
|
log_message("代码拉取成功")
|
|
else
|
|
log_message("错误: 代码拉取失败")
|
|
exit 1
|
|
fi
|
|
|
|
# 安装依赖(如果需要)
|
|
# log_message("安装依赖...")
|
|
# npm install
|
|
# if [ $? -eq 0 ]; then
|
|
# log_message("依赖安装成功")
|
|
# else
|
|
# log_message("错误: 依赖安装失败")
|
|
# exit 1
|
|
# fi
|
|
|
|
# 构建项目(如果需要)
|
|
# log_message("构建项目...")
|
|
# npm run build
|
|
# if [ $? -eq 0 ]; then
|
|
# log_message("项目构建成功")
|
|
# else
|
|
# log_message("错误: 项目构建失败")
|
|
# exit 1
|
|
# fi
|
|
|
|
# 复制到运行目录(如果需要)
|
|
# log_message("复制到运行目录...")
|
|
# cp -r dist/* "$PUBLIC_DIR"/
|
|
# if [ $? -eq 0 ]; then
|
|
# log_message("文件复制成功")
|
|
# else
|
|
# log_message("错误: 文件复制失败")
|
|
# exit 1
|
|
# fi
|
|
|
|
# 重启服务(如果需要)
|
|
# log_message("重启服务...")
|
|
# systemctl restart nginx
|
|
# if [ $? -eq 0 ]; then
|
|
# log_message("服务重启成功")
|
|
# else
|
|
# log_message("错误: 服务重启失败")
|
|
# exit 1
|
|
# fi
|
|
|
|
log_message("部署完成!")
|
|
exit 0 |