Linuxの自動化導入
14282 ワード
No.1自動配置gitプロジェクト
一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ
#!/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
No.2自動更新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
fi
No.3既存プロジェクトの自動配置
一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ
#!/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
No.4自動ロールバック項目
一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ一つ
#!/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
--各道の大神の指摘を歓迎して、転載してリンクを添付してください:https://www.cnblogs.com/leozhanggg/p/10917704.html