Start Tomcat and Apache at Boot Time

Start Tomcat and Apache at Boot Time
Make sure there is a valid user "tomcat" and that this user has rw permissions in the $CATALINA_HOME/conf and $CATALINA_HOME/logs directories. Also make sure that $JAVA_HOME is set. You will start Tomcat as user "tomcat" to avoid running it as root. The Apache server is started as root because it uses port 80 (lower than 1024) but it spawns processes that run as "nobody".

Save the following scripts as /etc/init.d/tomcat and /etc/init/apache. They will automatically be read and run at boot time. Check the log files if it does not start properly.

Make a link to it from /etc/rc5.d such as:

cd /etc/rc5.d
sudo ln -s ../init.d/tomcat S71tomcat
sudo ln -s ../init.d/apache S72apache

---------------------------- /etc/init.d/tomcat ------------------------
#!/bin/bash
#
# tomcat
#
# chkconfig:
# description: Start up the Tomcat servlet engine.

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


RETVAL=$?
CATALINA_HOME="/usr/apps/apache/tomcat/jakarta-tomcat-4.0.4"

case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
/bin/su tomcat $CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
/bin/su tomcat $CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac

exit $RETVAL
----------------------- end of /etc/init.d/tomcat ----------------------


---------------------------- /etc/init.d/apache ------------------------
#!/bin/bash
#
# apache
#
# chkconfig:
# description: Start up the Apache web server.

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


RETVAL=$?
APACHE_HOME="/usr/apps/apache/apache"

case "$1" in
start)
if [ -f $APACHE_HOME/bin/apachectl ]; then
echo $"Starting Apache"
$APACHE_HOME/bin/apachectl start
fi
;;
stop)
if [ -f $APACHE_HOME/bin/apachectl ]; then
echo $"Stopping Apache"
$APACHE_HOME/bin/apachectl stop
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac

exit $RETVAL
----------------------- end of /etc/init.d/apache ----------------------
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值