We will encounter many problems in Suse Linux. The question we want to address today is how to run Tomcat for Service. I hope that the Knowledge mentioned in this article will help you learn how to run Tomcat for Service.
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/apache-tomcat-5.5.12
- TOMCAT_START= $ TOMCAT_HOME/bin/startup. sh
- TOMCAT_STOP= $ TOMCAT_HOME/bin/shutdown. sh
- # Necessary environment variables export
- CATALINA_HOME= $ TOMCAT_HOME
- ExportJAVA_HOME=/Usr/java/jdk1.5.0 _ 05
- # Source function library.
- ./Etc/rc. d/init. d/functions
- # Source networking configuration.
- ./Etc/sysconfig/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 {GetProperty (Content)} ""}' | 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 {GetProperty (Content )}""}'
- Echo-n ") is running ..."
- Echo
- Else
- Echo "Tomcat is stopped"
- Fi
- }
- Case "{GetProperty (Content)}" in
- Start)
- Start ;;
- Stop)
- Stop ;;
- Restart)
- Stop
- Sleep 3
- Start ;;
- Status)
- Status ;;
- *)
- Echo "Usage: tomcatd {start | stop | restart | status }"
- Exit 1
- Esac
- Exit
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
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.The above describes how to run Tomcat for Service in Suse Linux. This method is worth your research.
- Install Oracle database with SuSE Linux10
- Solve the XEN bridge problem of Suse SLES11 bond Nic
- How to install OpenFOAM in Open SUSE
- Illustration: SUSE Linux Enterprise Server 11
- Create FTP with vsftp in SUSE linux10.0