不求甚解

此博客为个人学习之用,如与其他作品雷同,纯属巧合。
随笔 - 156, 文章 - 1, 评论 - 2, 阅读 - 10万

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

Q:jar包启动脚本备份

Posted on   三年三班王小朋  阅读(15)  评论(0编辑  收藏  举报

jarServer.sh

复制代码
#!/bin/bash
#APP_NAME必须配置。 

cd `dirname $0`
cd ..
DEPLOY_DIR=`pwd`
APP_HOME=$DEPLOY_DIR/lib
LOG_FILE=$DEPLOY_DIR/logs/stdin.out
#启动的程序名称
APP_NAME=digmax-ta404.jar

# 配置文件生产环境
#PROFILE=pro
#java虚拟机启动参数
JAVA_OPTS="-Xms1024m -Xmx2048m -Dlog4j2.formatMsgNoLookups=true -Dfastjson.parser.safeMode=true -Doracle.jdbc.fanEnabled=false -DMY_PASSWORD=Yhpt1qaz "

#**************************
#(函数)判断程序是否已启动
#初始化psid变量
#****************************
psid=0
checkpid() {
 JPID=$(ps -ef | grep "$APP_HOME/$APP_NAME" | grep -v grep | awk '{ print $2 }')
   if [ -z "$JPID" ]
   then
   psid=0
   else
   psid=$JPID
   fi
}  

#**************************
#启动程序
#****************************
start() {
checkpid
echo -n "Starting $APP_NAME ..."
nohup java -jar $JAVA_OPTS $APP_HOME/$APP_NAME > $LOG_FILE 2>&1 &
while [ $psid -lt 1 ]; do
 echo -e ".\c"
 sleep 1
 checkpid
 if [  $psid -gt 0  ]; then
       echo -e "\n$APP_NAME already started! (pid=$psid)"
       break
 fi
 done
}
#*****************************
#停止程序
#*****************************

stop() {
  checkpid
  if [ $psid -ne 0 ]; then
  echo -n "Stopping $APP_NAME ...(pid=$psid) "
  kill -9  $psid
  if [ $? -eq 0 ]; then
        echo "[OK]"
  else
    echo "[Failed]"
  fi
  checkpid
  if [ $psid -ne 0 ]; then  
        stop    
  fi
  else
    echo "$APP_NAME is not running"
  fi
}

#****************************
#检查程序运行状态
#****************************

status() {  
   checkpid
   if [ $psid -ne 0 ];  then  
      echo "$APP_NAME is running! (pid=$psid)" 
   else  
      echo "$APP_NAME is not running"  
   fi 
}

log(){
  tail -500f $LOG_FILE
}

#参数取值示例:{start|stop|restart|status}  
case "$1" in
'start')
    start
    ;;
'stop')
    stop
    ;;
'restart')
    stop
    sleep 1
    start
    ;;
'status')
    status
    ;;
'log')
    log
    ;;
 *)
    echo "Usage: $0 {start|stop|restart|status|log}"
    exit 1
esac
exit 0
us() {  
   checkpid  
  
   if [ $psid -ne 0 ];  then  
      echo "$APP_NAME is running! (pid=$psid)"  
   else  
      echo "$APP_NAME is not running"  
   fi  
}  

#********************************
#检查脚本的第二个参数($2),是否添加了额外的JVM参数
#读取脚本的第一个参数($1),进行判断  
#参数取值示例:{start|stop|restart|status}  
###################################  
case "$1" in
   'start')
      start
      ;;
   'stop')
     stop
     ;;
   'restart')
     stop
     start
     ;;
   'status')
     status
     ;;
  *)
     echo "Usage: $0 {start|stop|restart|status}"
     exit 1
esac
exit 0
复制代码

 

相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示