Created
July 15, 2015 06:22
-
-
Save aconstantin/5297c134585af1e93968 to your computer and use it in GitHub Desktop.
Sample Spring Boot control.sh script
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/sh | |
PROJECT_NAME=some-project | |
BASE_PATH=${HOME}/${PROJECT_NAME} | |
PID_FILE=$BASE_PATH/application.pid | |
SB_PORT=8080 | |
SB_PROFILES="foo,bar" | |
SB_JAVA=java | |
SB_JAR="${BASE_PATH}/${PROJECT_NAME}.jar" | |
SB_LOG="${BASE_PATH}/${PROJECT_NAME}.log" | |
SB_ARGS="--server.port=${SB_PORT} --spring.profiles.active=${SB_PROFILES}" | |
SB_VMARGS="-Djava.security.egd=file:/dev/./urandom" | |
pid_of_spring_boot() { | |
cd $BASE_PATH | |
pid=`cat application.pid` | |
return $pid | |
} | |
start() { | |
echo $"Starting $PROJECT_NAME: " | |
cd $BASE_PATH | |
nohup $SB_JAVA $SB_VMARGS -jar $SB_JAR $SB_ARGS >> $SB_LOG 2>&1 & | |
while [ ! -f $PID_FILE ] | |
do | |
echo "appliation.pid does not exist yet, sleep 1 second" | |
sleep 1 | |
done | |
echo "appliation.pid is available, so is the process" | |
PID=`cat ${PID_FILE}` | |
echo "$PROJECT_NAME (pid $PID) is running..." | |
} | |
stop() { | |
echo -n "Stopping $PROJECT_NAME: " | |
cd $BASE_PATH | |
if [ -f $PID_FILE ] | |
then | |
echo "application.pid exists, will kill process" | |
PID=`cat application.pid` | |
kill $PID | |
while [ -f $PID_FILE ] | |
do | |
echo "appliation.pid still exists, sleep 1 second" | |
sleep 1 | |
done | |
echo "appliation.pid is gone, so is the process" | |
fi | |
} | |
status() { | |
cd $BASE_PATH | |
if [ -f $PID_FILE ] | |
then | |
echo "application.pid exists, will kill process" | |
PID=`cat ${PID_FILE}` | |
echo "$PROJECT_NAME (pid $PID) is running..." | |
return 0 | |
fi | |
echo "$PROJECT_NAME is stopped" | |
return 3 | |
} | |
# See how we were called. | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
status | |
;; | |
restart) | |
stop | |
start | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|restart|status}" | |
exit 1 | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment