Linux實(shí)現(xiàn)項(xiàng)目的自動(dòng)化部署
更新時(shí)間:2022年07月08日 10:39:14 作者:小旭2021
這篇文章介紹了Linux實(shí)現(xiàn)項(xiàng)目自動(dòng)化部署的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
一、自動(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到此這篇關(guān)于Linux實(shí)現(xiàn)項(xiàng)目自動(dòng)化部署的文章就介紹到這了。希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
騰訊云(ubuntu)下安裝 nodejs + 實(shí)現(xiàn) Nginx 反向代理服務(wù)器
本文將介紹如何給騰訊云上的 Ubuntu Server 12.04 LTS 64位主機(jī)安裝 node 及 nginx,并簡(jiǎn)單配置反向代理。2016-11-11
詳解Ubuntu 16.04 pycharm設(shè)置桌面快捷啟動(dòng)方式
本篇文章主要介紹了Ubuntu 16.04 pycharm設(shè)置桌面快捷啟動(dòng)方式,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-12-12
Ubuntu Server 14.04升級(jí)Ubuntu Server 16.04
這篇文章主要介紹了 Ubuntu Server 14.04升級(jí)Ubuntu Server 16.04,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2016-12-12
Ubuntu18.04 一鍵升級(jí)Python所有第三方包 及安裝python包的方法
pip 是 Python 包管理工具,該工具提供了對(duì)Python 包的查找、下載、安裝、卸載的功能。這篇文章給大家介紹Ubuntu18.04 一鍵升級(jí)Python所有第三方包 ,感興趣的朋友一起看看吧2019-10-10

