Skip to content

Instantly share code, notes, and snippets.

@Elyorbe
Created January 11, 2022 07:31
Show Gist options
  • Save Elyorbe/37a6775de93b8e22d0686ab64589cc06 to your computer and use it in GitHub Desktop.
Save Elyorbe/37a6775de93b8e22d0686ab64589cc06 to your computer and use it in GitHub Desktop.
Sample shell script file to start and stop spring boot jar files
PID_FILE="$(pwd)/api-server.pid"
JAVA_HOME=/usr/lib/jvm/java-11/
JVM_OPTIONS="-Xms512M -Xmx1G -XX:+UseParallelGC"
JAR_FILE="api-server.jar"
SPRING_CONF_DIR="-Dspring.config.additional-location=$(pwd)/conf/ "
SPRING_ACTIVE_PROFILE="-Dspring.profiles.active=dev "
SPRING_OPTIONS="$SPRING_CONF_DIR$SPRING_ACTIVE_PROFILE"
case "$1" in
start)
nohup $JAVA_HOME/bin/java $SPRING_OPTIONS $JVM_OPTIONS -jar $JAR_FILE > run.out 2>&1 &
echo "$!" > $PID_FILE
echo STARTED
;;
stop)
if [ -f $PID_FILE ]; then
kill `cat $PID_FILE`
echo STOPPED
rm $PID_FILE
rm "$(pwd)/run.out"
else
echo "It seems the process isn't running."
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment