Tomcat 8 rodando como serviço

#adicionar o script do final do post com o nome tomcat em /etc/init.d/

sudo vim /etc/init.d/tomcat

#tornar arquivo executável

sudo chmod +x /etc/init.d/tomcat

#adicionar script ao chkconfig

sudo chkconfig --add /etc/init.d/tomcat

#habilitar o serviço no startup EC2

sudo chkconfig tomcat on

#Ubuntu

sudo update-rc.d tomcat defaults

Arquivo: tomcat

#!/bin/bash
#
# tomcat8 This shell script takes care of starting and stopping Tomcat
# Description: This shell script takes care of starting and stopping Tomcat
# chkconfig: - 80 20
#
## http://blog.maestropublishing.com/2013/04/23/tomcat7-service-startstop-script/
## Source function library.
. /etc/init.d/functions

TOMCAT_HOME=/home/ec2-user/tomcat
SHUTDOWN_WAIT=30

tomcat_pid() {
  echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
}

start() {
  pid=$(tomcat_pid)
  if [ -n "$pid" ]
  then
    echo "Tomcat is already running (pid: $pid)"
  else
    # Start tomcat
    echo "Starting tomcat"
    /bin/bash $TOMCAT_HOME/bin/startup.sh
  fi
  return 0
}

stop() {
  pid=$(tomcat_pid)
  if [ -n "$pid" ]
  then
    echo "Stopping Tomcat"
    /bin/bash $TOMCAT_HOME/bin/shutdown.sh

    let kwait=$SHUTDOWN_WAIT
    count=0;
    until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
    do
      echo -n -e "\nwaiting for processes to exit";
      sleep 1
      let count=$count+1;
    done

  if [ $count -gt $kwait ]
  then
    echo -n -e "\nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds"
    kill -9 $pid
  fi
  else
    echo "Tomcat is not running"
  fi
  return 0
}

case $1 in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    start
    ;;
  status)
    pid=$(tomcat_pid)
    if [ -n "$pid" ]
      then
      echo "Tomcat is running with pid: $pid"
      else
      echo "Tomcat is not running"
    fi
    ;;
esac
exit 0

Deixe uma resposta