Tomcat 9 Service on Centos 7 won’t start up at system boot

centos7systemdtomcat9

I'm not very experienced with Linux generally, so please forgive me if this is obvious to you.

I have done a large number of searches on various combinations of keywords, but can't find a solution to this problem.

I have installed command line only (core) CentOS 7 on a virtual machine.

I have installed java and downloaded tomcat 9.0.14 (I know that's not the latest version). I have set up tomcat to run as a service, using systemd, that is, I have created a file:

/etc/systemd/system/tomcat.service

I had to revise this post about 15 times before the submission form stopped thinking this was spam, so I had to remove a lot of information I originally wanted to include like what's in my service.tomcat file. Sorry. I'd love to include more detail, but the form just won't let me.

It is the only instance of Tomcat on the Linux server. It is installed in /opt/tomcat/apache-tomcat-9.0.14, but I have created a symbolic link named "latest" so it can be referenced as /opt/tomcat/latest.

Tomcat starts properly when I run the startup script manually, i.e:

cd /opt/tomcat/latest/bin
sudo ./startup.sh

When I do so, it properly responds and I can see the landing page using a browser on another computer.

I can also start up tomcat as a service – manually starting that service using:

sudo systemctl start tomcat

If I do so, then I can see tomcat working and using:

sudo systemctl status tomcat

says that it's working. I can also visit the landing page when tomcat is started this way. So it will start as a service, if I manually start the service with the above command.

The problem is that when I boot up the machine, tomcat doesn't start. I don't think that I've simply failed to reference the service, rather, I believe it might be failing (but I'm not 100% certain):

If I reboot the computer, tomcat doesn't start.
If I then go:

sudo systemctl status tomcat -l

I get this:

tomcat.service - Apache Tomcat Web Application Container
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2020-05-27 14:47:27 AEST; 3min 14s ago
Process: 1147 ExecStart=/opt/tomcat/latest/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 1168 (code=exited, status=1/FAILURE)

May 27 14:47:26 CentOS-7-NoGUI-Virgin systemd[1]: Starting Apache Tomcat Web Application Container...
May 27 14:47:27 CentOS-7-NoGUI-Virgin systemd[1]: Started Apache Tomcat Web Application Container.
May 27 14:47:27 CentOS-7-NoGUI-Virgin systemd[1]: tomcat.service: main process exited, code=exited, status=1/FAILURE
May 27 14:47:27 CentOS-7-NoGUI-Virgin systemd[1]: Unit tomcat.service entered failed state.
May 27 14:47:27 CentOS-7-NoGUI-Virgin systemd[1]: tomcat.service failed.

Based on the fact that it says tomcat failed, I don't think that the problem is that I've not told CentOS to start the service. Rather, I think it's trying to start the service, but it's not working.

If I then manually do:

sudo systemctl start tomcat

I get no text returned, but subsequently if I do this:

sudo systemctl status tomcat -l

it shows tomcat is running. I'd love to include the exact output of the command, but I had to remove that too in my many revisions of this to get the submission form not to think this was spam.

I believe I have properly set up the tomcat service to start at system boot time, by doing this:

sudo systemctl daemon-reload

sudo systemctl enable tomcat

I tried using journalctl -xe to see if I could learn why the service was failing to start at boot time, but I couldn't find anything in the results of that command that explained why this was occuring. I'm happy to provide the (very long) output from that, if that's helpful.

The tomcat.service file contains the following:
(I had to remove the contents of this file, even though it was marked as code, because the submission form insisted my post looked like spam. Sigh)

I have set the following in my user's home folder, in the .bashrc file:

export CATALINA_HOME=/opt/tomcat/latest

I wonder if perhaps when the service is starting up at boot time, if it's not running as my user, then perhaps it dosn't have access to this variable somehow ?

The actual startup script (referenced in the tomcat.service file is /opt/tomcat/latest/bin/startup.sh . It contains the default contents, I have not modified it in any way.

Again, the above script runs and will start tomcat.
I can even start tomcat as a service by manually typing sudo systemctl start tomcat.

It just won't start at boot time.

I have done a sudo yum check-update, followed by sudo yum install update. I did this to update CentOS 7 to the latest version. I did this after I installed tomcat, as part of the troubleshooting process I have been through. This didn't seem to help.

I would be most grateful if anyone can suggest a solution, or a troubleshooting step I should try next. For example, I'm not sure how to examine the startup process on a linux box specifically to look for services failing to start up and why.

Kind regards,
Spencer.

Best Answer

security settings in java could be the reason

"java.home/lib/security/java.policy"

catalina has its own security settings "

../tomcat/conf/catalina.policy"