Redhat RHEL Tomcat init script (tomcat 는 Liux 에서 스 크 립 트 초기 화 를 자동 으로 시작 합 니 다)
This is my effort to create a nice clean init script to start and stop tomcat for Redhat or RHEL servers.
Two file need to be created to get the init script working
/etc/sysconfig/tomcat
# Environment variables needed for tomcat startup
# I have setup the following links
# /usr/lib/jvm/jdk to point to the present installation of java/jdk
# /opt/tomcat to point to /opt/apache-tomcat-version-no:
PATH=$PATH:/usr/lib/jvm/jdk/bin
JAVA_HOME="/usr/lib/jvm/jdk"
CATALINA_HOME="/opt/tomcat"
CATALINA_BASE="/opt/tomcat"
/etc/init.d/tomcat #!/bin/bash
#
# tomcat
#
# chkconfig: 345 84 15
# description: Start up the Tomcat servlet engine.
# config: /etc/sysconfig/tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid
# Source function library.
. /etc/init.d/functions
# Loading the configuration parameters.
if [ -f /etc/sysconfig/tomcat ]; then
. /etc/sysconfig/tomcat
fi
RETVAL=0
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
logger -s "Starting Tomcat"
/bin/su -l tomcat -c $CATALINA_HOME/bin/startup.sh
RETVAL=$?
[ $RETVAL = 0 ] && touch /var/lock/subsys/tomcat
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
logger -s "Stopping Tomcat"
/bin/su -l tomcat -c $CATALINA_HOME/bin/shutdown.sh
RETVAL=$?
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/tomcat
fi
;;
restart)
$0 stop
$0 start
;;
version)
if [ -f $CATALINA_HOME/bin/version.sh ];
then
logger -s "Display Tomcat Version"
/bin/su -l tomcat -c $CATALINA_HOME/bin/version.sh
RETVAL=$?
fi
;;
*)
echo $"Usage: $0 {start|stop|restart|version}"
exit 1
;;
esac
exit $RETVAL
InstallingOnce the above files have been created issue the command chmod 755 /etc/init.d/tomcat
chkconfig --add tomcat
chkconfig --list tomcat
This will create the necessary links in the /etc/rcn.d directories. Lets now try and start and shutdown of tomcat. service tomcat start
service tomcat stop
service tomcat stop
You can inspect the log file /var/log/messages. You should have log file entries there identifying the user who restarted tomcateg: May 21 14:02:07 server1 bob : Stopping Tomcat
May 21 14:02:09 server1 bob : Starting Tomcat
May 21 14:05:34 server1 bob : Stopping Tomcat
May 21 14:06:14 server1 bob : Stopping Tomcat
May 21 14:06:42 server1 last message repeated 2 times
May 21 14:07:19 server1 bob : Starting Tomcat
BackgroundOk Now finer details. The above script was tested with RHEL 5.5, should work with Centos and Fedora distributions as well. What runlevels does it start at and in which sequence. This is controlled by the below line in /etc/init.d/tomcat # chkconfig: 345 84 15
The above line indicates tomcat should be started up in runlevels 3, 4, and 5. That is what 345 in the above line signifiesFurther more 84 and 15. 84 indicates the sequence number in which it needs to be started up. 15 indicates the sequence number in which it needs to be stopped.The reasoning for choosing 84 for startup sequence. The default start sequence number for Apache is 85. Knowing that I thought it would be most appropriate to give a sequence number of 84 so that tomcat would be started before Apache.Environment Variable UsedPATH=$PATH:/usr/lib/jvm/jdk/binI have /usr/lib/jvm/jdk as a symlink to the java installation folderJAVA_HOME="/usr/lib/jvm/jdk"I have /usr/lib/jvm/jdk as a symlink to the java installation folderCATALINA_HOME="/opt/tomcat"CATALINA_BASE="/opt/tomcat"Assumption is the tomcat tar file for tomcat is extracted to lets say /opt/apache-tomcat-6.0.26. I further have a symlink /opt/tomcat pointing to /opt/apache-tomcat-6.0.26. Hence why I have used /opt/tomcat for the catalina_home and _base environment variables. If you prefer using /usr/local/tomcat feel free to adjust accordinglyThe symlinks allow you to upgrade java and tomcat, and not having to worry about your init scripts or your environment variables.Once you have upgraded java and tomcat all you need to do is update your symlinks to point to the directory where you new version has been installedFuture ImprovementMy wish list Incorporate a mechanism to be able to check the tomcat "status". Possibly incorporate a PID file. Once the PID file has been incorporated, it might be easier to get the status checking added on to the init script.AcknowledgementsThe above was inspired from http://www.raibledesigns.com/tomcat/boot-howto.html Thank you.I have taken the original script from the above link, extended it so it is slightly clearer, and I don't have to manually create the
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.