SpringBoot启动脚本

1、简单操作

1 nohup java -jar affair-data.jar --spring.profiles.active=prod > affair-data.log 2>&1 &

2、脚本操作

 1 #!/bin/bash
 2 #这里可替换为你自己的执行程序,其他代码无需更改
 3 APP_NAME=fudan-api.jar
 4 FUDAN_API_CONTAINER_PORT=8686
 5 
 6  
 7 #使用说明,用来提示输入参数
 8 usage() {
 9     echo "Usage: sh demo.sh [start|stop|restart|status]"
10     exit 1
11 }
12  
13 #检查程序是否在运行
14 is_exist() { 
15     pid=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}' `
16     #如果不存在返回1,存在返回0
17     if [ -z "${pid}" ]; then
18       return 1
19     else
20       return 0
21     fi
22 }
23  
24 #启动方法
25 start() {
26    is_exist
27    if [ $? -eq "0" ]; then
28      echo "${APP_NAME} is already running. pid=${pid} ."
29    else
30      nohup java -jar -DFUDAN_API_CONTAINER_PORT=$FUDAN_API_CONTAINER_PORT  $APP_NAME > fudan-api.log 2>&1 &
31    fi
32 }
33  
34 #停止方法
35 stop() {
36    is_exist
37    if [ $? -eq "0" ]; then
38      kill -9 $pid
39    else
40      echo "${APP_NAME} is not running"
41    fi
42 }
43  
44 #输出运行状态
45 status() {
46    is_exist
47    if [ $? -eq "0" ]; then
48      echo "${APP_NAME} is running. Pid is ${pid}"
49    else
50      echo "${APP_NAME} is not running."
51    fi
52 }
53  
54 #重启
55 restart() {
56    stop
57    start
58 }
59  
60 #根据输入参数,选择执行对应方法,不输入则执行使用说明
61 case "$1" in
62    "start")
63      start
64      ;;
65    "stop")
66      stop
67      ;;
68    "status")
69      status
70      ;;
71    "restart")
72      restart
73      ;;
74    *)
75      usage
76      ;;
77 esac
原文地址:https://www.cnblogs.com/dszazhy/p/14718340.html