I have installed Tomcat 7 on Ubuntu 12.04 LTS which runs on an Amzon EC2 instance. Now I wish tomcat should restart automatically on system reboot.
I read this blog which suggest adding below script to /etc/init.d/tomcat7
:
# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid
case $1 in
start)
sh /usr/share/tomcat7/bin/startup.sh
;;
stop)
sh /usr/share/tomcat7/bin/shutdown.sh
;;
restart)
sh /usr/share/tomcat7/bin/shutdown.sh
sh /usr/share/tomcat7/bin/startup.sh
;;
esac
exit 0
and issue the following commands:
sudo chmod 755 /etc/init.d/tomcat7
sudo ln -s /etc/init.d/tomcat7 /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat7 /etc/rc2.d/S99tomcat
sudo /etc/init.d/tomcat7 restart
My Questions
- The tomcat7 already has script in it, where do we have to paste the suggested script?
- Is the suggested procedure correct?
Create the init script in /etc/init.d/tomcat7 with the contents as per below (your script should work too but I think this one adheres more closely to the standards).
This way Tomcat will start only after network interfaces have been configured.
Init script contents:
Change its permissions and add the correct symlinks automatically:
And from now on it will be automatically started and shut down upon entering the appropriate runlevels. You can also control it with
service tomcat7 <stop|start|restart>
Cant this be added to the
/etc/rc.local
Digital Ocean provides a very handy guide for using Tomcat 8.x and Ubuntu 16.04 LTS and systemd scripts.
https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-16-04
apache tomcat does not ship any init script with it.
Install the prepackaged version maintained by Ubuntu from the Ubuntu package manager this version ships its own init script.
Follow the steps in the blog you refered to which provide you with a kickstart init script.
I tried the accepted answer, which did not work.
What ended up working was to remove the service, and add the service back: