说明文档 txt
#让文件具有可执行的权限
chmod 777 tools.sh
第一种方式
执行命令
tools.sh start
停止
tools.sh stop
第二种方式
执行
./start.sh
停止
./stop.sh
#产看防火墙端口 开启端口
firewall-cmd --query-port=9704/tcp
firewall-cmd --add-port=9704/tcp --permanent
firewall-cmd --reload
#!/bin/bash
#配置java环境变量,如有可把此处注释掉
#export JAVA_HOME=/home/travel/jdk1.8.0_101
#export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#export PATH=$JAVA_HOME/bin:$PATH
#项目名称,请改成自己jar包名称,不要带.jar
APP_NAME=$(ls sensitive-word-admin.jar)
APP_PID=0
DIR=$(cd $(dirname $0); pwd)
echo $DIR
cd $DIR
getPid(){
local temppid=`ps aux | grep java | grep $APP_NAME | grep -v grep | awk '{print $2}'`
if [ -n "$temppid" ]; then
APP_PID=`echo $temppid | awk '{print $1}'`
else
APP_PID=0
fi
}
start(){
getPid
if [ "$APP_PID" -ne 0 ]; then
echo "$APP_NAME already started(PID=$APP_PID)"
else
echo "starting $APP_NAME..."
BUILD_ID=dontKillMe nohup java -server -Xmx1000M -Xms200M -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+DisableExplicitGC -Djava.net.preferIPv4Stack=true -Djava.security.egd=file:/dev/./urandom -Duser.timezone=Asia/Shanghai -jar $DIR/$APP_NAME > $DIR/log.log 2>&1 &
getPid
if [ "$APP_PID" -ne 0 ]; then
echo "(PID=$APP_PID)...success"
else
echo "app $APP_NAME start fail"
fi
fi
}
stop(){
getPid
if [ "$APP_PID" -ne 0 ]; then
echo "stopping $APP_name(PID=$APP_PID)..."
kill -9 $APP_PID
if [ $? -eq 0 ]; then
echo "$APP_NAME stopped"
else
echo "$APP_NAME stop failed."
fi
getPid
if [ $APP_PID -ne 0 ]; then
stop
fi
else
echo "$APP_NAME is not running."
fi
}
restart(){
stop
start
}
status(){
getPid
if [ $APP_PID -ne 0 ]; then
echo "$APP_NAME is running...(PID=$APP_PID)"
else
echo "$APP_NAME is not running"
fi
}
#if [ "$(id -u)" -eq 0 ]; then
# echo "$APP_NAME must not be run as root!"
# exit 1
#fi
case "$1" in
start)
start
exit 0
;;
stop)
stop
exit 0
;;
restart)
stop
start
exit 0
;;
status)
status
exit 0
;;
**)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
评论区