start tomcat on boot in linux

Start tomcat on boot in Linux

As you all know, all startup scripts are found in /etc/init.d folder. To start tomcat on linux boot then below are primary steps:

  1. create tomcat script that starts,stop,restarts tomcat
  2. create symbolic link of tomcat in rc.d folders. Linux system will run all scripts defined in rc.d folders

Create Tomcat Auto startup script:

  1. login with root user
  2. create a file name with tomcat in /etc/init.d create tomcat startup script
    1. cd /etc/init.d
      vi tomcat
  3. if you set the JAVA_HOME and CATALINA_HOME is bash_profile then you no need to set in /etc/init.d/tomcat script
  4. tomcat script is:
    1. ###export CATALINA_HOME="/usr/local/apache-tomcat-7.0.61"
      ## export JAVA_HOME="/usr/local/jdk7"
      export CATALINA_HOME="/usr/local/apache-tomcat-7.0.61"
      case "$1" in
                  echo $"Starting Tomcat"
                  sh $CATALINA_HOME/bin/
                 echo $"Stopping Tomcat"
                 sh $CATALINA_HOME/bin/
                 sh $CATALINA_HOME/bin/
                 sh $CATALINA_HOME/bin/
               echo $"Usage: $0 {start|stop|restart}"
       exit 1
      exit $ERROR
  5.  chmod 775 tomcat
  6. create symbolic link of the tomcat script in rc.d directory

Add Tomcat script to rc.d directory

We need to create two symbolic links

  • K{level}tomcat    –  K76tomcat  means it kills  the process after K75
  • S{level}tomcat    –  S98tomcat means it starts the tomcat after S97.

Run the below Symbolic commands in Terminal:

  • ln -s /etc/init.d/tomcat /etc/rc.d/rc6.d/K26tomcat tomcat auto startup
  • ln -s /etc/init.d/tomcat /etc/rc.d/rc0.d/K26tomcattomcat auto startup
  • ln -s /etc/init.d/tomcat /etc/rc.d/rc3.d/S81tomcattomcat auto startup
  • ln -s /etc/init.d/tomcat /etc/rc.d/rc2.d/S81tomcat
  • ln -s /etc/init.d/tomcat /etc/rc.d/rc5.d/S81tomcat

I used to prefer to start the tomcat after mysql start.

What are the rc.d directories?

you can found below list of directories in /etc/rc.d and represents  run levels with different modes of operating system

  • /etc/rc.d/rc0.d    –    0   –  HALT or shutdown the system –   All symlinks with K extensions must go here
  • /etc/rc.d/rc1.d   –     1   –  Single mode system
  • /etc/rc.d/rc2.d  –      2   –   Multi user mode with out networking
  • ,/etc/rc.d/rc3.d  –     3   –   Multi user mode with networking enabled. most of the all startup scripts will go here.
  • /etc/rc.d/rc4.d   –     4  –    Not used
  • /etc/rc.d/rc5.d   –     5  –    GUI enabled and starts system with normal mode. Add startup scripts in this.
  • /etc/rc.d/rc6.d   –     6  –  Reboots the system and most scripts start with K level goes into this folder to kill the process

We need to  create Symbolic links

  • K{level}tomcat – create in rc0d, rc6.d
  • S{level}tomcat  – Create in rc3.d,rc5,d,rc2.d



4 thoughts on “start tomcat on boot in linux”
  1. I entered the above, but I get “[FAILED] Failed to start tomcat.service” everytime I reboot. Systemctl Status:

    8< – – – – – –

    * tomcat.service
    Loaded: loaded (/etc/init.d/tomcat; generated)
    Active: failed (Result: exit-code) since
    Docs: man:systemd-sysv-generator(8)
    Process: 358 ExecStart=/etc/init.d/tomcat start (code=exitied, status=203/EXEC)

    systemd[1]: Starting tomcat.service
    systemd[1]: tomcat.service: Control process exited, code=exited, status 203/EXEC
    systemd[1]: tomcat.service: Failed with result ‘exit-code’.
    systemd[1]: Failed to start tomcat.service.

    8< – – – – –

    I put "/etc/init.d/tomcat start" in /etc/rc.local and it starts fine.

    There is no rc.d directory, but I did add the S & K scripts to the appropriate rc?.d directories.

    RASPIOS 10 (BUSTER) Lite version on Raspberry Pi Zero.

Leave a Reply