1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| # !/bin/bash
APP_DIR="/data/apps/webmail" BIN_DIR="$APP_DIR" LOG_DIR="$APP_DIR/logs" LOG_FILE="$LOG_DIR/info.log" NEW_PRO="dist"
feishu_webhook="https://open.feishu.cn/open-apis/bot/v2/hook/token1" feishu_webhook2="https://open.feishu.cn/open-apis/bot/v2/hook/token2"
export TZ="Asia/Shanghai"
mkdir -p $BIN_DIR $LOG_DIR
# 推送到飞书 function push_to_feishu() {
content="$1"
cur_datetime=$(date +"%Y-%m-%d %H:%M:%S")
message="状态:${content}\n" message+="时间:${cur_datetime}"
read -r -d '' json_payload <<EOF { "msg_type": "text", "content": { "text": "${message}" } } EOF
echo ">>> JSON Payload: ${json_payload}"
#response=$(curl -H "Content-Type: application/json" -X POST -d "${json_payload}" "${feishu_webhook}") #echo ">>> 飞书响应: ${response} <<<" #response2=$(curl -H "Content-Type: application/json" -X POST -d "${json_payload}" "${feishu_webhook2}") #echo ">>> 飞书响应2: ${response2} <<<" }
cleanup_logs() { push_to_feishu "正在清理 15 天前的日志..." echo "正在清理 15 天前的日志..." >> $LOG_FILE find $LOG_DIR -type f -mtime +15 -exec rm -f {} \; push_to_feishu "日志清理完成..." echo "日志清理完成。" >> $LOG_FILE }
# 主逻辑 echo "======== 前端部署开始 $(date) ========" > $LOG_FILE push_to_feishu "打包完成" push_to_feishu "前端部署开始" BUILD_JAR_PATH=$(pwd) cd $APP_DIR || { echo "目录 $APP_DIR 不存在!" >> $LOG_FILE; exit 1; } rm -rf $APP_DIR/$NEW_PRO mv $BUILD_JAR_PATH/$NEW_PRO $BIN_DIR/ > $LOG_FILE 2>&1 push_to_feishu "正在移动前端项目,0表示成功,移动结果$?..."
fi cleanup_logs push_to_feishu "前端部署完成..." echo "======== 前端部署完成 $(date) ========" >> $LOG_FILE
|