#!/bin/bash
# 程序包目录
APP_HOME=/home/xloan/data/management/
# 程序包名
APP_NAME=xloan-management-1.0.jar
# 程序日志文件目录
APP_LOG_PATH=/home/xloan/data/management/logs/
# 程序日志文件名
APP_LOG_NAME=show.log
# 程序启动参数
JAVA_OPTIONS=" -Xms2048m -Xmx2048m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintHeapAtGC -Xloggc:./logs/app-gc-%t.log -XX:+UseG1GC -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=50M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./logs/app-oom-dump.hprof "
# 关闭程序等待时间(单位:秒)
SHUTDOWN_WAIT_TIME=30
# 使用说明, 用来提示输入参数
usage() {
echo "Usage: sh 执行脚本.sh [start|stop|restart|status]"
exit 1
}
# 检查程序是否运行中
is_exist() {
pid=` ps -ef | grep java | grep $APP_NAME | grep -v grep | awk '{print $2}' `
if [ -z "${pid}" ]; then
return 1
else
return 0
fi
}
# 启动程序
start() {
is_exist
if [ $? -eq "0" ]; then
echo -e "\n>>> ${APP_NAME} is already running. PID=${pid}<<<"
else
nohup java $JAVA_OPTIONS -jar $APP_HOME$APP_NAME > $APP_LOG_PATH$APP_LOG_NAME 2>&1 &
is_exist
if [ $? -eq "0" ]; then
echo -e "\n>>> ${APP_NAME} started. PID=${pid}<<<"
fi
fi
}
# 停止程序
stop() {
is_exist
if [ $? -eq "0" ]; then
kill $pid
let kwait=$SHUTDOWN_WAIT_TIME
count=0
until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
do
echo -n -e "\n\e[00;31mwaiting for processes to exit\e[00m"
sleep 1
let count=$count+1
done
if [ $count -gt $kwait ]; then
echo -n -e "\n\e[00;31mkilling processes didn't stop after $SHUTDOWN_WAIT_TIME seconds\e[00m"
kill -9 $pid
fi
echo -e "\n${APP_NAME} stoped."
else
echo -e "\n${APP_NAME} is not running"
fi
}
# 查看状态
status() {
is_exist
if [ $? -eq "0" ]; then
echo -e "\n${APP_NAME} is running. PID=${pid}"
else
echo -e "\n${APP_NAME} is not running."
fi
}
# 重启
restart() {
stop
sleep 3
start
}
# 选项
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac
Java 启动脚本
最新推荐文章于 2024-06-26 09:09:40 发布