Under the Linux system, when a service is set up, it needs to be mounted under/ETC/RCX.D, and the startup script will be written under/etc/init.d/.
Create a new file under/etc/init.d/Tomcat (need to operate under root)
Vi/etc/init.d/tomcat
Write the following code:
# Tomcat Self-starter script
#!/bin/sh
# chkconfig:345 99 10
# Description:auto-starts Tomcat
#/ETC/INIT.D/TOMCATD
# Tomcat Auto-start
# Source function library.
#. /etc/init.d/functions
# source Networking configuration.
#. /etc/sysconfig/network
Retval=0
Export JDK_HOME=/USR/JAVA/JDK1.7.0_45 (please fill in the actual JDK directory)
Export catalina_home=/home/ldatum/usr/apache-tomcat-7.0.10 (please fill in the real Tomcat directory)
Export catalina_base=/home/ldatum/usr/apache-tomcat-7.0.10 (please fill in the real Tomcat directory)
Start ()
{
If [-f $CATALINA _home/bin/startup.sh];
Then
echo $ "Starting Tomcat"
$CATALINA _home/bin/startup.sh
Retval=$?
echo "OK"
Return $RETVAL
Fi
}
Stop ()
{
If [-f $CATALINA _home/bin/shutdown.sh];
Then
echo $ "Stopping Tomcat"
$CATALINA _home/bin/shutdown.sh
Retval=$?
Sleep 1
PS-FWWU Tomcat | grep apache-tomcat|grep-v grep | Grep-v PID | awk ' {print $} ' |xargs kill-9
echo "OK"
# [$RETVAL-eq 0] && rm-f/var/lock/...
Return $RETVAL
Fi
}
Case "$" in
Start
Start
;;
Stop
Stop
;;
Restart
echo $ "restaring Tomcat"
$ stop
Sleep 1
$ start
;;
*)
echo $ "Usage: $ {Start|stop|restart}"
Exit 1
;;
Esac
Exit $RETVAL
Once added, add executable permissions to it:chmod +x/etc/init.d/tomcat.
The link to the shell file is then connected to the/etc/rc2.d/directory. The numbers in the/etc/rcx.d/directory for Linux represent the different run level, which is the order in which the boot starts, Ubuntu9.10 There are 0-5 six level, can not be casually connected to other directories, it may be in that directory when the program started Tomcat needs some of the library has not been loaded, with the LN command to link tomcat links Past:ln-s/etc/init.d/ Tomcat /etc/rc2.d/s16tomcat. The naming rules in the RCX.D directory are very specific, more different needs may be the beginning of s, may also be K start, after the number represents their boot sequence, detailed look at the respective directory of the Readme file
The next step is to set the script to run automatically when the system starts, and stop automatically when the system shuts down, using the following command:chkconfig--add Tomcat. If chkconfig is not installed, it is installed with programs such as Apt-get or yum , and the general server version of Linux is already in place.
Finally, use Chkconfig--list to confirm that you added the success
Finally, the reboot system is restarted. After rebooting, you will find that your Tomcat has run successfully.
Install Tomcat under Linux and set auto-start