Advertisement
Guest User

Tomcat Script

a guest
Oct 31st, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.89 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # tomcat     This shell script takes care of starting and stopping Tomcat
  4. #
  5. # chkconfig: - 80 20
  6. #
  7. ### BEGIN INIT INFO
  8. # Provides: tomcat
  9. # Required-Start: $network $syslog
  10. # Required-Stop: $network $syslog
  11. # Default-Start:
  12. # Default-Stop:
  13. # Short-Description: start and stop tomcat
  14. ### END INIT INFO
  15.  
  16. TOMCAT_USER=liferayapp
  17. TOMCAT_HOME="/opt/liferay/tomcat-7.0.27"
  18. SHUTDOWN_WAIT=45
  19.  
  20. tomcat_pid() {
  21.     echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
  22. }
  23.  
  24. start() {
  25.     pid=$(tomcat_pid)
  26.     if [ -n "$pid" ]
  27.     then
  28.         echo "Tomcat is already running (pid: $pid)"
  29.     else
  30.         # Start tomcat
  31.         echo "Starting tomcat"
  32.         /bin/su - -c "cd $TOMCAT_HOME/bin && $TOMCAT_HOME/bin/startup.sh" $TOMCAT_USER
  33.     fi
  34.     return 0
  35. }
  36.  
  37. stop() {
  38.     pid=$(tomcat_pid)
  39.     if [ -n "$pid" ]
  40.     then
  41.         echo "Stoping Tomcat"
  42.         /bin/su - -c "cd $TOMCAT_HOME/bin && $TOMCAT_HOME/bin/shutdown.sh" $TOMCAT_USER
  43.  
  44.     let kwait=$SHUTDOWN_WAIT
  45.     count=0
  46.     count_by=5
  47.     until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
  48.     do
  49.         echo "Waiting for processes to exit. Timeout before we kill the pid: ${count}/${kwait}"
  50.         sleep $count_by
  51.         let count=$count+$count_by;
  52.     done
  53.  
  54.     if [ $count -gt $kwait ]; then
  55.         echo "Killing processes which didn't stop after $SHUTDOWN_WAIT seconds"
  56.         kill -9 $pid
  57.     fi
  58.     else
  59.         echo "Tomcat is not running"
  60.     fi
  61.  
  62.     return 0
  63. }
  64.  
  65. case $1 in
  66.     start)
  67.         start
  68.         ;;
  69.     stop)
  70.         stop
  71.         ;;
  72.     restart)
  73.         stop
  74.         start
  75.         ;;
  76.     status)
  77.        pid=$(tomcat_pid)
  78.         if [ -n "$pid" ]
  79.         then
  80.            echo "Tomcat is running with pid: $pid"
  81.         else
  82.            echo "Tomcat is not running"
  83.         fi
  84.         ;;
  85. esac
  86.  
  87. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement