123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #!/bin/bash
- # 配置参数
- JAVA_HOME="/usr/local/java/jdk";
- JAR_NAME="appservice.jar";
- JAR_PORT=8083
- JAVA_OPTS=" -server -Xmx1024m -Xms1024m -Duser.timezone=GMT+08 -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:MaxTenuringThreshold=15 -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=dump/ -XX:ErrorFile=hss_err_pid<pid>.log"
- # 检查应用进程号,保存在psid变量
- psid=0
- checkpid() {
- javaps=`$JAVA_HOME/bin/jps -l | grep "\<${JAR_NAME}\>"`
- if [ -n "$javaps" ]; then
- psid=`echo $javaps | awk '{print $1}'`
- else
- psid=0
- fi
- }
- # 启动应用
- start() {
- checkpid
- if [ $psid -ne 0 ]; then
- echo "================================"
- echo "warn: $JAR_NAME already started! (pid=$psid)"
- echo "================================"
- else
- echo -n "Starting $JAR_NAME ..."
- nohup $JAVA_HOME/bin/java -jar $JAVA_OPTS $JAR_NAME --server.port=$JAR_PORT >nohup.out 2>&1 &
- checkpid
- if [ $psid -ne 0 ]; then
- echo "(pid=$psid) [OK]"
- else
- echo "[Failed]"
- fi
- fi
- }
- # 停止应用
- stop() {
- checkpid
- if [ $psid -ne 0 ]; then
- echo -n "Stopping $JAR_NAME ...(pid=$psid) "
- kill -15 $psid
- if [ $? -eq 0 ]; then
- echo "[OK]"
- else
- echo "[Failed]"
- fi
- sleep 1
- checkpid
- if [ $psid -ne 0 ]; then
- stop
- fi
- else
- echo "================================"
- echo "warn: $JAR_NAME is not running"
- echo "================================"
- fi
- }
- case $1 in
- start)
- echo "start project......"
- start
- ;;
- stop)
- echo "stop project......"
- stop
- ;;
- restart)
- echo "restart project......"
- stop
- start
- ;;
- *)
- esac
- exit 0
|