Apache Tomcat is not configured with autostart by default in Ubuntu. So, custom init script is required to configure Tomcat for autostart on startup.
Create the init script in /etc/init.d/tomcat8 with the contents as per below.
Init script contents:
#!/bin/bash
### BEGIN INIT INFO
# Provides: tomcat8
# 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 {tomcat_root}/bin/startup.sh
}
stop() {
sh {tomcat_root}/bin/shutdown.sh
}
case $1 in
start|stop) $1;;
restart) stop; start;;
*) echo "Run as $0 <start|stop|restart>"; exit 1;;
esac
Note: Please change {tomcat_root} with your Tomcat installation folder path.
Change its permissions and add the correct symlinks automatically:
chmod 755 /etc/init.d/tomcat8
update-rc.d tomcat8 defaults
And from now on it will be automatically started and shut down upon entering the appropriate run levels.
It could be also controlled with just use following commands like Apache
service tomcat8 <stop|start|restart>
Using above process any server script can be created and configured to start on startup.