shell 脚本发布前后端代码
shell 脚本发布前后端代码
- 1、发布前端
- 2、发布后端
1、发布前端
#! /bin/bashif [ ! $1 ]
thenecho "this command needs 1 parameters"exit
fiif [ -d "/usr/local/nginx/html/xxxx-$1" ]
thenecho "file exists: /usr/local/nginx/html/xxxx-$1, please check input parameters"exit
fiif [ ! -f "~/xxxx.zip" ]
thenecho "file not exists: ~/xxxx.zip"exit
fiecho "start version updating..."echo "starting back old web static files..."
mv xxxx xxxx-back-$1echo "unzip new web static files..."
unzip ~/xxxx.zip -d /usr/local/nginx/htmlecho "version update finished!"
2、发布后端
#! /bin/bashif [ ! $1 ]
thenecho "this command needs 1 parameters"exit
fiif [ -f "/home/apache-tomcat-8.5.84/webapps/xxxx.war.$1back" ]
thenecho "file exists: /home/apache-tomcat-8.5.84/webapps/xxxx.war.$1back, please check input parameters"exit
fiif [ ! -f "~/xxxx.war" ]
thenecho "file not exists: ~/xxxx.war"exit
fiecho "start version updating..."echo "shutting down Tomcat server..."
/home/apache-tomcat-8.5.84/bin/shutdown.sh
sleep 15s
netstat -nptl
echo "Tomcat server shut down."echo "starting back war..."
mv /home/apache-tomcat-8.5.84/webapps/xxxx.war /home/apache-tomcat-8.5.84/webapps/xxxx.war.$1backecho "deleting old webApp file archive..."
rm -rf /home/apache-tomcat-8.5.84/webapps/xxxxecho "copying new version webApp to Tomcat server..."
cp ~/xxxx.war /home/apache-tomcat-8.5.84/webappsecho "restarting Tomcat server..."
/home/apache-tomcat-8.5.84/bin/startup.shsleep 15s
netstat -nptlecho "version update finished!"
参考: Shell脚本编程30分钟入门