人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動(dòng)態(tài)

Linux實(shí)現(xiàn)項(xiàng)目的自動(dòng)化部署

發(fā)布日期:2022-07-15 19:29 | 文章來源:站長之家

一、自動(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í)有所幫助,也希望大家多多支持本站。

海外服務(wù)器租用

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。

實(shí)時(shí)開通

自選配置、實(shí)時(shí)開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對(duì)1客戶咨詢顧問

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部