linux:设置tomcat开机自动启动
2008/2/5
linux:设置tomcat开机自动启动
分公司的一台服务器,重新启动后,老是忘记启动tomcat, 开发的同事要求设置为开机自动启动,感觉很简单,但还是花了点时间修改才完成。
参考了网上的几个帖子,但都不是很适合要求,还是要自己修改一下,大概如下:
[root@appsit init.d]# pwd
/etc/init.d
[root@appsit init.d]# cat tomcatd
#!/bin/sh
# chkconfig: 345 99 10
# description: Auto-starts tomcat
# /etc/init.d/tomcatd
# Tomcat auto-start
/etc/init.d
[root@appsit init.d]# cat 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
. /etc/init.d/functions
# source networking configuration.
. /etc/sysconfig/network
. /etc/sysconfig/network
RETVAL=0
# CATALINA_HOME="/usr/apps/apache/tomcat/jakarta-tomcat-4.0.4"
export JAVA_HOME=/tomcat/java/jdk1.5.0_09
export CATALINA_HOME=/tomcat/tomcat/apache-tomcat-5.5.20
export CATALINA_BASE=/tomcat/tomcat/apache-tomcat-5.5.20
TOMCATUSER=tomcat
export JAVA_HOME=/tomcat/java/jdk1.5.0_09
export CATALINA_HOME=/tomcat/tomcat/apache-tomcat-5.5.20
export CATALINA_BASE=/tomcat/tomcat/apache-tomcat-5.5.20
TOMCATUSER=tomcat
start()
{
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
/bin/su $TOMCATUSER -c $CATALINA_HOME/bin/startup.sh
RETVAL=$?
echo " OK"
return $RETVAL
fi
}
{
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
/bin/su $TOMCATUSER -c $CATALINA_HOME/bin/startup.sh
RETVAL=$?
echo " OK"
return $RETVAL
fi
}
stop()
{
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
/bin/su $TOMCATUSER -c $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
}
{
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
/bin/su $TOMCATUSER -c $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
stop
;;
restart)
echo $"Restaring Tomcat"
$0 stop
sleep 1
$0 start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
[root@appsit init.d]# chmod u+x tomcatd
[root@appsit init.d]# chkconfig --add tomcatd
[root@appsit init.d]# chkconfig --add tomcatd
[root@appsit init.d]# chkconfig --list tomcatd
tomcatd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
tomcatd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[root@appsit init.d]# service tomcatd stop
删除:
[root@appsit init.d]# chkconfig --del tomcatd
写得也还不完善,比如tomcat 用户用个变量代替,用 RETVAL=$?来返回最后命令的退出状态,...
这些留待以后完善