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