Automatic Tomcat Startup in Linux Upon System Boot

  • Last update:March 18, 2026
  • Overview

    This document introduces how to configure Tomcat installed in Linux to start automatically upon system boot.

    iconNote: 
    Since the path of log files will change after you configure Tomcat to start automatically upon system boot, you are advised to specify the log file path. 

    Configuring Automatic Tomcat Startup upon System Boot for Ubuntu 16.04 and Earlier Releases, CentOS 6.x, and RedHat 6.x

    Creating a Script to Manage Tomcat

    1. First, create a tomcat script in the /etc/init.d/ directory.

    vi /etc/init.d/tomcat

    Press the i (lowercase) key to enter insert mode, and add the following content to the script.

    #!/bin/bash
    # tomcat startup script for the Tomcat server
    # chkconfig: 35 80 20
    # description: start the tomcat deamon
    #prog=tomcat
    #EDISPORT=8080
    #The default port number is 8080. If a non-default port is used, modify it accordingly.
    #EXEC=/usr/tomcat/bin/startup.sh 
    #Path to the Tomcat startup script
    #CONF="/usr/tomcat/bin/catalina.sh"
    #Path to the configuration script
    #<---------------jdk--------------->#
    #. /etc/rc.d/init.d/functions
    #prog=tomcat 
    #JAVA_HOME=/usr/jdk/jdk1.8.0_181
    #export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
    #export PATH=$PATH:$JAVA_HOME/bin
    #export JAVA_HOME#CATALANA_HOME=/usr/tomcat/
    #export CATALINA_HOME
    #<---------------jdk--------------->#
    CATALANA_HOME=/usr/tomcat/
    export CATALINA_HOME
    case "$1" in start)
    echo "Starting Tomcat..."
    $CATALANA_HOME/bin/startup.sh
    ;;
    stop)
    echo "Stopping Tomcat..."
    $CATALANA_HOME/bin/shutdown.sh
    ;;
    restart)
    echo "Stopping Tomcat..."
    $CATALANA_HOME/bin/shutdown.sh
    sleep 2
    echo
    echo "Starting Tomcat..."
    $CATALANA_HOME/bin/startup.sh
    ;;
    *)
    echo "Usage: $prog {start|stop|restart}"
    ;;
    esac exit 0

    For Tomcat installed by custom compilation (as provided in this document), you need to modify the following configuration items in the script according to your installation path.

    CATALANA_HOME=/usr/tomcat/ # Root directory of catalina.sh under tomcat/bin/

    2. After saving the script file, set the execution permission of the file.

    chmod a+x /etc/init.d/tomcat

    3. You can now manage the Tomcat service using this script.

    /etc/init.d/tomcat start
    /etc/init.d/tomcat stop

    Enabling Automatic Tomcat Startup upon System Boot Using chkconfig

    1. After completing the steps above to manage the Tomcat service using the script, you can use the chkconfig command to enable automatic Tomcat startup upon system boot.

    Add the Tomcat service to the chkconfig management list:

    chkconfig --add /etc/init.d/tomcat

    2. After configuring the script, you can set automatic startup upon system boot and manage the service using the following commands.

    chkconfig tomcat on     # Enable automatic startup on system boot.
    chkconfig tomcat off    # Disable automatic startup on system boot.
    service tomcat start    # Start the Tomcat service.
    service tomcat stop     # Stop the Tomcat service.
    service tomcat restart  # Restart the Tomcat service.

    Configuring Automatic Tomcat Startup upon System Boot for Ubuntu 16.10 and Later Releases, CentOS 7.x, and RedHat 7.x

    Creating a Script to Manage Tomcat

    1. Create a tomcat.service file in the /usr/lib/systemd/system/ directory.

    vi /usr/lib/systemd/system/tomcat.service

    Press the i (lowercase) key to enter insert mode, and add the following content to the script.

    [Unit]
    Description=tomcat service
    After=network.target
    [Service]
    Type=forking
    ExecStart=/usr/tomcat/bin/startup.sh
    ExecReload=/usr/tomcat/bin/startup.sh -s reload
    ExecStop=/usr/tomcat/bin/shutdown.sh
    PrivateTmp=true
    [Install]WantedBy=multi-user.target

    iconNote: 
    You need to modify the Tomcat installation path /usr/tomcat in the script according to the actual path.

    2. After saving the script file, set the execution permission of the file.

    chmod a+x /usr/lib/systemd/system/tomcat.service

    Specifying the JRE Path for Tomcat Startup

    1. Edit the setclasspath.sh file in the bin directory of Tomcat.

    vi /usr/tomcat/bin/setclasspath.sh   #Your own Tomcat path

    iconNote:
    Normally, this file contains content. If it is empty, edit setenv.sh in Tomcat/bin instead. If the file does not exist, you can create a setenv.sh file.

    2. Add the JRE environment variable.

    export JAVA_HOME=/usr/local/java/jdk1.8.0_151 #Your own Java path
    export JRE_HOME=/usr/local/java/jdk1.8.0_151/jre #Your own JRE path

    iconNote: 
    If you use the deployment package provided by Fanruan, which includes a bundled JDK, add the following environment variable.
    export JAVA_HOME=/usr/local/tomcat/jdk/
    export PATH=$JAVA_HOME/bin:$PATH

    The following figure shows the effect after you add the JRE environment variable.

    3. Save the file and exit the editing page.

    Enabling Automatic Tomcat Startup upon System Boot Using systemctl

    2. After configuring the script, you can set automatic startup upon system boot and manage the service using the following commands.

    systemctl enable tomcat.service          # Enable automatic startup on system boot.
    systemctl disable tomcat.service         # Disable automatic startup on system boot.
    systemctl start tomcat.service          # Start the Tomcat service.
    systemctl stop tomcat.service           # Stop the Tomcat service.
    systemctl status tomcat.service          # Check the current status of the service.
    systemctl list-units --type=service      # Check all active services.

    Attachment List


    Theme: Deployment and Integration
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy