#!/bin/bash
# Created By: ZP
BUILD_ID=dontkillme
PROG=admin
APP_NAME=/data/check-server.jar
PIDFILE=/var/run/check-server.pid
LOGFILE=/data/log.file
Date=$(date "+%Y-%m-%d %H:%M:%S")
ACTIVE=test
NACOS_ADDR=localhost:8848
JAVA_OPT="-XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -Xms256m -Xmx256m -Xmn128m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC"
status() {
if [ -f $PIDFILE ]; then
PID=$(cat $PIDFILE)
if [ ! -x /proc/${PID} ]; then
return 1
else
return 0
fi
else
return 1
fi
}
case "$1" in
start)
status
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "$PIDFILE exists, process is already running or crashed"
exit 1
fi
echo "Starting $PROG ..."
#nohup java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=10914 -jar $APP_NAME > $LOGFILE 2>&1 &
nohup java $JAVA_OPT -jar $APP_NAME --spring.profiles.active=$ACTIVE --nacos.server-addr=$NACOS_ADDR > $LOGFILE 2>&1 &
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "$Date $PROG is started [OK]"
echo $! > $PIDFILE
exit 0
else
echo "Stopping $PROG"
rm -f $PIDFILE
exit 1
fi
;;
stop)
status
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "$Date Shutting down $PROG"
kill -9 `cat $PIDFILE`
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
rm -f $PIDFILE
else
echo "Failed to stopping $PROG"
fi
fi
;;
status)
status
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
PID=$(cat $PIDFILE)
echo "$PROG is running ($PID)"
else
echo "$PROG is not running"
fi
;;
restart)
sh $0 stop
sh $0 start
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
;;
esac
chmod 777 run.sh
运行命令
sh run.sh start
sh run.sh stop
网友评论