Description: How to Run Tomcat for Service

Source: Internet
Author: User

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.

  1. #! /Bin/bash
  2. # Chkconfig: 2345 10 90
  3. # Description: Starts and Stops the Tomcat daemon.
  4. TOMCAT_HOME=/Usr/local/apache-tomcat-5.5.12
  5. TOMCAT_START= $ TOMCAT_HOME/bin/startup. sh
  6. TOMCAT_STOP= $ TOMCAT_HOME/bin/shutdown. sh
  7. # Necessary environment variables export
  8. CATALINA_HOME= $ TOMCAT_HOME
  9. ExportJAVA_HOME=/Usr/java/jdk1.5.0 _ 05
  10. # Source function library.
  11. ./Etc/rc. d/init. d/functions
  12. # Source networking configuration.
  13. ./Etc/sysconfig/network
  14. # Check that networking is up.
  15. ["$ {NETWORKING}" = "no"] & exit 0
  16. # Check for tomcat script
  17. If [! -F $ TOMCAT_HOME/bin/catalina. sh]
  18. Then echo "Tomcat not valilable ..."
  19. Exit
  20. Fi
  21. Start (){
  22. Echo-n "Starting Tomcat :"
  23. Daemon $ TOMCAT_START
  24. Echo
  25. Touch/var/lock/subsys/tomcat
  26. }
  27. Stop (){
  28. Echo-n $ "Shutting down Tomcat :"
  29. Daemon $ TOMCAT_STOP
  30. Rm-f/var/lock/subsys/tomcat. pid echo
  31. }
  32. Restart (){
  33. Stop
  34. Start
  35. }
  36. Status (){
  37. Ps ax-- Width=1000| Grep "[o] rg. apache. catalina. startup. Bootstrap start"
  38. | Awk '{printf {GetProperty (Content)} ""}' | wc | awk '{print $2 }'>
  39. /Tmp/tomcat_process_count.txt
  40. Read line</Tmp/tomcat_process_count.txt
  41. If [$ line-gt 0]; then
  42. Echo-n "tomcat (pid"
  43. Ps ax-- Width=1000| Grep "org. apache. catalina. startup. Bootstrap start" | awk '{printf {GetProperty (Content )}""}'
  44. Echo-n ") is running ..."
  45. Echo
  46. Else
  47. Echo "Tomcat is stopped"
  48. Fi
  49. }
  50. Case "{GetProperty (Content)}" in
  51. Start)
  52. Start ;;
  53. Stop)
  54. Stop ;;
  55. Restart)
  56. Stop
  57. Sleep 3
  58. Start ;;
  59. Status)
  60. Status ;;
  61. *)
  62. Echo "Usage: tomcatd {start | stop | restart | status }"
  63. Exit 1
  64. Esac
  65. 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.

  1. Install Oracle database with SuSE Linux10
  2. Solve the XEN bridge problem of Suse SLES11 bond Nic
  3. How to install OpenFOAM in Open SUSE
  4. Illustration: SUSE Linux Enterprise Server 11
  5. Create FTP with vsftp in SUSE linux10.0

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.