Linux start stop restart springboot jar package script

#!/bin/bash
# Here can be replaced with your own program execution
APP_NAME=app-1.0.0.jar
# Instructions for prompt input parameters
usage() {
   echo "Usage: sh app.sh [start|stop|restart|status]"
   exit 1
}
  
# Check program is running
is_exist(){
   pid = `ps -ef | grep $ APP_NAME | grep -v grep | awk '{print $ 2}'`
   # 1 if there is no return, there is return 0 
   if [ -z "${pid}" ]; then
     return 1
   else
     return 0
    be
   }
  
# Start method specified path needs to be modified
start(){
   is_exist
   if [ $? -eq "0" ]; then
     echo "${APP_NAME} is already running. pid=${pid} ."
   else
     nohup java -jar /home/admin/zjh/$APP_NAME > /home/admin/zjh/proprietor-app.log 2>&1 &
     echo "${APP_NAME} start success"
   be
}
  
Stop method #
stop(){
  is_exist
  if [ $? -eq "0" ]; then
   kill -9 $pid
  else
   echo "${APP_NAME} is not running"
  be
}
  
# Output running state
status(){
 is_exist
  if [ $? -eq "0" ]; then
   echo "${APP_NAME} is running. Pid is ${pid}"
  else
   echo "${APP_NAME} is NOT running."
 be
}
  
# Reboot
restart(){
 stop
 start
}
  
# According to the input parameter, performing the corresponding selected method is executed instructions do not enter
case "$1" in
 "start")
 start
 ;;
 "stop")
 stop
 ;;
 "status")
 status
 ;;
 "restart")
 restart
 ;;
 *)
 usage
 ;;
esac

 

Guess you like

Origin www.cnblogs.com/zhangjiahao/p/12511895.html