Article Title: analyzes Automatic startup of SUSELinuxTomcat. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Maybe you know SUSE Linux very well. Maybe you don't know much about it. Here we will discuss each other. Today we are talking about Automatic startup of SUSE Linux Tomcat. I hope this article will help you and hope you can learn how to enable SUSE Linux Tomcat automatically. Add the command to the/etc/init. d/boot. local file. The corresponding file of the Red Hat system is/etc/rc. d/rc. local.
For commands or programs automatically run during Linux Startup, In rh-based linux systems, it is generally stored in/etc/rc. d/rc. local. However, SuSE Linux does not have this file, and users are not recommended to manage the startup service in this way. We recommend that you use a regular method to manage the Service Startup Mode.
Some people may say that in The SuSE system, it can be placed in/etc/init. d/boot. local, depending on the actual situation. Because SuSE/etc/init. d/boot. the local file is composed of/etc/init. the script d/boot is started, and the final boot script is complete. It is executed when you enter the runlevel environment to execute various rc scripts. The rh/etc/rc. d/rc. local file is executed in the last stage when various rc scripts are executed in the runlevel environment, so the layers are different. If the program you want to run is suitable for running the runlevel service before it is executed, you can put it in the boot. local file in SuSE linux.
However, if your service needs to be executed only after entering runlevel, the common practice of SuSE should be to write an rc script and put it in/etc/init. d/directory, and then use the chkconfig or inssev program to manage whether to enable or disable the Service Project during startup of A runlevel environment. For the rc script Writing Method, refer to the existing script files in/etc/init. d/. You should easily write your own version.
1. Create a startup/Stop script file
The script allows Tomcat to run as a Service.
#! /Bin/bash
# Chkconfig: 2345 10 90
# Description: Starts and Stops the Tomcat daemon.
TOMCAT_HOME =/usr/local/tomcat/apache-tomcat-5.5.25
TOMCAT_START = $ TOMCAT_HOME/bin/startup. sh
TOMCAT_STOP = $ TOMCAT_HOME/bin/shutdown. sh
# Necessary environment variables export
CATALINA_HOME = $ TOMCAT_HOME
Export JAVA_HOME =/usr/java/jdk1.6.0 _ 03
# Source function library.
./Etc/rc. d/init. d/functions
# Source networking configuration.
./Etc/rc. d/network
# Check that networking is up.
["$ {NETWORKING}" = "no"] & exit 0
# Check for tomcat script
If [! -F $ TOMCAT_HOME/bin/catalina. sh]
Then echo "Tomcat not valilable ..."
Exit
Fi
Start (){
Echo-n "Starting Tomcat :"
Daemon $ TOMCAT_START
Echo
Touch/var/lock/subsys/tomcat
}
Stop (){
Echo-n $ "Shutting down Tomcat :"
Daemon $ TOMCAT_STOP
Rm-f/var/lock/subsys/tomcat. pid echo
}
Restart (){
Stop
Start
}
Status (){
Ps ax -- width = 1000 | grep "[o] rg. apache. catalina. startup. bootstrap start "| awk '{printf $1"}' | wc | awk '{print $2}'>/tmp/tomcat_process_count.txt
Read line </tmp/tomcat_process_count.txt
If [$ line-gt 0]; then
Echo-n "tomcat (pid"
Ps ax -- width = 1000 | grep "org. apache. catalina. startup. Bootstrap start" | awk '{printf $1 ""}'
Echo-n ") is running ..."
Echo
Else
Echo "Tomcat is stopped"
Fi
}
Case "$1" in
Start)
Start ;;
Stop)
Stop ;;
Restart)
Stop
Sleep 3
Start ;;
Status)
Status ;;
*)
Echo "Usage: tomcatd {start | stop | restart | status }"
Exit 1
Esac
Exit 0
Ii. Save and set the script file
Save the preceding script file in/etc/init. d and name it tomcat;
Set tomcat file attributes
# Chmod a + x tomcat
3. Set the service running level
Finally, use chkconfig to set service running.
# Chkconfig -- add tomcat
The service is successfully added.
Then you can use chkconfig -- list to view the Custom Service in the service list.
Note:
In the comments statement of the first two lines of the tomcat file, the chkconfig and description must be included (do not make spelling mistakes). Otherwise, when "chkconfig -- add tomcat" is executed, the error message "tomcat service does not support chkconfig" appears.
This line of chkconfig indicates the default startup running level and the priority of Start and Stop. if the service is not started at any running level by default, "-" is used instead of "Run level. In tomcat, the script is started at runtime Level 2, 3, 4, and 5. The start priority is 10, and the Stop priority is 90.
The description line describes the service. You can use "\" to annotate the service. In this way, you will learn the SUSE Linux Tomcat Automatic startup process.
Original address http:// OS .51cto.com/art/200911/164919.htm