網(wǎng)站首頁 編程語言 正文
一、自動(dòng)化部署git項(xiàng)目
#!/bin/bash
# 清除項(xiàng)目進(jìn)程和歷史文件
pkill -f start.py
sleep 1
cd /root/automation |rm -rf testProduce/
# 獲取項(xiàng)目最新git代碼(前提服務(wù)器配置好git賬戶)
git clone git@dev.test.com:test_code/testProduce.git
# 啟動(dòng)項(xiàng)目
cd testProduce/
nohup /usr/python/bin/python3 start.py &
sleep 3
# 檢查是否啟動(dòng)成功
pinfo=`pgrep -af start.py`
if [ -n $pinfo ]
then
echo "Successfully!!!"
else
echo "Failed!!!"
fi
二、自動(dòng)化更新git項(xiàng)目
#!/bin/bash
# 切換至項(xiàng)目路徑
cd /root/automation
# 檢查項(xiàng)目是否有更新
gitinfo=`git pull`
if [[ "${gitinfo}" == "Already up-to-date." ]]
then
echo "Already up-to-date."
else
# 重啟項(xiàng)目
pkill -f start.py
sleep 1
nohup /usr/python/bin/python3 start.py &
sleep 3
# 檢查是否啟動(dòng)成功
pinfo=`pgrep -af start.py`
if [ -n $pinfo ]
then
echo "Successfully!!!"
else
echo "Failed!!!"
fi
三、自動(dòng)化部署已有項(xiàng)目
#!/bin/bash
# 設(shè)置源服務(wù)器信息
username="root"
password="root"
host="10.22.33.44"
dir="/usr/local/app"
# 備份當(dāng)前項(xiàng)目(以備回滾)
echo "Saving testProduce..."
now=`date +%Y%m%d%H%M%S`
cd $dir | mkdir -p bak/$now
tar -czvf testProduce.tar.gz testProduce/ testProduce-web/
mv testProduce.tar.gz bak/$now/testProduce.tar.gz
# 拷貝項(xiàng)目更新包
echo "Copying testProduce..."
/usr/bin/expect<<EOF
set timeout 10
spawn scp -r $username@$host:$dir/testProduce-web/ $dir
expect "*password:"
send "$password\r"
expect eof
spawn scp -r $username@$host:$dir/testProduce/lib $dir/testProduce/
expect "*password:"
send "$password\r"
expect eof
spawn scp $username@$host:$dir/testProduce/testProduce.jar $dir/testProduce/
expect "*password:"
send "$password\r"
expect eof
#interact
EOF
# 重啟項(xiàng)目
echo "Restarting testProduce..."
sh testProduce/restart.sh
sleep 8
# 檢查是否啟動(dòng)成功
pinfo=`pgrep -af testProduce.jar`
if [ -n $pinfo ]
then
echo "Successfully!!!"
else
echo "Failed!!!"
fi
:<<COMMENTBLOCK
pkill -f testProduce.jar
COMMENTBLOCK
四、自動(dòng)化回滾項(xiàng)目
#!/bin/bash
# 清除當(dāng)前項(xiàng)目
echo "Clear..."
rm -rf testProduce* |cd bak
# 檢查是否指定回滾版本(默認(rèn)回滾上個(gè)版本,按日期排序,所以此路徑不能有其他文件)
if [ -z $1 ]
then
vs=`ls -l |sort -r |awk 'NR==2 {print $NF}'`
else
vs=$1
fi
# 回滾項(xiàng)目
echo "Reset>>> $vs"
cd $vs |cp testProduce.tar.gz ../../
tar -zxvf testProduce.tar.gz |rm -f testProduce.tar.gz
# 重啟項(xiàng)目
echo "Restarting testProduce..."
sh testProduce/restart.sh
sleep 8
# 檢查是否啟動(dòng)成功
pinfo=`pgrep -af testProduce.jar`
if [ -n $pinfo ]
then
echo "Successfully!!!"
else
echo "Failed!!!"
fi
原文鏈接:https://www.cnblogs.com/chenyablog/p/15219545.html
相關(guān)推薦
- 2022-06-18 C語言深入講解宏的定義與使用方法_C 語言
- 2022-06-09 Python字符串的索引與切片_python
- 2022-06-21 C語言超全面講解函數(shù)的使用方法上_C 語言
- 2022-04-08 c++11中std::move函數(shù)的使用_C 語言
- 2022-06-09 Entity?Framework?Core基于數(shù)據(jù)模型創(chuàng)建數(shù)據(jù)庫_實(shí)用技巧
- 2022-08-23 Python+Selenium實(shí)現(xiàn)在Geoserver批量發(fā)布Mongo矢量數(shù)據(jù)_python
- 2021-11-27 nginx中的兩個(gè)模塊的proxy_pass的區(qū)別解析_nginx
- 2022-09-15 windows中cmd下添加、刪除和修改靜態(tài)路由實(shí)現(xiàn)_DOS/BAT
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支