Score:0

unable to start java using shell script from /etc/rc.loal file

gi flag

i have a java based web application and using Apache server.

once centos reboots java process not running again even existing java process killing and for that i created a script to start apache, cassandra and java process. apche server and cassandra starting but java not starting

for debugging i added echos in my script and appending echo to a file and am able to see the all echo's.

i tried these changes:

API_start.sh in /root path

#!/bin/bash
echo '111111' >> /root/temp.txt
service cassandra start

service httpd start
echo '2222222' >> /root/temp.txt
prid=$(ps aux| egrep '[A]PI_Controller.jar' | awk '{print $2}')
echo $prid >> /root/temp.txt

if [ -z "$prid" ]
then
        echo "No process to kill"
else
        kill -9 $prid
        echo "Successfully service stopped"
fi
echo '33333333' >> /root/temp.txt
pridold=$(ps aux| egrep '[B]lacklist.jar' | awk '{print $2}')
echo $pridold >> /root/temp.txt

if [ -z "$pridold" ]
then
        echo "No process to kill"
else
        kill -9 $pridold
        echo "Successfully service stopped old jar file"
fi
echo '444444444' >> /root/temp.txt
nohup java -Djsse.enableSNIExtension=false -jar API_Controller.jar &
echo '5555555555' >> /root/temp.txt

echo "Successfully service started"

/etc/rc.local file (changed to execute mode)

#!/bin/bash
touch /var/lock/subsys/local
nohup sh  /root/API_start.sh &

after rebooting centos i got prints like below in temp.txt

111111
2222222

33333333

444444444
5555555555

if i run API_start.sh manually from /etc/ java able to staring but i need to do it automatically.

please help me where i am doing wrong since i am new to shell script

Thank you

michael avatar
ru flag
might I also recommend logging the output of the `java` command, e.g., `java > /var/log/some_logfile.log 2>&1 </dev/null` (note I'm adding the option to close `stdin` but that's unrelated to capturing output and just there because it's common w/ `nohup`). I'm guessing you'll have to set at least `JAVA_HOME` (i.e.: `export JAVA_HOME=/path/to/java_home`, such that `java` is `$JAVA_HOME/bin/java`) and possibly other env vars that might be necessary for the application to run (eg `$LD_LIBRARY_PATH`? but I'm just guessing; these are in your env when you run it manually but not for startup scripts)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.