第一步:新建?/etc/init.d/tomcat6?文件(文件名就是服务名)。文件里的内容如下:
#!/bin/sh # Comments to support chkconfig on RedHat Linux # chkconfig: 2345 64 36 # description: tomcat6. # Comments to support LSB init script conventions ### BEGIN INIT INFO # Provides: tomcat6 # Required-Start: $local_fs $network $remote_fs # Should-Start: ypbind nscd ldap ntpd xntpd # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start and stop tomcat6 # Description: tomcat6. ### END INIT INFO # source function library. . /etc/rc.d/init.d/functions NAME=tomcat6 DESC="$NAME daemon" CATALINA_HOME=/usr/local/tomcat6 DAEMON=$CATALINA_HOME/bin/startup.sh SCRIPTNAME=/etc/init.d/$NAME export JAVA_HOME=/usr/jdk64 set -e [ -x "$DAEMON" ] || exit 0 do_start() { daemon $DAEMON || echo -n "$NAME already running" } do_stop() { daemon $CATALINA_HOME/bin/shutdown.sh || echo -n "$NAME not running" } case "$1" in start) echo -n "Starting $DESC: $NAME" do_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" do_stop echo "." ;; restart) echo -n "Restarting $DESC: $NAME" do_stop do_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2 exit 3 ;; esac exit 0
?第二步:设置开机启动,在终端执行以下命令:
?
chkconfig --add tomcat6 chkconfig tomcat6 on
?
service tomcat6 start
?
service tomcat6 stop
?
?如果要关闭开机启动,在终端执行以下命令:
chkconfig tomcat6 off
?