How to stop java application using a shell script
- by Fernando Moyano
I have a shell script, which is run under a opensuse linux, that starts a java application (under a jar), the script is:
#!/bin/sh
#export JAVA_HOME=/usr/local/java
#PATH=/usr/local/java/bin:${PATH}
#---------------------------------#
# dynamically build the classpath #
#---------------------------------#
THE_CLASSPATH=
for i in `ls ./lib/*.jar`
do
THE_CLASSPATH=${THE_CLASSPATH}:${i}
done
#---------------------------#
# run the application #
#---------------------------#
java -server -Xms512M -Xmx1G -cp ".:${THE_CLASSPATH}" com.package.MyApp > myApp.out 2>&0 &
This script is working fine.
Now, what I want, is to write a script to kill gracefully this app, something that allows me to kill it with the -15 argument from Linux kill command.
The problem, is that there will be many java applications running on this server, so I need to specifically kill this one.
Any help?
Thanks in advance,
Fernando