Linux下设置tomcat服务

以centos为例apache

  1. 建立一个tomcat文件,内容以下centos

    #!/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目录下tomcat

  3. 受权bash

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

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

    chkconfig tomcat on
  6. 尝试以下命令吧ip

    service tomcat start
    service tomcat status
    service tomcat restart
    service tomcat stop
相关文章
相关标签/搜索