sh RHEL / CentOS tomcat7 init.d服务脚本。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh RHEL / CentOS tomcat7 init.d服务脚本。相关的知识,希望对你有一定的参考价值。
#!/bin/bash
#
# tomcat
#
# chkconfig: 345 96 30
# description: Start up the Tomcat servlet engine.
#
# processname: java
# pidfile: /var/run/tomcat.pid
#
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: implementation for Servlet 2.5 and JSP 2.1
## END INIT INFO
# Source function library.
. /etc/init.d/functions
## tomcat installation directory
PROCESS_NAME=apache-tomcat
CATALINA_HOME="/opt/apache-tomcat"
export CATALINA_OPTS="$CATALINA_OPS -server -Xms256m -Xmx1024m -Djava.library.path=/opt/DigitalPersona/lib -Dspring.profiles.active=prod -XX:+HeapDumpOnOutOfMemoryError"
## run as a diffent user
TOMCAT_USER=tomcat
## Path to the pid, runnning info file
pidfile=${PIDFILE-/var/run/${PROCESS_NAME}.pid};
lockfile=${LOCKFILE-/var/lock/${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"
/bin/su -l ${TOMCAT_USER} -c "$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"
/bin/su -l ${TOMCAT_USER} -c "$CATALINA_HOME/bin/shutdown.sh"
RETVAL=$?
[ $RETVAL = 0 ] && rm -f ${lockfile}
[ $RETVAL = 0 ] && rm -f ${pidfile}
fi
sleep 5
ps h ${PID}
if [ $? -eq 0 ]; then
echo "Process did not stop garcefully. Killing it"
tail -1 /opt/apache-tomcat/logs/catalina.out
kill -9 ${PID}
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"
/bin/su -l ${TOMCAT_USER} -c "$CATALINA_HOME/bin/version.sh"
RETVAL=$?
fi
;;
*)
echo $"Usage: $0 {start|stop|restart|status|version}"
exit 1
;;
esac
exit $RETVAL
以上是关于sh RHEL / CentOS tomcat7 init.d服务脚本。的主要内容,如果未能解决你的问题,请参考以下文章
sh 在RHEL / CentOS上安装MySQL Top(mtop)
sh 在rhel / centos 7上编译并安装tmux 2.9a
sh CentOS 7 RHEL 7和fedora上的Selenium,Firefox和Behat
sh 在CentOS / RHEL 7/6/5和Fedora上安装JAVA 8(JDK 8u40)的脚本
sh 在基于yum的系统上列出yum组(已安装,可用或可用的环境)(RHEL Redhat Fedora CentOS等)
centos7设置tomcat7为系统服务的方法