编写shell脚本,分为两个脚本,一个底层shell(startMt.sh),一个Web层脚本(startApi.sh)
一. 脚本
底层startMt.sh脚本如下:
#!/bin/bash
# 构建web
#read appname
appname="robinbootService"
echo "input="$appname
PID=$(ps -ef | grep $appname | grep -v grep | awk '{print $2}')
# 遍历杀掉 pid
for var in ${PID[@]};
do
echo "loop pid= $var"
kill -9 $var
done
echo "kill $appname success"
cd /Users/sunww/Documents/JAVA/robinson/RobinBoot
mvn -Dmaven.test.skip=true clean package
echo "build robinbootService-0.0.1-SNAPSHOT.jar success"
cp /Users/sunww/Documents/JAVA/robinson/RobinBoot/RobinBootService/target/robinbootService-0.0.1-SNAPSHOT.jar /Users/sunww/Documents/JAVA/WebApp
echo "cp robinbootService/webapps ok!"
# sh /usr/local/tomcat/bin/startup.sh
java -jar /Users/sunww/Documents/JAVA/robinson/RobinBoot/RobinBootService/target/robinbootService-0.0.1-SNAPSHOT.jar
echo "robinbootService startup success"
echo "start $appname success"
Web层脚本startApi.sh 如下:
#!/bin/bash
# 构建MT
#read appname
appname="robinBootWeb"
echo "input="$appname
PID=$(ps -ef | grep $appname | grep -v grep | awk '{print $2}')
# 遍历杀掉 pid
for var in ${PID[@]};
do
echo "loop pid= $var"
kill -9 $var
done
echo "kill $appname success"
cd /Users/sunww/Documents/JAVA/robinson/RobinBootWeb
mvn -Dmaven.test.skip=true clean package
echo "build robinBootWeb-0.0.1-SNAPSHOT.jar success"
cp /Users/sunww/Documents/JAVA/robinson/RobinBootWeb/target/robinBootWeb-0.0.1-SNAPSHOT.jar /Users/sunww/Documents/JAVA/WebApp
echo "cp robinBootWeb/webapps ok!"
# sh /usr/local/tomcat/bin/startup.sh
java -jar /Users/sunww/Documents/JAVA/robinson/RobinBootWeb/target/robinBootWeb-0.0.1-SNAPSHOT.jar
echo "robinBootWeb startup success"
echo "start $appname success"
二 启动工程
先启动底层,再启动上层
执行 sh startMt.sh
执行 sh startApi.sh
用postMan访问,测试通过 :