Linux下设置tomcat服务

以centos为例

  1. 创建一个tomcat文件,内容如下

    #!/bin/bash
    #
    # Startup script for the tomcat
    # chkconfig: 2345 90 60
    
    # source function library
    . /etc/rc.d/init.d/functions
    # 这里的tomcat地址修改成你的tomcat地址
    tomcat=/apache-tomcat-7.0.77
    startup=$tomcat/bin/startup.sh
    shutdown=$tomcat/bin/shutdown.sh
    
    start() {
      echo -n $"Starting Tomcat service: "
      sh $startup
      echo $?
    }
    
    stop() {
      echo -n $"Stopping Tomcat service: "
      sh $shutdown
      echo $?
    }
    
    restart() {
      stop
      start
    }
    
    status() {
      ps -aef | grep apache-tomcat | grep -v grep
    }
    
    # Handle the different input options
    case "$1" in
    start)
      start
      ;;
    stop)
      stop
      ;;
    status)
      status
      ;;
    restart)
      restart
      ;;
    *)
      echo $"Usage: $0 {start|stop|restart|status}"
      exit 1
    esac
    
    exit 0
  2. 将tomcat文件复制到/etc/init.d目录下

  3. 授权

    cd /etc/init.d
    chmod u+x tomcat
  4. 设置tomcat为一个服务

    chkconfig --add tomcat
  5. 设置tomcat自启动

    chkconfig tomcat on
  6. 尝试如下命令吧

    service tomcat start
    service tomcat status
    service tomcat restart
    service tomcat stop
    原文作者:Backache
    原文地址: https://segmentfault.com/a/1190000009396372
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞