To register Tomcat as a service__linux under Linux

Source: Internet
Author: User
Tags file permissions

1. Write a shell script called Tomcat, which reads as follows (can be rewritten according to the actual situation):

#!/bin/bash # chkconfig:2345 # Description:start and Stop Tomcat by service export java_home=/usr/java/jdk1.8.0_51 Export Catalina_home=/usr/local/tomcat/export classpath= $JAVA _home/lib/tools.jar: $CATALINA _home/bin/
Commons-daemon.jar: $CATALINA _home/bin/bootstrap.jar # source function library. . 
/etc/rc.d/init.d/functions if [! f $CATALINA _home/bin/catalina.sh] then echo "Tomcat not valilable ..." Exit Fi # Start 
Start () {Echo-n "starting tomcat:" $CATALINA _home/bin/startup.sh Echo} #stop Stop () {echo-n "shutting down Tomcat:" $CATALINA _home/bin/shutdown.sh} #restart restart () {Stop sleep 3 start} #status status () {PS Ax--width=1000 | grep [O]rg.apache.catalina.startup.bootstrap start] | awk ' {printf $ '} ' | WC | awk ' {print $} ' >/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 $ '} ' Echo-n") is running ..." echo else echo "Tomcat is stopped ' fi} case '" in Start "start;;
stop) stop;;
Restart) Stop sleep 3 start;;
status) status;; *) echo "USAGE:TOMCATD {start|stop|restart|status}" Exit 1 Esac Exit 0</span>
Note: The second line chkconfig and the third line description must be added, otherwise it cannot be registered as a service


2. Then put Tomcat under the/etc/init.d folder


3. Modify file Permissions: #chmod a+x Tomcat


4. Add Service run: #chkconfig add tomcat












Related Article

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.