Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Dec 17 '12 at 11:57

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

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

1 Answer 1

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).

#!/bin/sh
#
# tomcat7     This shell script takes care of starting and stopping Tomcat
#
# chkconfig: - 80 20
#
### BEGIN INIT INFO
# 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
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
START_DAEMON=/opt/apache-tomcat-6.0.33/bin/startup.sh
STOP_DAEMON=/opt/apache-tomcat-6.0.33/bin/shutdown.sh

NAME=tomcat
DESC=tomcat

case "$1" in
    start)
        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;
        fi
        echo -n "Starting $DESC:\n  $START_DAEMON \n"
        $START_DAEMON 
        ;;

    stop)
        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;
        fi
        echo -n "Stopping $DESC:\n $STOP_DAEMON \n "
        $STOP_DAEMON
        ;;

    restart|force-reload)
        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"
              $STOP_DAEMON
              sleep 5
        fi
        echo -n "starting $DESC: \n $START_DAEMON \n"
        $START_DAEMON
        echo "Starting, please wait for about 50 seconds."
        sleep 20
        ;;

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

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 –  newbie.my 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.