linux tomcat 自启动 日志生成问题
1.tomcat服务自启动脚本
# tomcat auto start
#!/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 JDK_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64 (your jdk home)
export CATALINA_HOME=/app/apache-tomcat-7.0.54 (your tomcat home)
export CATALINA_BASE=/app/apache-tomcat-7.0.54 (your tomcat home)
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
2.操作步骤
1).tomcat自启动脚本加入到init.d目录下(注意脚本里面的路径问题)
vi etc/init.d 把以上脚本粘贴进去就好了
2).赋权限:chmod +x /etc/init.d/tomcat
3).执行命令:ln -s /etc/init.d/tomcat /etc/rc2.d/S16Tomcat
4).设置权限:chkconfig --add tomcat
5).命令生效:重启操作系统
6).service tomcat start启动服务,service tomcat stop关闭服务
3.针对java web工程log4j日志写不问题,目前解决方法只是把日志路径写成绝对路径,这样,不管是用服务启动tomcat,还是bin目录下执行startup.sh启动,都可以正常写日志。如果有其它方法,请提供。