Start / Stop script for springboot app on linux, with following features:

  1. Start script won’t create new instance if the app already running
  2. Run the app in background and forward all console output to “log.log”

1. Start Script

run.sh
#!/bin/bash if [ -f "./PID" ]; then echo "PID exists, app already running" else nohup java -jar ./MyApp-0.1-SNAPSHOT.jar > log.log 2>&1 & echo $! > PID fi

2. Stop Script

stop.sh
#!/bin/bash kill `cat ./PID` rm PID