Skip to main content Skip to complementary content

Installing Apache Tomcat as a service on systemd-based Linux systems

Before you begin

All the following commands must be executed with super-user privileges.

Procedure

  1. Create the service file with the following command:
    touch /etc/systemd/system/tomcat.service
  2. Assign the relevant rights to the file you created:
    chmod 664 /etc/systemd/system/tomcat.service
  3. Paste the following content in the file while adapting it to your configuration:
    [Unit]
    Description=Apache Tomcat Web Application Container
    After=syslog.target network.target
    
    [Service]
    Type=forking
    
    Environment=JAVA_HOME=/usr/lib/jvm/jre
    Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
    Environment=CATALINA_HOME=/opt/tomcat
    Environment=CATALINA_BASE=/opt/tomcat
    Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
    Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
    
    ExecStart=/opt/tomcat/bin/startup.sh
    ExecStop=/bin/kill -15 $MAINPID
    
    [Install]
    WantedBy=multi-user.target
  4. Reload the service daemon:
    systemctl daemon-reload
  5. Start the service:
    systemctl start tomcat.service

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!