Tomcat starts with every server reboot

I am having a problem at hand. Everytime I reboot my Unix server, tomcat tales precedence and starts.

I checked /etc/init.d but there is no mention of starting tomcat but of dhis. I am giving below (now commented commands)

#!/bin/sh
#Tomcat init script

HOME=/home/dhis/tomcat-dhis/bin

#case $1 in
#start)
##      sudo -u dhis ${HOME}/startup.sh
#       ;;
#stop)
#       sudo -u dhis ${HOME}/shutdown.sh
#       ;;
#restart)
#       sudo -u dhis ${HOME}/shutdown.sh
#       sleep 5
#       sudo -u dhis ${HOME}/startup.sh
#       ;;
#esac
#exit 0

Before commenting I was getting two instances on of tomcat and one of dhis. I could kill dhis process with kill -9 but tomcat respawned every time with new PID.

So I have to issue sudo service tomcat9 stop and then issue the dhis2 startup command.

Why is thing happening and what is the solution so that i do not have to worry about reboots. These reboots were mainly due to system up gradation

My Linux is 20.04.1-Ubuntu and Java is version 11 and dhis2 version 2.36

Hi @amitta . I am not 100% sure I understand your problem. What I understand is that you have Tomcat running in your server and (I assume) is blocking the start up scripts of DHIS2? But then you said you could achieve having Tomcat and DHIS2 running so I am not sure.

I am assuming you are using Tomcat as the java server for DHIS2 but maybe you expect DHIS2 to spin up its own version and not the one from the startup scripts of the Operative System?

In any case, should you want to stop Tomcat starting from your scripts, -assuming you are on Ubuntu using systemd (which I am assuming as it is the default service system for Ubuntu in your version)- you can disable permanently the service by running

systemctl disable tomcat9

But before I would recommend running the following command to make sure my assuming is correct

systemctl status tomcat9

Also, I am not sure how do you usually start DHIS2. You might have some user scripts to start it manually or you might want to start it automatically. For the later you have many options like creating a systemd service, enabling a cron job, creating init scripts, etc

1 Like

Dear James

Thanks for your reply and sorry for sending an ambiguous message.

What i was saying that with DHIS installation, I had also set up init.d script also. SO with every reboot, tomcat service and dhis service both of the were starting, As a result DHIS server was not loading. But what i am not able to understand where tomcat startup script is mentioned. In that i wo;d go there and disable/remove it.

How i am starting DHIS2?

Right now by manually executing /home/dhis/tomcat-dhis/bin/startup.sh

Have you followed the official installation guide? System Administration Guide - DHIS2 Documentation

I cannot know how your DHIS2 is starting but I am assuming you set up some scripts in /etc/rc.local ? If your goal is to have only DHIS2 running (which would produce the start of Tomcat as well) you should disable the automatic startup of Tomcat.

I am assuming (again) that you installed Tomcat via apt-get or a similar tool and it is included as a service. Please run the mentioned command

systemctl status tomcat9

and verify if it says something like enabled. For example this is the docker service in my machine (sorry but don’t have tomcat) where you can see the service is enabled. Enabled means that will start up as soon as the operative system finished loading.

1 Like

Dear @jaime.bosque, i have followed the method suggested in the DHIS2 Installation guide suggested by you.

Presently if I issue the command systemctl status tomcat9, I get “dead” response
tomcat9.service - Apache Tomcat 9 Web Application Server
** Loaded: loaded (/lib/systemd/system/tomcat9.service; disabled; vendor preset: enabled)**
** Active: inactive (dead)**
** Docs: https://tomcat.apache.org/tomcat-9.0-doc/index.html**

Please note that even with this response my DHIS2 is running. I can login into my DHIS2 system

I believe you get dead because you stopped it manually as you mentioned before. If you restart the machine you should have it differently. In any case, this doesn’t block you from disabling by using the command explained above.

Best.