打包
将項目打好的包上傳至生産環境目錄
部署
建立目錄8001,8002等自己所需端口,将包放入8001同級目錄并執行腳本 ./service.sh copy ./service.sh start
- copy 将jar包複制至端口對應目錄
- start 按端口号啟動
- stop 停止項目
- status 項目狀态
腳本
#!/bin/sh
# 更換這裡的服務名為你的服務名
SERVICE=xxxx-0.0.1-SNAPSHOT
SERVICE_NAME=xxx
PORTS=(8001 8002 8003 8004 8005 8006 8007 8008 8009 8010)
copy(){
for i in ${PORTS[@]}
do
echo "starting copy file to ${i}"
\cp -rf $SERVICE.jar $i/
echo "finish copy file to ${i}"
done
}
start(){
for i in ${PORTS[@]}
do
echo "starting..."
# 設定調優參數和啟動日志輸出檔案
nohup java -jar $i/$SERVICE.jar --server.port= $i >$i/$SERVICE_NAME.log 2>&1 &
if [ $? -ne 0 ]
then
echo "start failed, please check the log!"
exit $?
else
echo $! > $i/$SERVICE$i.pid
echo "start success"
fi
done
}
stop(){
for i in ${PORTS[@]}
do
echo "stopping..."
kill -9 `cat $SERVICE$i.pid`
if [ $? -ne 0 ]
then
echo "stop failed, may be $SERVICE isn't running"
exit $?
else
rm -rf $i/$SERVICE$i.pid
echo "stop success"
fi
done
}
restart(){
stop&&start
}
status(){
num=`ps -ef | grep $SERVICE | grep -v grep | wc -l`
if [ $num -eq 0 ]
then
echo "$SERVICE isn't running..."
else
echo "$SERVICE is running..."
fi
}
case $1 in
start) start ;;
stop) stop ;;
restart) restart ;;
status) status ;;
*) echo "Usage:service.sh {start|stop|restart|status}" ;;
esac
exit 0