Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to know whether is there any way to make our Apache tomcat to run automatically in the boot time?I want to simplify our works as we do not want to execute the start up script(provided in the Apache tomcat directory) every time the Linux machine is being rebooted.Hope anybody can help.Thanks.

share|improve this question

migrated from Dec 17 '12 at 11:57

This question came from our site for professional and enthusiast programmers.

right.sorry for wrong post – Dec 17 '12 at 9:59

You just need to add the startup script to your boot sequence.
The easiest way (I think) is to create a startup script in /etc/init.d and add them to the run level you want. Here is a script I used (later I assume that the script is called tomcat).

# tomcat7     This shell script takes care of starting and stopping Tomcat
# chkconfig: - 80 20
# Provides: tomcat7
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start:
# Default-Stop:
# Description: Release implementation for Servlet 2.5 and JSP 2.1
# Short-Description: start and stop tomcat



case "$1" in
        tomcat_pid=`ps -ef | grep apache | grep tomcat | grep java | egrep -v grep | awk '{print $2}'`
        if [ -n "$tomcat_pid" ]; then
          echo "Tomcat is running."
          exit 1;
        echo -n "Starting $DESC:\n  $START_DAEMON \n"

        tomcat_pid=`ps -ef | grep apache | grep tomcat | grep java | egrep -v grep | awk '{print $2}'`
        if [ -z "$tomcat_pid" ]; then
          echo "Tomcat is not running."
          exit 1;
        echo -n "Stopping $DESC:\n $STOP_DAEMON \n "

        tomcat_pid=`ps -ef | grep apache | grep tomcat | grep java | egrep -v grep | awk '{print $2}'`
        if [ -n "$tomcat_pid" ]; then
          echo -n "Restarting $DESC: \n $STOP_DAEMON \n"
              sleep 5
        echo -n "starting $DESC: \n $START_DAEMON \n"
        echo "Starting, please wait for about 50 seconds."
        sleep 20

        echo "Usage: $NAME {start|stop|restart}" >&2
        exit 1

exit 0

Now to add it to boot depends on your distro. For example: Ubuntu for default run levels would look like sudo update-rc.d tomcat defaults
Red Hat would look like chkconfig --add tomcat then chkconfig tomcat on

share|improve this answer
i've already tried the solution.but it shows i'm unable to use chkconfig as it showing this error : service tomcat does not support chkconfig .FYI i', using centos 5 – Dec 18 '12 at 2:20
I updated the script to include chkconfig info. You should add the run levels you want on the default-start and default-stop lines – grekier Dec 18 '12 at 6:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .