Last active
August 29, 2015 14:02
-
-
Save lesstif/4cf7262fd95bc7b95fe1 to your computer and use it in GitHub Desktop.
RHEL/CentOS tomcat running script for user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Source function library. | |
. /etc/init.d/functions | |
## tomcat installation directory | |
PROCESS_NAME=tomcat-caservicename | |
CATALINA_HOME="/home/lesstif/apache-tomcat-7.0.54/" | |
## Path to the pid, runnning info file | |
pidfile=${PIDFILE-${CATALINA_HOME}/.${PROCESS_NAME}.pid}; | |
lockfile=${LOCKFILE-${CATALINA_HOME}/.${PROCESS_NAME}}; | |
RETVAL=0 | |
case "$1" in | |
start) | |
PID=`pidofproc -p ${pidfile} ${PROCESS_NAME}` | |
if [[ (-n ${PID}) && ($PID -gt 0) ]]; then | |
logger -s "${PROCESS_NAME}(pid ${PID}) is already running." | |
exit; | |
fi | |
if [ -f $CATALINA_HOME/bin/startup.sh ]; | |
then | |
logger -s "Starting Tomcat" | |
$CATALINA_HOME/bin/startup.sh -Dprocessname=${PROCESS_NAME} | |
PID=`ps -eaf|grep processname=${PROCESS_NAME}|grep -v grep|awk '{print $2}'` | |
RETVAL=$? | |
[ $RETVAL = 0 ] && touch ${lockfile} | |
[ $RETVAL = 0 ] && echo "${PID}" > ${pidfile} | |
fi | |
;; | |
stop) | |
PID=`pidofproc -p ${pidfile} ${PROCESS_NAME}` | |
## if PID valid run shutdown.sh | |
if [[ -z ${PID} ]];then | |
logger -s "${PROCESS_NAME} is not running." | |
exit; | |
fi | |
if [[ (${PID} -gt 0) && (-f $CATALINA_HOME/bin/shutdown.sh) ]]; | |
then | |
logger -s "Stopping Tomcat" | |
$CATALINA_HOME/bin/shutdown.sh | |
RETVAL=$? | |
[ $RETVAL = 0 ] && rm -f ${lockfile} | |
[ $RETVAL = 0 ] && rm -f ${pidfile} | |
fi | |
;; | |
status) | |
status -p ${pidfile} ${PROCESS_NAME} | |
RETVAL=$? | |
;; | |
restart) | |
$0 stop | |
$0 start | |
;; | |
version) | |
if [ -f $CATALINA_HOME/bin/version.sh ]; | |
then | |
logger -s "Display Tomcat Version" | |
$CATALINA_HOME/bin/version.sh | |
RETVAL=$? | |
fi | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|restart|status|version}" | |
exit 1 | |
;; | |
esac | |
exit $RETVAL | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment