加入收藏 | 设为首页 | 会员中心 | 我要投稿 汽车网 (https://www.0577qiche.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

Linux实现项目的自动化布置

发布时间:2023-03-08 10:37:48 所属栏目:教程 来源:
导读:#!/bin/bash

# 清除项目进程和历史文件
pkill -f start.py
sleep 1
cd /root/automation |rm -rf testProduce/

# 获取项目最新git代码(前提服务器配置好git账户)
git clone git@dev.test.com:test_c
#!/bin/bash
  
# 清除项目进程和历史文件
pkill -f start.py
sleep 1
cd /root/automation |rm -rf testProduce/
  
# 获取项目最新git代码(前提服务器配置好git账户)
git clone git@dev.test.com:test_code/testProduce.git
  
# 启动项目
cd testProduce/
nohup /usr/python/bin/python3 start.py &
sleep 3
  
# 检查是否启动成功
pinfo=`pgrep -af start.py`
if [ -n $pinfo ]
then
  echo "Successfully!!!"
else
  echo "Failed!!!"
fi
自动化更新git项目

#!/bin/bash
  
# 切换至项目路径
cd /root/automation
  
# 检查项目是否有更新
gitinfo=`git pull`
if [[ "${gitinfo}" == "Already up-to-date." ]]
then
  echo "Already up-to-date."
else
  # 重启项目
  pkill -f start.py
  sleep 1
  nohup /usr/python/bin/python3 start.py &
  sleep 3
  
  # 检查是否启动成功
  pinfo=`pgrep -af start.py`
  if [ -n $pinfo ]
  then
    echo "Successfully!!!"
  else
    echo "Failed!!!"
  fi
自动化部署已有项目

#!/bin/bash
  
# 设置源服务器信息
username="root"
password="root"
host="10.22.33.44"
dir="/usr/local/app"
  
# 备份当前项目(以备回滚)
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
  
# 拷贝项目更新包
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
  
# 重启项目
echo "Restarting testProduce..."
sh testProduce/restart.sh
sleep 8
  
# 检查是否启动成功
pinfo=`pgrep -af testProduce.jar`
if [ -n $pinfo ]
then
  echo "Successfully!!!"
else
  echo "Failed!!!"
fi
  
:<<COMMENTBLOCK
  pkill -f testProduce.jar
COMMENTBLOCK
四、自动化回滚项目

#!/bin/bash
  
# 清除当前项目
echo "Clear..."
rm -rf testProduce* |cd bak
  
# 检查是否指定回滚版本(默认回滚上个版本,按日期排序,所以此路径不能有其他文件)
if [ -z $1 ]
then
  vs=`ls -l |sort -r |awk 'NR==2 {print $NF}'`
else
  vs=$1
fi
  
# 回滚项目
echo "Reset>>> $vs"
cd $vs |cp testProduce.tar.gz ../../
tar -zxvf testProduce.tar.gz |rm -f testProduce.tar.gz
  
# 重启项目
echo "Restarting testProduce..."
sh testProduce/restart.sh
sleep 8
  
# 检查是否启动成功
pinfo=`pgrep -af testProduce.jar`
if [ -n $pinfo ]
then
  echo "Successfully!!!"
else
  echo "Failed!!!"
fi

(编辑:汽车网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章