How to Start Tomcat 8 Automatically at Server Boot on Enterprise Linux 7

Since Tomcat 8 was installed through unpacking the tar file downloaded from Apache, so there's no native service representing Tomcat on your server (Please refer to How to Install Java 8 and Tomcat 8 on Enterprise Linux 7). You have to add a customized service to systemd instead of SysVinit by yourself for starting Tomcat 8 at server boot. Here are the steps:

Create a service script for Tomcat.
[root@test ~]# vi /lib/systemd/system/tomcat.service


# Start service
ExecStart=/usr/bin/java -Djava.util.logging.config.file=/usr/tomcat/default/conf/ -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/tomcat/default/endorsed -classpath /usr/tomcat/default/bin/bootstrap.jar:/usr/tomcat/default/bin/tomcat-juli.jar -Dcatalina.base=/usr/tomcat/default -Dcatalina.home=/usr/tomcat/default org.apache.catalina.startup.Bootstrap start
#ExecStart=/usr/bin/su -c '/usr/tomcat/default/bin/'

Please note that I listed two ExecStart commands above:
  1. Initiate Java with Tomcat Directly
  2. /usr/bin/java -Djava.util.logging.config.file=/usr/tomcat/default/conf/ -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/tomcat/default/endorsed -classpath /usr/tomcat/default/bin/bootstrap.jar:/usr/tomcat/default/bin/tomcat-juli.jar -Dcatalina.base=/usr/tomcat/default -Dcatalina.home=/usr/tomcat/default org.apache.catalina.startup.Bootstrap start
    This command directly initiate Java with Tomcat parameters, so it's easy to manage the process of tomcat.service by systemctl. That is, you can start and stop the service like this:
    [root@test ~]# systemctl start tomcat.service
    [root@test ~]# systemctl stop tomcat.service

    For your environment, please feel free to modify the command string according your requirements.
  3. Execute Tomcat provided command
  4. /usr/bin/su -c '/usr/tomcat/default/bin/'
Both are workable. You may choose any one of them for your ExecStart as you like.

Force systemd reload all configurations. This will make systemd acknowledge tomcat.service.
[root@test ~]# systemctl daemon-reload
[root@test ~]# systemctl status tomcat.service
tomcat.service - Tomcat
   Loaded: loaded (/usr/lib/systemd/system/tomcat.service; disabled)
   Active: inactive (dead)

Enable tomcat.service for making necessary soft links and startup at server boots.
[root@test ~]# systemctl enable tomcat.service
ln -s '/usr/lib/systemd/system/tomcat.service' '/etc/systemd/system/tomcat.service'
ln -s '/usr/lib/systemd/system/tomcat.service' '/etc/systemd/system/'
[root@test ~]# systemctl status tomcat.service
tomcat.service - Tomcat
   Loaded: loaded (/usr/lib/systemd/system/tomcat.service; enabled)
   Active: inactive (dead)

If you'd like to start tomcat.service right away, you can do this.
[root@test ~]# systemctl start tomcat.service
All set! Please reboot your web server to verify the result.
[root@test ~]# init 6

2 thoughts on “How to Start Tomcat 8 Automatically at Server Boot on Enterprise Linux 7”

Leave a Reply

Your email address will not be published. Required fields are marked *