Created
January 31, 2019 01:37
-
-
Save zacscoding/2913e53332ec0ba722de906e40e92e28 to your computer and use it in GitHub Desktop.
spring boot jar start shell script
This file contains hidden or 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
``` | |
#!/usr/bin/env bash | |
SCRIPTPATH=$( cd "$(dirname "$0")" ; pwd -P ) | |
WORKING_DIR=$( cd "${SCRIPTPATH}/../" ; pwd -P ) | |
VERSION="1.0" | |
JAR="MY-jar-"${VERSION}".jar" | |
# check server pid | |
function check_server_pid() { | |
local pid_file="$WORKING_DIR/server.pid" | |
if [[ -f "$pid_file" ]]; then | |
if [[ -s "$pid_file" ]]; then | |
local pid=$(cat ${pid_file}) | |
PID=$(ps -p ${pid} | tail -1 | grep -v grep | grep -v vi | grep -v PID | awk '{print $1}') | |
fi | |
else | |
PID=$(ps -ef | grep ${JAR} | grep -v grep | grep -v vi | grep -v PID | awk '{print $2}') | |
fi | |
} | |
check_server_pid | |
# check current user is root or not | |
if [[ "$(id -u)" = "0" ]]; then | |
echo "It can not be executed by root." 1>&2 | |
exit 1 | |
fi | |
# check override properties | |
function get_spring_config_location() { | |
local properties_file=$WORKING_DIR/application.yaml | |
if [[ -f "$properties_file" ]] | |
then | |
return "classpath:/application.yaml,$PROPERTIES_FILE" | |
else | |
return "classpath:/application.yaml" | |
fi | |
} | |
if [[ -z $PID ]]; then | |
nohup java -Xms512m -Xmx512m -jar ${WORKING_DIR}/${JAR} --spring_config_location=get_spring_config_location 1>> $WORKING_DIR/server.log 2>&1 & | |
PID=$! | |
echo $PID > $WORKING_DIR/server.pid | |
echo "Success to start ${JAR}" | |
echo "pid : "$PID | |
echo "tail -f ${WORKING_DIR}/server.log" | |
exit 0 | |
else | |
echo "Already ${JAR} is running" | |
exit 0 | |
fi | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment