tlinux服务器上的tomcat能不能设置成开机自动启动
1个回答
展开全部
在/etc/init.d/下创建文件tomcatd :
#!/bin/sh
# chkconfig: 345 99 10
# description: Auto-starts tomcat# /etc/init.d/tomcatd
# Tomcat auto-start
# Source function library.
#. /etc/init.d/functions# source networking configuration.
#. /etc/sysconfig/network
RETVAL=0
export JRE_HOME=/usr/java/jdk1.6.0_17/jre
export CATALINA_HOME=/usr/apps/tomcat7
export CATALINA_BASE=/usr/apps/tomcat7
start(){
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
RETVAL=$?
echo " OK"
return $RETVAL
fi
}
stop(){
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
RETVAL=$?
sleep 1
ps -fwwu tomcat | grep apache-tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9
echo " OK"
# [ $RETVAL -eq 0 ] && rm -f /var/lock/...
return $RETVAL
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
echo $"Restaring Tomcat"
$0 stop
sleep 1
$0 start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
[root@root init.d]# chmod u+x tomcatd
[root@root init.d]# chkconfig --add tomcatd
注意:
在tomcat文件的头两行的注释语句中,需要包含chkconfig和description两部分内容(确认不要拼写错误),否则在执行“chkconfig --add tomcatd”时,会出现“tomcatd 服务不支持 chkconfig”的错误提示。
#!/bin/sh
# chkconfig: 345 99 10
# description: Auto-starts tomcat# /etc/init.d/tomcatd
# Tomcat auto-start
# Source function library.
#. /etc/init.d/functions# source networking configuration.
#. /etc/sysconfig/network
RETVAL=0
export JRE_HOME=/usr/java/jdk1.6.0_17/jre
export CATALINA_HOME=/usr/apps/tomcat7
export CATALINA_BASE=/usr/apps/tomcat7
start(){
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
RETVAL=$?
echo " OK"
return $RETVAL
fi
}
stop(){
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
RETVAL=$?
sleep 1
ps -fwwu tomcat | grep apache-tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9
echo " OK"
# [ $RETVAL -eq 0 ] && rm -f /var/lock/...
return $RETVAL
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
echo $"Restaring Tomcat"
$0 stop
sleep 1
$0 start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
[root@root init.d]# chmod u+x tomcatd
[root@root init.d]# chkconfig --add tomcatd
注意:
在tomcat文件的头两行的注释语句中,需要包含chkconfig和description两部分内容(确认不要拼写错误),否则在执行“chkconfig --add tomcatd”时,会出现“tomcatd 服务不支持 chkconfig”的错误提示。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询