1847710 Members
6170 Online
110265 Solutions
New Discussion

init.d script problem

 
T Dockery
Advisor

init.d script problem

I'm having an oddity with an /sbin/init.d startup script for Tomcat 4.0.3 on an HP-UX 11.0 system. I can run the script from the command line, and it works fine. But at system reboot, it gets run, returns with an OK, and the tomcat gets far enough along to write a little bit of initialization information to its logs, but then the process disappears without any error. Note in the listing below that I am using nohup and a sleep to start Tomcat.

Ideas?

-Tom

-------------------------------
#!/sbin/sh

CATALINA_HOME=/opt/tomcat
JAVA_HOME=/opt/java
export CATALINA_HOME
export JAVA_HOME

PATH=/sbin:/usr/sbin:/usr/bin
export PATH


rval=0
set_return() {
x=$?
if [ $x -ne 0 ]; then
echo "ERROR CODE $x"
rval=1
fi
}


case $1 in
start_msg)
echo "Start Tomcat"
;;

stop_msg)
echo "Stopping Tomcat"
;;

'start')
if [ -x $CATALINA_HOME/bin/startup.sh ] ; then
nohup nice $CATALINA_HOME/bin/startup.sh > /tmp/tomcat.out 2>&1 &
sleep 10
set_return
else
rval=2
fi
;;

'stop')
if [ -x $CATALINA_HOME/bin/shutdown.sh ] ; then
$CATALINA_HOME/bin/shutdown.sh &
set_return
else
rval=2
fi
;;

*)
echo "usage: $0 {start|stop}"
;;
esac

exit $rval
7 REPLIES 7
Robert Gamble
Respected Contributor

Re: init.d script problem

Tom,

When you say you run it from the command line, do you mean you run '/sbin/init.d/tomcat start' or 'nohup nice $CATALINA_HOME/bin/startup.sh' ?

Running the init script as root can make in difference in troubleshooting.

If you are already doing that, try introducing some logging into the Tomcat applcation, perhaps modifying the startup.sh for some 'echo "half-way_done"' kind of things. Perhaps another shell script that startup.sh calls...

If you start it manually and it works, does the init stop script work ?

Hope these suggestions help!
T Dockery
Advisor

Re: init.d script problem

Robert,

I mean I run /sbin/init.d/tomcat start as root, and it works correctly. And yes, /sbin/init.d/tomcat stop works as expected.

The Tomcat startup gets as far as launching the Java process, so adding more "got heres" in the script isn't likely to give me anything more. The log output from the Tomcat java process varies; if I extend the sleep from 10 seconds to 120 seconds, I get a bit more, but all normal processing, no hint of a reason for failure.

It appears that the process is getting a SIGHUP or SIGTERM, but nohup should prevent that. Somehow this appears to me to be the nub of the problem.

FYI, this is Tomcat 4.0.3 directly from the Apache Jakarta site, as we need a common install for HP-UX, Solaris and Windows. The startup.sh script execs catalina.sh, which invokes java with Tomcat's org.apache.catalina.startup.Bootstrap class.

-Tom
Robert Gamble
Respected Contributor

Re: init.d script problem

Do you really need the nohup ? The startup.sh should complete in a reasonable time. I know it shouldn't have anything to do with it, but at this point, it is worth a try.

Since you point out the script runs comepletly, but the resulting processes do not live long, it seems to point to some type of environment entity is killing it, which could be a parent process dying and bring (somehow) down the nohup'd & backgrounded processes.

Play with removing the nohup and '&'.

Hopefully someone with better scripting experience will read this and point out what we are forgetting to consider. ;)
T Dockery
Advisor

Re: init.d script problem

Thanks for the idea, but same result without the nohup. Which reminds me, this script has been working for several months on a pair of old E55 systems, after I added the nohup and the sleep. It is now failing on L-class machines. Both types of systems are running HP-UX 11.0. The obvious differences are 32-bit vs 64-bit installations, and much faster processors.
GK_5
Regular Advisor

Re: init.d script problem

Is the enviornment set properly for tomcat to start at startup. When you run it as root the environment is set and it works.
IT is great!
T Dockery
Advisor

Re: init.d script problem

Yes, the environment is correct. From the script:

CATALINA_HOME=/opt/tomcat
JAVA_HOME=/opt/java
export CATALINA_HOME
export JAVA_HOME

PATH=/sbin:/usr/sbin:/usr/bin
export PATH

The startup.sh script takes care of anything else.
T Dockery
Advisor

Re: init.d script problem

Interestingly, I tried replacing the startup line that begins with nohup with the following:

at now << EOD > /tmp/tomcat.out 2>&1
nice $CATALINA_HOME/bin/startup.sh >> /tmp/tomcat.out 2>&1 &
EOD

Works like a charm. But why does "at" work when "nohup" doesn't?