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

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


#!/usr/bin/env bash
#
# Filename:     manage.sh
# Revision:     1.1
# Date:         2018-09-22
# Author:       Nestor(Peng.niu)
# Email:        niu8753@163.com
# 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值