[Solved] Tomcat5 Startup Script for Ubuntu 20.04 LTS
Tomcat5.5 and JDK5 are very old items on the application table but they still exists for legacy applications. There might be some business reasons but for IT they are headache. Configuration is almost manual at every step and you need to invest too much time thinking rather than doing it. You need to configure JDK5 manually and create all the symlinks. The same you have to do for tomcat5 and tomcat5 startup script for Ubuntu 20.04 is no different than others but it can take too much time to adjust things and understand it. I have created a simple script which will start Tomcat5 at system startup. Its simple and easy and consists only few commands.
Solution!!!
This article assumes that you have already downloaded JDK5 and configured it, if not you can follow my previous article link to download and install it.
The main focus of this article is to provide a simple script which can be created in /etc/init.d so that it can be triggered at system restart to automatically start tomcat5 on ubuntu 20.04 LTS
create a file under /etc/init.d
vi /etc/init.d/tomcat
Copy the under given script in the above file. You can change the JAVA_HOME path and CATALINA_HOME path and adjust according to your paths on the Ubuntu 20.04 LTS server.
#!/bin/bash # #tomcat # # chkconfig: # description: Start up the Tomcat servlet engine. # Source function library. . /lib/lsb/init-functions RETVAL=$? JAVA_HOME=/usr/lib/jvm/java5 export JAVA_HOME PATH=$JAVA_HOME/bin:$PATH export PATH CATALINA_HOME="/usr/local/tomcat" case "$1" in start) if [ -f $CATALINA_HOME/bin/startup.sh ]; then echo $"Starting Tomcat" /usr/local/tomcat/bin/startup.sh fi ;; stop) if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then echo $"Stopping Tomcat" /usr/local/tomcat/bin/shutdown.sh fi ;; *) echo $"Usage: $0 {start|stop}" exit 1 ;; esac exit $RETVAL
Now you need to set the permissions of tomcat script under /etc/init.d directory. Follow the under given command:
chmod 755 /etc/init.d/tomcat
Once you are done, you need to create the symlinks for the startup under all levels.
update-rc.d tomcat defaults
Now you need to reload the configuration so that it can read from it disk. use under listed command:
systemctl daemon-reload
You might need to adjust the permissions of the log directory under tomcat which can be done with CHMOD command followed by the required flags according to your needs.
I used under given permissions to make it work on my server:
chmod a+rwx -R logs
This method worked for me, hope it will work for you as well.
Note: to make sure that your tomcat is configured correctly and working, you can test it before creating this startup script by issuing under listed commands:
sh /usr/local/tomcat/bin/startup.sh sh /usr/local/tomcat/bin/shutdown.sh
Adjust the paths according to your system paths.