Tuesday, 17 December 2013

Run a java application as a service (deamon) on linux

A simple solution is to create a script start.sh that runs Java through nohup and then stores the PID to a file:
nohup java -jar myapplication.jar > log.txt 2> errors.txt < /dev/null &
echo $PID > pid.txt
Then your stop script stop.sh would read the PID from the file and kill the application:
PID=$(cat pid.txt)
kill $PID
#Collected from stackoverflow

No comments:

Post a Comment