#!/bin/bash
java -jar myapp.jar & echo $! > ./pid.file &
Starts your app and saves the process id in a file
#!/bin/bash
kill $(cat ./pid.file)
Stops your app using the saved process id
start_silent.sh
#!/bin/bash
nohup ./start.sh > foo.out 2> foo.err < /dev/null &
If you need to start the app using ssh from a remote machine or a CI pipeline then use this script instead to start your app. Using start.sh directly can leave the shell to hang.
After eg. re/deploying your app you can restart it using:
sshpass -p password ssh -oStrictHostKeyChecking=no userName@www.domain.com 'cd /home/user/pathToApp; ./stop.sh; ./start_silent.sh'