2012年6月21日木曜日

【Tomcat7】tomcatの起動ファイルを作成してみた

cd /etc/init.d/
touch tomcat
chmod 755 tomcat
chkconfig --add tomcat
chkconfig --list | grep tomcat
---
tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off
---
vi tomcat
で以下を貼り付けてください
#!/bin/sh
#
# Startup script for Apache Tomcat 7.0.27.0
#
# chkconfig: 2345 85 15
# description: Apache Tomcat Java Servlets and JSP server
# processname: tomcat
# pidfile: /var/run/tomcat.pid
# config: /usr/local/tomcat/conf/server.xml

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

CATALINA_HOME=/usr/local/tomcat
TOMCAT_SCRIPT=$CATALINA_HOME/bin/catalina.sh
TOMCAT_USER=root

if [ ! -f $TOMCAT_SCRIPT ]; then
    exit 0
fi

# See how we were called.
case "$1" in
    start)
        # Start daemons.
        if [ -f /var/lock/subsys/tomcat ] ; then
            echo "Tomcat already started!"
            exit 1
        fi
        echo -n "Starting Tomcat: "
        su -s /bin/bash - $TOMCAT_USER -c "$TOMCAT_SCRIPT start"
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/tomcat
        ;;
    stop)
        # Stop daemons.
        if [ ! -f /var/lock/subsys/tomcat ] ; then
            echo "Tomcat already stopped!"
            exit 1
        fi
        echo -n "Shutting down Tomcat: "
        $TOMCAT_SCRIPT stop
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/tomcat
        ;;
    status)
        status tomcat
        exit $?
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $TOMCAT_PROG {start|stop|status|restart}"
        exit 1
esac

exit 0

太字の箇所の設定は自身の設定に合わせてください
これでserviceコマンドからtomcatを起動することができます

0 件のコメント:

コメントを投稿