Run Tomcat as a Service in SUSELinux

Source: Internet
Author: User
Tags stop script
Article Title: Run Tomcat as a Service in SUSELinux. 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.

SUSE Linux does not have rc. local
 
 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.12TOMCAT_START=$TOMCAT_HOME/bin/startup.shTOMCAT_STOP=$TOMCAT_HOME/bin/shutdown.sh# necessary environment variables exportCATALINA_HOME=$TOMCAT_HOME export JAVA_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 fistart(){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

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.