Created
October 4, 2018 06:18
-
-
Save lonly197/0ffcc0564e4bc30a7ce13ad57c8db60e to your computer and use it in GitHub Desktop.
The script for manage the spring boot app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set App Name | |
AppName="bumblebee-api" | |
# Set Version | |
Version="1.0.0" | |
# Set Jar Package File Name | |
SpringBoot="$AppName-$Version.jar" | |
# Set The Home Path | |
HomePath="/opt/bumblebee" | |
# Set The Full Path For Jar Package | |
Jar="${HomePath}/app/${SpringBoot}" | |
# Set Active Profice | |
Profice="prod" | |
# Or Set The Config File Path | |
Config="${HomePath}/config/application-${Profice}.properties" | |
# Set The Log Path | |
Log="${HomePath}/logs/${AppName}.log" | |
# Set The Log Size | |
LogMaxSize=10240000 | |
if [ "$1" = "" ]; | |
then | |
echo -e "\033[0;31m 未输入操作名 \033[0m \033[0;34m {start|stop|restart|status|log} \033[0m" | |
exit 1 | |
fi | |
if [ "$SpringBoot" = "" ]; | |
then | |
echo -e "\033[0;31m 未输入应用名 \033[0m" | |
exit 1 | |
fi | |
function start() | |
{ | |
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l` | |
if [ $count != 0 ];then | |
echo "$SpringBoot is running..." | |
else | |
echo "Start $SpringBoot success..." | |
nohup java -Dspring.config.location=${Config} -jar ${Jar} --name="$AppName" --spring.profiles.active=${Profice} > ${Log} ./ 2>&1 & | |
current_date=`date -d "-1 day" "+%Y%m%d"` | |
split -b $LogMaxSize -d -a 4 ${Log} | |
fi | |
} | |
function stop() | |
{ | |
echo "Stop $SpringBoot" | |
boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'` | |
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l` | |
if [ $count != 0 ];then | |
kill $boot_id | |
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l` | |
boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'` | |
kill -9 $boot_id | |
fi | |
} | |
function restart() | |
{ | |
stop | |
sleep 2 | |
start | |
} | |
function status() | |
{ | |
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l` | |
if [ $count != 0 ];then | |
echo "$SpringBoot is running..." | |
else | |
echo "$SpringBoot is not running..." | |
fi | |
} | |
function log() | |
{ | |
if [ ! -f "${Log}" ]; then | |
echo "Not Found $AppName.log" | |
else | |
tail -f ${Log} | |
fi | |
} | |
function remote_debug() { | |
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l` | |
if [ $count != 0 ];then | |
echo "$SpringBoot is running..." | |
else | |
echo "Debug $SpringBoot success..." | |
nohup java -Dspring.config.location=${Config} -Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8889 -jar ${Jar} --name="$AppName" --spring.profiles.active=${Profice} > ${Log} ./ 2>&1 & | |
current_date=`date -d "-1 day" "+%Y%m%d"` | |
split -b $LogMaxSize -d -a 4 ${Log} | |
fi | |
} | |
function debug() | |
{ | |
stop | |
sleep 2 | |
remote_debug | |
} | |
case $1 in | |
start) | |
start;; | |
stop) | |
stop;; | |
restart) | |
restart;; | |
status) | |
status;; | |
log) | |
log;; | |
debug) | |
debug;; | |
*) | |
echo -e "\033[0;31m Usage: \033[0m \033[0;34m sh $0 {start|stop|restart|status|log|debug} {SpringBootJarName} \033[0m | |
\033[0;31m Example: \033[0m | |
\033[0;33m sh $0 start esmart-test.jar \033[0m" | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment