写了个启动程序, 调优jvm的脚本
#!/bin/bash MEM=`free -m | grep Mem | awk '{print int($2 * 90 / 100)}'` JAVA_OPTS="-server \ -Xmx${MEM}m -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:ParallelGCThreads=4\ " APP_HOME=`dirname $(pwd)` APP_JAR_NAME="idfa.web-1.0.jar" PID_FILE="$APP_HOME/pid.file" pid=0 commond="$JAVA_OPTS -jar $APP_HOME/libs/$APP_JAR_NAME" #commond="nohup java -jar $APP_HOME/libs/$APP_JAR_NAME 1 >> $APP_HOME/nohup.log 2>&1 &" getpid() { if [ -f "${PID_FILE}" ]; then pid=`cat ${PID_FILE}` echo "----------------------------------------" echo "pid file with ${pid}" echo "----------------------------------------" pid_count=`ps aux | grep idfa.web-1.0 | grep " ${pid} " | grep -v grep | wc -l` if [ ${pid_count} -eq 0 ]; then echo "${pid} dose not exist!" rm -rf ${PID_FILE} pid=0 fi else pid=0 fi } startup(){ getpid echo "=======================================" if [ ${pid} -ne 0 ]; then echo "${APP_JAR_NAME} already started(PID=${pid})" echo "=======================================" else echo "Starting ${APP_JAR_NAME}" ulimit -c unlimited cd ${APP_HOME} echo $commond nohup java $commond & echo $! > ${PID_FILE} sleep 1 getpid if [ ${pid} -ne 0 ]; then echo "(PID=${pid})...[Success]" echo "=======================================" else echo "[Failed]" echo "=======================================" exit -1 fi cd - fi } shutdown(){ getpid echo "=======================================" if [ ${pid} -ne 0 ]; then echo "Stopping ${APP_JAR_NAME}(PID=${pid})..." kill -15 ${pid} getpid while [ ${pid} -ne 0 ] do sleep 1 getpid done echo "[Success]" echo "=======================================" else echo "${APP_JAR_NAME} is not running" echo "=======================================" fi } shutdown_force(){ getpid echo "=======================================" if [ ${pid} -ne 0 ]; then echo "Stopping ${APP_JAR_NAME}(PID=${pid})..." kill -9 ${pid} getpid while [ ${pid} -ne 0 ] do sleep 1 getpid done echo "[Success]" echo "=======================================" else echo "${APP_JAR_NAME} is not running" echo "=======================================" fi } status(){ getpid echo "=======================================" if [ ${pid} -ne 0 ]; then echo "${APP_JAR_NAME} is running(PID=${pid})" echo "=======================================" else echo "${APP_JAR_NAME} is not running" echo "=======================================" fi } case "$1" in start) startup ;; stop) shutdown ;; force) shutdown_force ;; restart) $0 stop sleep 1 $0 start ;; status) status ;; *) exit 1 esac
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。