jar的启动脚本
#!/bin/sh
RED='\E[1;31m' # 红
GREEN='\E[1;32m' # 绿
YELOW='\E[1;33m' # 黄
BLUE='\E[1;34m' # 蓝
PINK='\E[1;35m' # 粉红
SBLUE='\E[1;36m' # 天蓝
RES='\E[0m' # 清除颜色
PROJECT_NAME="xxxxxxx"
isExist(){
pid=$(ps -ef | grep ${PROJECT_NAME} | grep -v "grep" | awk '{print $2}')
if [ -z "${pid}" ]; then
return 0
else
return 1
fi
}
start(){
isExist
if [ $? -eq "0" ]; then
echo -e "${SBLUE}INFO${RES} ${PROJECT_NAME} is starting ......"
nohup java -jar -Xms1G -Xmx2G -Xss1G ${PROJECT_NAME} --spring.profiles.active=prod > /dev/null 2>&1 &
echo -e "${SBLUE}INFO${RES} ${PROJECT_NAME} startup success"
else
echo -e "${YELOW}WARN${RES} ${PROJECT_NAME} is running, pid=${pid} "
fi
}
stop(){
isExist
if [ $? -eq "0" ]; then
echo -e "${YELOW}WARN${RES} ${PROJECT_NAME} is not running ......"
else
echo -e "${SBLUE}INFO${RES} ${PROJECT_NAME} is running, pid=${pid}, prepare kill it "
kill -9 ${pid}
echo -e "${SBLUE}INFO${RES} ${PROJECT_NAME} has been successfully killed ......"
fi
}
restart(){
stop
sleep 2
start
}
case "$1" in
"start")
start
;;
"stop")
stop
;;
"restart")
restart
;;
*)
echo "please enter the correct commands: "
echo "such as : sh startup.sh [ start | stop | restart ]"
;;
esac