CentOS 單個Tomcat 的啓動服務腳本

1.創建腳本
vi /etc/init.d/tomcat

  1. #! /bin/sh
  2. #shell script takes care of starting and stopping
  3. # the glassfish DAS and glassfish instance.
  4. #
  5. # chkconfig: - 64 36
  6. # description: Tomcat auto start
  7. # /etc/init.d/tomcatd
  8. # Tomcat auto-start
  9. # Source function library.
  10. #. /etc/init.d/functions
  11. # source networking configuration.
  12. #. /etc/sysconfig/network
  13. RETVAL=0
  14. export JRE_HOME=/usr/local/jdk1.7.0
  15. export CATALINA_HOME=/home/Gula/pay
  16. export CATALINA_BASE=/home/Gula/pay
  17. start()
  18. {
  19. if [ -f $CATALINA_HOME/bin/startup.sh ];
  20. then
  21. echo $"Starting Tomcat"
  22. $CATALINA_HOME/bin/startup.sh
  23. RETVAL=$?
  24. echo " OK"
  25. return $RETVAL
  26. fi
  27. }
  28. stop()
  29. {
  30. if [ -f $CATALINA_HOME/bin/shutdown.sh ];
  31. then
  32. echo $"Stopping Tomcat"
  33. $CATALINA_HOME/bin/shutdown.sh
  34. RETVAL=$?
  35. sleep 1
  36. ps -fwwu yhjhoo | grep apache-tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9
  37. echo " OK"
  38. # [ $RETVAL -eq 0 ] && rm -f /var/lock/...
  39. return $RETVAL
  40. fi
  41. }
  42. case "$1" in
  43. start)
  44. start
  45. ;;
  46. stop)
  47. stop
  48. ;;
  49. restart)
  50. echo $"Restaring Tomcat"
  51. $0 stop
  52. sleep 1
  53. $0 start
  54. ;;
  55. *)
  56. echo $"Usage: $0 {start|stop|restart}"
  57. exit 1
  58. ;;
  59. esac
  60. exit $RETVAL

2.修改執行權限

  1. chmod +x /etc/init.d/tomcat
  2. chkconfig --add tomcat
  3. chkconfig tomcat on
  4. 啓動/關閉/重啓命令爲 service tomcat service|stop|restart
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章