Problem: I have a java application that needs to run as a background process in Linux. The process needs to be started and shutdown with shell scripts.
Approach: We can use nohup utility in linux to run Java process in background. After starting the process write the process id into a file. kill the process during shutdown using process id.
Startup Script:
Shutdown Script:
Approach: We can use nohup utility in linux to run Java process in background. After starting the process write the process id into a file. kill the process during shutdown using process id.
Startup Script:
#Start java application as a background process nohup java -jar app.jar & #write the process id to file echo $! > PID
Shutdown Script:
#kills the background java process kill -9 `cat PID` #clean up the process ID file rm -rf PID
No comments:
Post a Comment