2013年11月5日 星期二

[Linux 文章收集] Starting Tomcat as a Linux service

來源自 這裡 
Preface: 
The following bash script file can be used on Linux instances to startup a Tomcat server as a service. The script does need some minor modifications to suit your specific instance of Linux. The following two variables must be changed: 
1. The JAVA_HOME variable must point to an installed version of java on your system. 
# 根據你安裝 JDK 的位置進行調整
export JAVA_HOME=/usr/local/jdk

2. The tomcat_home variable must pouint to an installed Tomact server on your system 
# 根據你置放 Tomcat 目錄進行調整
tomcat_home=/usr/local/jakarta-tomcat


Bash script sample: 
  1. #!/bin/bash  
  2. # This is the init script for starting up the  
  3. #  Jakarta Tomcat server  
  4. #  
  5. # chkconfig: 345 91 10  
  6. # description: Starts and stops the Tomcat daemon.  
  7. #  
  8.   
  9. # Source function library.  
  10. . /etc/rc.d/init.d/functions  
  11.   
  12. # Get config.  
  13. . /etc/sysconfig/network  
  14.   
  15. # Check that networking is up.  
  16. "${NETWORKING}" = "no" ] && exit 0  
  17.   
  18. export JAVA_HOME=/usr/local/jdk  
  19. tomcat_home=/usr/local/jakarta-tomcat  
  20. startup=$tomcat/bin/startup.sh  
  21. shutdown=$tomcat/bin/shutdown.sh  
  22.   
  23. start(){  
  24.    echo -n "Starting Tomcat service:"  
  25.    cd $tomcat_home  
  26.    $startup  
  27.    echo "done"  
  28. }  
  29.   
  30. stop(){  
  31.    echo -n "Shutting down tomcat: "  
  32.    cd $tomcat_home  
  33.    $shutdown  
  34.    echo "done."  
  35. }  
  36.   
  37. status(){  
  38.     numproc=`ps -ef | grep catalina | grep -v "grep catalina" | wc -l`  
  39.     if [ $numproc -gt 0 ]; then  
  40.        echo "Tomcat is running..."  
  41.     else  
  42.        echo "Tomcat is stopped..."  
  43.     fi  
  44. }  
  45.   
  46. restart(){  
  47.    stop  
  48.    start  
  49. }  
  50.   
  51. # See how we were called.  
  52. case "$1" in  
  53. start)  
  54.    start  
  55.    ;;  
  56. stop)  
  57.    stop  
  58.    ;;  
  59. status)  
  60.    status  
  61.    ;;  
  62. restart)  
  63.    restart  
  64.    ;;  
  65. *)  
  66.    echo $"Usage: $0 {start|stop|status|restart}"  
  67.    exit 1  
  68. esac  
Steps to install on a linux system: 
1. Copy the modified shell script to /etc/init.d/tomcatd
2. Make sure it can be executed: chmod a+x tomcatd 
3. Set up appropriate deamon levels by performing: chkconfig --add tomcatd

Supplement: 
鳥哥 Linux 私房菜 > 認識系統服務 (daemons)

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...