chkconfig로 tomcat 서비스 자동실행 등록
CentOS를 기준으로 작성되었다.
1. 스크립트를 생성한다.
# vi /etc/rc.d/init.d/tomcat
# chkconfig: 345 90 90 # description: init file for tomcat # processname: tomcat # Source function library. . /etc/rc.d/init.d/functions
export JAVA_HOME=/ictdata/dspace/jdk1.7.0_60 export TOMCAT_HOME=/ictdata/dspace/apache/apache-tomcat-7.0.40 export CLASSPATH="."
PRGDIR="$TOMCAT_HOME/bin" EXECUTABLE=startup.sh UNEXECUTABLE=shutdown.sh
# Check that target executable exists if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then echo "Cannot find $PRGDIR/$EXECUTABLE" echo "This file is needed to run this program" exit 1 fi
case "$1" in start) echo -n "Starting Tomcat service: " echo daemon "$PRGDIR"/"$EXECUTABLE" ;; stop) echo -n "Shutting down Tomcat service: " echo daemon "$PRGDIR"/"$UNEXECUTABLE" ;; restart) $0 stop sleep 2 $0 start ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 esac echo exit 0 |
2. 스크립트 권한을 설정한다.
# chmod 755 /etc/rc.d/init.d/tomcat
3. chkconfig로 서비스를 등록한다.
# chkconfig --add tomcat
4. 등록된 서비스를 확인한다.
# chkconfig --list