CentOS 7 spring 打包后生产的jar 文件启动脚本

以下仅供参考。
有问题欢迎留言,共同进步!


#!/usr/bin/env bash
#
# Filename:     manage.sh
# Revision:     1.1
# Date:         2018-09-22
# Author:       Nestor(Peng.niu)
# Email:        [email protected]
# Description:  The Script is for the operation management of the manage application, including
#               start stop and restart, and provides the function of viewing the application log.
# Notes:        For CentOS 7+ only. Sprint Jar.
# Copyright:    2018 (c) Nestor.
# Version:      1.0
#               The first script provides a simple service statup/stop/restart.
# Version:      1.1
#               The second script adds specification writting and optimizes the startup, issues 
#               after the service is stopped, further adjusting the variable definition.

# System environment variable settings
export LANG="zh_CN.utf8"
export JAVA_HOME=/data/app/jdk1.8.0_181

# Set the jar package startup parameters
JAVA_OPTS="-jar -Xms512m -Xmx512m -Duser.timezone=GMT+08"
ENV_TYPE="--spring.profiles.active=test"
# Set the application package absolute path
APP_INFO="/data/app/pangu-manager/*.jar"
# Parsing app parameters
APP_NAME=$(basename $APP_INFO)
APP_PATH=$(dirname $APP_INFO)
APP_LOG=$APP_PATH/$(echo $APP_PATH| awk -F '/' '{print $NF}').log


# Instructions for use, prompting the user for input parameters
usage() {
  echo $"Usage: $0 { start|stop|restart|status|logs }"
  retval=1
}

# Check if the app is running
check_running() {
  service_pid=$(ps -ef|grep java|grep $APP_NAME|awk '{print $2}')
  # The existence process returns 0,otherwise it returns 1
  if [ -z $service_pid ]; then
    return 1
  else
    return 0
  fi
}

# Launch application
start() {
  echo $"Starting the $APP_NAME service..."
  check_running
  if [ "$?" -eq "0" ]; then
    echo $"$APP_NAME is already running, Pid is $service_pid"
  else
    $JAVA_HOME/bin/java $JAVA_OPTS $APP_INFO $ENV_TYPE> $APP_LOG 2>&1 &
  fi
}

# Stop application
stop() {
  echo $"Stopping the $APP_NAME service..."
  check_running
  if [ "$?" -eq "0" ]; then
    kill -9 $service_pid
    echo $"$APP_NAME is stopped!"
  else
    echo $"$APP_NAME had been stopped!"
  fi
}

# Display application running status
status() {
  check_running
  if [ "$?" -eq "0" ]; then
    echo $"$APP_NAME is running. Pid is $service_pid"
  else
    echo $"$APP_NAME is not running."
  fi
}

# Restart application service
restart() {
  stop
  start
}

# Display the running log of the service
logs() {
  if [ -f $APP_LOG ]; then
    tail -100f $APP_LOG
  else
    echo $"$APP_LOG is not exist..."
  fi
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  status)
    status
    ;;
  logs)
    logs
    ;;
  *)
    usage
    ;;
esac

猜你喜欢

转载自blog.csdn.net/youduweiren/article/details/82814100