Skip to content

Instantly share code, notes, and snippets.

@daviddefco
Created April 26, 2018 12:01
Show Gist options
  • Save daviddefco/d7fb077dd33eba97765c76123ee5a6b9 to your computer and use it in GitHub Desktop.
Save daviddefco/d7fb077dd33eba97765c76123ee5a6b9 to your computer and use it in GitHub Desktop.
Boot bash script to launch SpringBoot executable JARs
#!/bin/bash
usage="boot <JAR file name> <start|stop|restart>"
startProcess() {
echo "Starting JAR ${jar_filename}"
process_pid=`pgrep -f "^java.*${jar_filename}"`
if [[ ${process_pid} ]]
then
echo "JAR is already running with PID ${process_pid}. Stop it before starting or restart it."
exit -1
fi
java -jar ${jar_filename} &
sleep 5
echo "JAR started"
}
stopProcess() {
echo "Stopping JAR ${jar_filename}"
process_pid=`pgrep -f "^java.*${jar_filename}"`
if ! [[ ${process_pid} ]]
then
echo "No JAR ${jar_filename} is executing."
exit -1
fi
kill -9 ${process_pid}
echo "JAR stopped"
}
if [[ ${#} -lt 1 ]]
then
echo ${usage}
exit -2
fi
jar_filename=$1
boot_command=$2
case $boot_command in
-start|start)
startProcess
;;
-stop|stop)
stopProcess
;;
-restat|restart)
echo "Restarting JAR ${jar_filename}"
stopProcess
startProcess
;;
*)
echo ${usage}
exit -2
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment