jar启动脚本

jar启动脚本,第1张

linuxjava工程启动脚本
#!/bin/sh

######################
#  jar包启动停停止脚本 #
######################

# jar包存放的路径
prog_path="/to/path"

# jar包名称
prog_name="xxxx-0.0.1"

# 执行命令
exec="java -Xms1024m -Xmx1024m -jar $prog_path""/""$prog_name"".jar"

#查看进程号
prog_pid=`ps -ef | grep $prog_name | grep -v grep | cut -c 10- | cut -c -5|sed 's/ //g'`
prog_time=`date --date='0 days ago' "+%Y/%m/%d %H:%M:%S"`

#  获取进程号
get_pid(){
    prog_pid=`ps -ef | grep $prog_name | grep -v grep | cut -c 10- | cut -c -5|sed 's/ //g'`
    echo $prog_pid
}

start(){
   prog_pid=$(get_pid);
   if [ -n "$prog_pid" ]; then
     echo ${prog_time} "$prog_name (pid:$prog_pid) ,and it's running."
     return 1
   fi
   echo ${prog_time} "$prog_name Starting ..."
   echo $exec
   nohup $exec >/dev/null 2>&1 &
   
   sleep 10

   prog_pid=$(get_pid);   
   if [ -z "$prog_pid" ]; then
    echo ${prog_time} "Start $prog_name is failed."
    return 2
   fi  
   echo ${prog_time} "$prog_name (pid:$prog_pid) is running."
   echo ${prog_time} "Start $prog_name is ok."
   return 0   
}

stop(){
   echo ${prog_time} "$prog_name Stoping..."
   prog_pid=$(get_pid);
   if [ -n "$prog_pid" ]; then
    echo ${prog_time} "Found $prog_name (pid:$prog_pid)"	
    kill -9 $prog_pid
   fi

   sleep 3

   prog_pid=$(get_pid);
   if [ -n "$prog_pid" ]; then	
    echo ${prog_time} "Stop $prog_name is failed."
    return 1
   fi
   echo ${prog_time} "Stop $prog_name is ok."
   return 0
}

status(){
   prog_pid=$(get_pid);
   if [ -n "$prog_pid" ]; then
    echo ${prog_time} "$prog_name (pid:$prog_pid) is running..."
    return 0
   fi
   echo ${prog_time} "$prog_name is stoped."
   return 1
}

restart(){
    stop
    start
}

# 启停函数调用
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status
    ;;
  restart)
    restart
    ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart}"
    exit 2
esac

exit $?

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/926777.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存