<返回更多

liunx中jar包启动脚本

2022-05-05    热爱技术的小张
加入收藏
#!/bin/sh
#
# Appctrl	This shell script takes care of starting and stopping
#		the VccpDataServer (vccpdsctrl).
#
##########
# jar包存放的位置
prog_path="/usr/local/app/admin"
# jar包名称
prog_name="admin-1.1.0"
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
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 ..."
   #export JAVA_HOME=/home/javahome
   #export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
   #export PATH=$PATH:$JAVA_HOME/bin
   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
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status
    ;;
  restart)
    restart
    ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart}"
    exit 2
esac

exit $?
声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>