启动服务: #!/bin/bash CPU_COUNT=`cat /proc/cpuinfo | grep processor | wc -l` MEM_OPTS="-Xms1024m -Xmx1024m -XX:PermSize=256m -Dlogging.config=config/log4j2.xml -server" GC_OPTS="-XX:ParallelGCThreads=$CPU_COUNT -XX:SurvivorRatio=1 -XX:-UseAdaptiveSizePolicy -XX:+CMSClassUnloadingEnabled -XX:CMSInitiatingOccupancyFraction=80 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -Xloggc:logs/gc.log" echo "JMX参数: "$JMX_OPTS echo "内存参数: "$MEM_OPTS echo "垃圾收集参数: "$GC_OPTS # 打印到startup.log if [ ! -d logs ]; then mkdir logs ; fi java $MEM_OPTS -jar lib/test-1.0.0-SNAPSHOT.jar --spring.config.name=test >> logs/start.out 2>&1 & pid=$! echo $pid>.pid echo "test bd 启动成功"
停止服务:
#!/bin/bash jar_pid=`ps -ef|grep -v grep | grep 'lib/teat-SNAPSHOT.jar'|awk '{ print $2 }'` echo $jar_pid if [ ! -n "$jar_pid" ]; then echo 'test bd 没有运行' else kill -9 $jar_pid echo 'kill' $jar_pid echo 'test bd 关闭成功' fi