Skip to content

Instantly share code, notes, and snippets.

@zacscoding
Created January 31, 2019 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zacscoding/2913e53332ec0ba722de906e40e92e28 to your computer and use it in GitHub Desktop.
Save zacscoding/2913e53332ec0ba722de906e40e92e28 to your computer and use it in GitHub Desktop.
spring boot jar start shell script
```
#!/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