脚本编辑复制的时候一定要 注意回车的方式LINUX 是LF
#!/bin/bash
#JAR 包名称
JAR_NAME=eureka-1.0-SNAPSHOT
Suffix=jar
APP_NAME=$JAR_NAME.$Suffix
CUR_SHELL_DIR=`pwd`
LOG_PATH=$CUR_SHELL_DIR/logs/$JAR_NAME.out
#启动参数
SPRING_PROFILES_ACTIV="-Dspring.profiles.active=test"
# 启动内存参数
#JAVA_MEM_OPTS=" -server -Xms1024m -Xmx1024m -XX:PermSize=128m"
JAVA_MEM_OPTS=" -server -Xms256m -Xmx512m -XX:PermSize=128m"
#使用说明
usage() {
echo "sh eureka.sh [start|stop|restart|status]"
exit 1
}
#检查程序是否在运行
is_exist(){
pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `
#如果不存在返回1,存在返回0
if [ -z "$pid" ]; then
return 1
else
return 0
fi
}
#启动方法
start(){
is_exist
if [ $? -eq "0" ]; then
echo -e "ERROR: The $APP_NAME already started and the PID is $pid ."
else
#日志备份
nowdate=`date +%Y%m%d`
rm -f $LOG_PATH.*
mv $LOG_PATH $LOG_PATH.$nowdate
echo "Starting the $APP_NAME ..."
nohup java $JAVA_MEM_OPTS $SPRING_PROFILES_ACTIV -jar $APP_NAME >> $LOG_PATH 2>&1 &
tail -f $LOG_PATH
fi
}
#停止方法
stop(){
is_exist
if [ $? -eq "0" ]; then
echo "Stoping the $APP_NAME ...."
kill -9 $pid
echo "${APP_NAME} is stoped"
else
echo "ERROR: The ${APP_NAME} does not started"
fi
}
#输出运行状态
status(){
is_exist
if [ $? -eq "0" ]; then
echo "The $APP_NAME is running and the PID is $pid"
else
echo "The $APP_NAME is stopped."
fi
}
#重启
restart(){
stop
start
}
#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac