#!/bin/sh
#chkconfig: 2345 80 90 #description: tomcatJAVA_HOME=/usr/java/jdk1.7.0_79
PATH=$PATH:/usr/java/jdk1.7.0_79/binTOMCAT_CLI=/home/tomcat7/bin/startup.sh
PIDPORT=`echo $(ps -ef |grep tomcat |grep -w 'tomcat7'|grep -v 'grep'|awk '{print $2}')`case "$1" in
start) if [ -n "$PIDPORT" ] then echo "$PIDPORT tomcat exists, process is already running." else echo "Starting tomcat server..." $TOMCAT_CLI echo "$(ps -ef |grep tomcat |grep -w 'tomcat7'|grep -v 'grep'|awk '{print $2}') is running..." fi ;; stop) if [ ! -n "$PIDPORT" ] then echo "tomcat process is not running." else echo "Stopping tomcat..." kill -9 $PIDPORT sleep 2 if [ `ps -ef |grep tomcat |grep -w 'tomcat7'|grep -v 'grep'|wc -l` -eq 0 ] then echo "tomcat is stop..." fi fi ;; restart|force-reload) ${0} stop ${0} start ;; *) echo "Usage: /etc/init.d/tomcat {start|stop|restart|force-reload}" >&2 exit 1esac