在項(xiàng)目上線之后,采用Jenkins自動(dòng)化集成工具幫助我們自動(dòng)化部署項(xiàng)目,往往需要在服務(wù)器編寫Shell腳本來自動(dòng)更新項(xiàng)目维咸。
以下為我的一個(gè)腳本示例:
#!/bin/sh
cp_original="/home/app/jars/jenkins_update/store/jack.war"
cp_destination="/home/app/mj-store-test/webapps/"
project_path="/home/app/mj-store-test/"
log_path="/home/app/jars/jenkins_update/scripts/update_jack_log.txt"
cp_revert="/home/app/jars/jenkins_update/store/jack_revert.war"
cd ${project_path}
echo "$(date +%F%n%T)" > ${log_path}
echo "cd ${project_path}" >> ${log_path}
bin/shutdown.sh
echo "bin/shutdown.sh" >> ${log_path}
ps -ef | grep tomcat-mjstore | grep -v grep | cut -c 9-15 | xargs kill -9
echo "ps -ef | grep tomcat-mjstore | grep -v grep | cut -c 9-15 | xargs kill -9" >> ${log_path}
rm -rf webapps/mjstyle*
echo "rm -rf webapps/mjstyle*" >> ${log_path}
cp -f ${cp_original} ${cp_destination}
echo "cp -f ${cp_original} ${cp_destination}" >> ${log_path}
bin/startup.sh
echo "bin/startup.sh" >> ${log_path}
rm -f ${cp_revert}
mv ${cp_original} ${cp_revert}
Shell腳本編寫完成之后,還需要給予其可執(zhí)行權(quán)限:
chmod +x update.sh