I'm having a problem with a sh script. I'm working on a sh script that allows me to execute a java script in background, and before executing it, check if it is currently running.
The code is here:
## START ##
start)
echo $" "
echo $"Checking for agents running, wait please..."
MI_PS=$(ps -ef|grep $JAR_NAME |awk '{print $2, $7}' |egrep -v "00:00:00" |awk '{print$1}')
sleep 1
for kill_process in $MY_PS; do
/bin/kill -9 $kill_process
done
# Verificamos que se ha realizado correctamente
VERIFY=$?
if [ "$?" = "0" ]; then
echo -n "Jar instance stopped correctly"
echo -ne "\033[0;32m [OK] \033[0m"
echo $" "
else
echo -n "Jar instance stopped incorrectly"
echo -ne "\033[0;31m [Error] \033[0m"
echo ""
echo "It is required to kill process "$MY_PS" manually."
echo "Ask your administrator"
echo $" "
fi
echo $" "
echo -n "Starting Jar"
echo $" "
nohup java -Dprops.dir=conf -jar func.jar &
echo $" "
echo -n "Jar running"
echo -ne "\033[0;32m [OK] \033[0m"
echo $" "
;;
The problem I'm having is that when setting the nohup ... & in order to execute in background jar file is not doing anything. If I write:
java -Dprops.dir=conf -jar func.jar
Then it works. My jar file is using a quartz library (scheduler library for Java), I don't know if some of you knows if there is any incompatibility between nohup and quartz...
Or maybe there is somekind of problem with setting JVM variables ( -Dprops.dir=conf )
Thanks!
I figured out my problem, it turned out to not be related to Quartz at all. I was using SwingUtilities.invokeLater() for some cheap asynchronous tasks. For some reason the program was working only if I had xwindows running on my desktop, but would terminate with no error logged when I shut down my computer (also shutting down xwindows). The fix was to start the program with -Djava.awt.headless=true
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.