How to get Tomcat to start Automatically at boot time on Unix

Version 2
    Share This:

    This document contains official content from the BMC Software Knowledge Base. It is automatically updated when the knowledge article is modified.


    Remedy AR System Server


    BMC Remedy AR System Server


       What should I do to get Tomcat to start automatically on a server reboot?  

    BMC Remedy AR System Server (version 7.5.00) DR: AR System Mid Tier;



    Legacy ID:KA313370


    Running Tomcat Automatically on Unix

      To run a process automatically on Unix, you usually create a startup script in a predefined directory that the OS can then find and execute as it starts up. As you probably know, Unix runs at various run or init levels. At each level, it starts various services. Although there are technically 10 possible levels, the ones that typically concern you are 1, which is when the system is running in single-user mode; 2, which is when the system is running in multi-user mode with Network File Service (NFS); 3, for full multi-user mode; and 5, which is full multi-user mode plus X Windows. 
      To tell Unix which services should start at which run level, a collection of directories under /etc/rc.d contains service startup scripts. What you can see under /etc/rc.d is a directory for each Unix run level from 0 to 6, named rc[n].d, where [n] is the run level. The convention is to put the scripts in the init.d directory and then create symbolic links in the various run-level directories as appropriate. The convention also provides a way to determine the order of script execution at a particular run level: the symbolic links are named S[n][scriptname], where [n] is a two-digit number and [scriptname] is the actual name of the script in the /etc/rc.d/init.d directory that is being pointed to. There is a similar convention for stopping services, whereby Unix executes scripts as it descends through run levels. Scripts that need to execute to stop services are named K[n][scriptname], where [n] is a two-digit number and [scriptname] is the actual name of the script in the /etc/rc.d/init.d directory that is being pointed to. To make this work, you must configure the actual script to handle both start and stop situations, as you'll do in a minute. 
      You usually want Tomcat, or any Web server for that matter, to start at run level 3 and/or 5. So you can start by creating a script file called tomcat in /etc/rc.d/init.d that looks like the following: 
      ----begin of script---- 
      # Startup script for Tomcat 
      case "$1" in 
      echo -n "Starting Tomcat" 
      echo -n "Stopping Tomcat" 
      $0 stop 
      $0 start 
      echo "Usage: $0 {start|stop|restart}" 
      exit 1 
      exit 0 
      ----end of script---- 
      NOTE: you'll need to replace <PATH_TO_YOUR_TOMCAT_INSTALL> for the actual path to your tomcat on the script. 
      This script expects to be called with one of three arguments: start, stop, or restart. After you create the script, you need to create a symbolic link for it in the appropriate rc directory. For example (for runlevel 3): 
      # cd /etc/rc.d/rc3.d 
      # ln -f ../init.d/tomcat K90tomcat 
      # ln -f ../init.d/tomcat S90tomcat 
      NOTE: the number 90 there is just an example, you should set it according to your environment 
      What you are doing here is providing a startup link, S90tomcat, which the OS will then call with the start argument. Because you want to gracefully shut down Tomcat when the machine stops, you'll also provide a shutdown link so that the OS will call with the stop argument. Obviously, both links point to the same script, which you've already coded to handle both arguments. 
    Related Products:  
    1. BMC Remedy AR System Server


    Article Number:


    Article Type:


      Looking for additional information?    Search BMC Support  or  Browse Knowledge Articles