SpringBoot部署脚本,拿走即用!
生活随笔
收集整理的這篇文章主要介紹了
SpringBoot部署脚本,拿走即用!
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一個可以直接拿來使用的shell腳本,適用于springboot項目
#!/bin/bash
# 這里可替換為你自己的執行程序,其他代碼無需更改,絕對路徑相對路徑均可。
# 若使用jenkins等工具遠程構建,則使用絕對路徑,下面的日志輸出路徑同!
APP_NAME=/root/webserver-0.0.1-SNAPSHOT.jar# 使用說明,用來提示輸入參數 僅在輸入錯誤時提示使用。
usage() {echo "Usage: sh 腳本名.sh [start|stop|restart|status]"exit 1
}#檢查程序是否在運行
is_exist(){pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `#如果不存在返回1,存在返回0 if [ -z "${pid}" ]; thenreturn 1elsereturn 0fi
}#啟動方法
start(){is_existif [ $? -eq "0" ]; thenecho "${APP_NAME} is already running. pid=${pid} ."elsenohup java -jar $APP_NAME > ./log.txt 2>&1 &echo "${APP_NAME} start success"fi
}#停止方法
stop(){is_existif [ $? -eq "0" ]; thenkill -9 $pidelseecho "${APP_NAME} is not running"fi
}#輸出運行狀態
status(){is_existif [ $? -eq "0" ]; thenecho "${APP_NAME} is running. Pid is ${pid}"elseecho "${APP_NAME} is NOT running."fi
}#重啟
restart(){stopstart
}#根據輸入參數,選擇執行對應方法,不輸入則執行使用說明
case "$1" in"start")start;;"stop")stop;;"status")status;;"restart")restart;;*)usage;;
esac
總結
以上是生活随笔為你收集整理的SpringBoot部署脚本,拿走即用!的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Docker容器的备份与恢复,Docke
- 下一篇: 淘宝获取单笔订单信息服务端调用API及流