Jar包启动脚本
#!/bin/bash
####################################################################################
### mail: zengfq_8008606252@163.com ###
### Blog address: https://www.gylinux.cn ###
### QQ: 315089363 ###
####################################################################################
ENV=dev
RUNNING_USER=root
ADATE=`date +%Y%m%d%H%M%S`
APP_NAME=jar包名
APP_HOME=`pwd`
dirname $0|grep "^/" >/dev/null
if [ $? -eq 0 ];then
APP_HOME=`dirname $0`
else
dirname $0|grep "^\." >/dev/null
retval=$?
if [ $retval -eq 0 ];then
APP_HOME=`dirname $0|sed "s#^.#$APP_HOME#"`
else
APP_HOME=`dirname $0|sed "s#^#$APP_HOME/#"`
fi
fi
if [ ! -d "$APP_HOME/logs" ];then
mkdir $APP_HOME/logs
fi
LOG_PATH=$APP_HOME/logs/$APP_NAME.out
GC_LOG_PATH=$APP_HOME/logs/gc-$APP_NAME-$ADATE.log
#JMX监控需用到
JMX="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1091 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
#JVM参数
JVM_OPTS="-Dname=$APP_NAME -Djeesuite.configcenter.profile=$ENV -Duser.timezone=Asia/Shanghai -Xms2046M -Xmx2046M -XX:PermSize=256M -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -Xloggc:$GC_LOG_PATH -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
JAR_FILE=$APP_NAME.jar
pid=0
start(){
checkpid
if [ ! -n "$pid" ]; then
# JAVA_CMD="nohup java -jar $JVM_OPTS $JAR_FILE > $LOG_PATH 2>&1 &"
# su - $RUNNING_USER -c "$JAVA_CMD"
nohup java -jar $JVM_OPTS $JAR_FILE > $LOG_PATH 2>&1 --xjar.keyfile=params.x &
echo "---------------------------------"
echo "启动完成,按CTRL+C退出日志界面即可>>>>>"
echo "---------------------------------"
sleep 2s
tail -f $LOG_PATH
else
echo "$APP_NAME is runing PID: $pid"
fi
}
status(){
checkpid
if [ ! -n "$pid" ]; then
echo "$APP_NAME not runing"
else
echo "$APP_NAME runing PID: $pid"
fi
}
checkpid(){
pid=`ps -ef |grep $JAR_FILE |grep -v grep |awk '{print $2}'`
}
stop(){
checkpid
if [ ! -n "$pid" ]; then
echo "$APP_NAME not runing"
else
echo "$APP_NAME stop..."
kill -9 $pid
fi
}
restart(){
stop
sleep 1s
start
}
case $1 in
start) start;;
stop) stop;;
restart) restart;;
status) status;;
*) echo "require start|stop|restart|status" ;;
esac
层级脚本
#!/usr/bin/bash
####################################################################################
### mail: zengfq_8008606252@163.com ###
### Blog address: https://www.gylinux.cn ###
### QQ: 315089363 ###
####################################################################################
#微服务日志路径调用变量 ###
LogAudience=/service/audience-service/log ###
LogsAudience=/service/audience-service/logs ###
LogUser=/service/user-service/log ###
LogsUser=/service/user-service/logs ###
LogsGateway=/service/gateway/logs ###
LogsImService=/service/im-service/logs ###
LogsLogistics=/service/logistics-service/logs ###
LogMall=/service/mall-service/log ###
LogsMall=/service/mall-service/logs ###
LogOrder=/service/order-service/log ###
LogsOrder=/service/order-service/logs ###
LogsPay=/service/pay-service/logs ###
LogsTestingd=/service/testingd-service/logs ###
#服务脚本启动路径###################################################################
StartPath1=/service/audience-service ###
StartPath2=/service/user-service ###
StartPath3=/service/gateway ###
StartPath4=/service/im-service ###
StartPath5=/service/logistics-service ###
StartPath6=/service/mall-service ###
StartPath7=/service/order-service ###
StartPath8=/service/pay-service ###
StartPath9=/service/testingd-service ###
####################################################################################
####################################################################################
set -x ####
clear ####
# 定义多个函数可以调用多次 ####
####################################################################################
Tailflogs1(){
echo -e "\033[34m******************1. 正常日志查看****************** \033[0m"
cat <
1. audience-service-info.log
2. audience-service.out
3. user-service-info.log
4. user-service.out
5. wmsx-gateway.out
6. im-service.out
7. logistics-service.out
8. mallinfo
9. mall-service.out
10. order-service-info.log
11. order-service.out
12. pay-service.out
13. testingd-service.out
EOF
echo -e "\033[34m*************************************************** \033[0m"
}
Tailflogs1
TailfEeeor2(){
echo -e "\033[33m*****************2. 错误日志查看******************* \033[0m"
cat <
15. audience-service-error.log
16. mall-service-mallerror.log
17. order-service-error.log
18. user-service-error.log
EOF
echo -e "\033[33m*************************************************** \033[0m"
}
TailfEeeor2
StartJar(){
echo -e "\033[32m******************3. 服务启动********************** \033[0m"
cat <
20. audience-service
21. user-service
22. wmsx-gateway
23. im-service
24. logistics-service
25. mall-service
26. order-service
27. pay-service
28. testingd-service
29. help
EOF
echo -e "\033[32m*************************************************** \033[0m"
}
StartJar
echo -e "\003"
read -p "欢迎加入微媒云播请选择: " software
case $software in
1)
clear
Tailflogs1
read -p "日志查看: " Tailflogs1
case $Tailflogs1 in
1)
tailf $LogAudience/info.log
;;
2)
tailf $LogsAudience/audience-service.out
;;
3)
tailf $LogUser/info.log
;;
4)
tailf $LogsUser/user-service.out
;;
5)
tailf $LogsGateway/wmsx-gateway.out
;;
6)
tailf $LogsImService/im-service.out
;;
7)
tailf $LogsLogistics/logistics-service.out
;;
8)
tailf $LogMall/mallinfo.log
;;
9)
tailf $LogsMall/mall-service.out
;;
10)
tailf $LogOrder/info.log
;;
11)
tailf $LogsOrder/order-service.out
;;
12)
tailf $LogsPay/pay-service.out
;;
13)
tailf $LogsTestingd/testingd-service.out
;;
14)
clear ;;
esac
;;
2)
TailfEeeor2
read -p "错误日志: " TailfEeeor2
case $TailfEeeor2 in
15)
tailf $LogAudience/error.log
;;
16)
tailf $LogMall/mallerror.log
;;
17)
tailf $LogOrder/error.log
;;
18)
tailf $LogUser/error.log
;;
19)
clear ;;
esac
;;
3)
StartJar
read -p "服务启动: " StartJar
case $StartJar in
20)
/bin/bash $StartPath1/audience-service.sh start
;;
21)
/bin/bash $StartPath2/user-service.sh start
;;
22)
/bin/bash $StartPath3/gateway-service.sh start
;;
23)
/bin/bash $StartPath4/im-service.sh start
;;
24)
/bin/bash $StartPath5/logistics-service.sh start
;;
25)
/bin/bash $StartPath6/mall-service.sh start
;;
26)
/bin/bash $StartPath7/order-service.sh start
;;
27)
/bin/bash $StartPath8/pay-service.sh start
;;
28)
/bin/bash $StartPath9/testingd-service.sh start
;;
29)
exit
esac
esac