Apache tomcat startup script not booting at startup.

I copied the script from an AskUbuntu post -

#!/bin/bash

### BEGIN INIT INFO
# Provides:        tomcat7
# Required-Start:  $network
# Required-Stop:   $network
# Default-Start:   2 3 4 5
# Default-Stop:    0 1 6
# Short-Description: Start/Stop Tomcat server
### END INIT INFO

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

start() {
 sh /usr/share/tomcat7/bin/startup.sh
}

stop() {
 sh /usr/share/tomcat7/bin/shutdown.sh
}

case $1 in
  start|stop) $1;;
  restart) stop; start;;
  *) echo "Run as $0 <start|stop|restart>"; exit 1;;
esac

The script can be started manually, but it doesn't execute on bootup.

Could it be because I've to change the "PATH=/sbin:/bin:/usr/sbin:/usr/bin " ?
I am using Tomcat6 though.

Everything is the same, I have only modified the start and stop variables to suit my install directory as follows :

start() {
 sh /home/drg/Desktop/apache/bin/startup.sh
}

stop() {
 sh /home/drg/Desktop/apache/bin/shutdown.sh
}

Please post your environment; operating system, version, etc.

To make anything start at boot time you (or the install routine) will need to enter it in a startup script somewhere (eg, a file in /etc/rc3.d), unless you're running an O/S that's clairvoyant you will need to tell it what to do.

Oops sorry forgotten about that.

OS : LinuxMint 16 64bit
Environment : Cinnamon ?

I added the relevant symlinks in the rc.* directories via the following commands :

chmod 755 /etc/init.d/tomcat7 
update-rc.d tomcat7 defaults

Yep, so you obviously know more than enough to fix your problem.

You said that you can start it manually so you can decide where in the boot order it should start and put the same command into rc3 script.

Reboot the system to check whether it starts okay or errors out.

No, I am not familiar with Linux bash scripting and the boot order like you said =/.

I simply followed instructions I found online, but it didn't work.

update-rc.d tomcat7 defaults
The above code should result in the tomcat7 script being set the correct boot order automatically ?

Well I'm not familiar with LinuxMint 16 64bit but the multi-user startup scripts are usually in /etc/rc3.d (or perhaps in your O/S /etc/rc.d).

Take a look in there and list the files present. Is there a Tomcat? Use grep to search for it. If the command you used entered the required script you should see it (or at least a link to the file elsewhere).

If all else fails you could simply create a file SnnTomcat for example and put your Apache start command in there (where nn is a number setting the appropriate position in the boot sequence). Make the script executable.

I expect another member who knows LinuxMint better will respond and help you out shortly.

The problem might also be the init level, type who -r to know what is your default level... then be sure the start link is in that rc.*d and put the stop in one level lower...

The first question that comes to mind is "have you looked at your various system and error log files to see if there are any clues there?"

Or have you considered adding a simple logging statement to your script to test to see what is going on when the script executes during boot time (or if it is even being executed all all)?

My experience is that logging (printing) is just about the most valuable debugging tool available.

1 Like
who -r 

returns run-level 2.

Under /etc/rc2.d , I have a S20tomcat7 script symlink inside. It didn't boot up =/

I tried slowing down its boot sequence by changing S20 to S90 , but it still doesn't boot..

if you want to start tomcat during booting do entry in /etc/rc.local

write your commands in rc.local file and reboot.

Oh yeah, this is the error I found in the boot logs..

sh: 0: Can't open /home/drg/Desktop/Linux/bin/startup.sh

Hmm why is this so ? The startup.sh has 755 perms and both owner and root is drg.

Try rebooting the system and checking Tomcat is not started.

Then whilst logged in as root, enter the command manually:

 
 # /etc/rc2.d/S20tomcat7 start
  

(Actually, you probably won't need the "start" argument, that's probably inside the S20tomcat7)

Now if it falls over you should see the error message(s).

Here is an example of rc.local which is running from 2 years on my server, if your tomcat starts only with sudo then its permission issue.

$ cat /etc/rc.local 
#!/bin/sh -e

# Start Tomcat 
JAVA_HOME="/usr/lib/jvm/jdk1.7.0_10"
JAVA_OPTS="-Djava.awt.headless=true"
CATALINA_PID="/usr/local/www/html/TOMCAT_DEMO/tomcat/webapps/UI_PID"
export JAVA_HOME JAVA_OPTS CATALINA_PID
exec /usr/local/www/html/TOMCAT_DEMO/tomcat/bin/catalina.sh start


exit 0

I tried posting the same script into /etc/rc.local , but it doesn't work. The boot log shows the echo message in the tomcat init script.

Run as $0 <start|stop|restart> 

On the other hand, if anyone can interpret this error from my boot logs for the rc scripts, it will be greatly appreciated.

sh: 0: Can't open /home/drg/Desktop/Linux/bin/startup.sh

How are you getting on with solving this?

Simplistically.......

You installed this package using a documented procedure.
You can start Tomcat manually. Good!!!
The procedure created a script in /etc/rc2.d/S20tomcat7 but it doesn't run at boot time.

As per my post #12 you can test this manually to see any errors.

Pay particular attention to VBE's comment about run levels.
It could be that the script in rc2.d is the stop script, and the start script is in rc3.d, I don't know LinuxMint. Perhaps rc2.d is start and rc1.d is stop.

Take a look around and see.
Then, logged in as root you should be able to start and stop Tomcat from the command line using these scripts. Post any errors.