
正文
解压安装的tomcat, 使用chkconfig命令让tomcat 随机启动,tomcat 变为系统服务
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
使用解压安装的tomcat包,命令行输入 service tomcat start 会报 tomcat: unrecognized service 错误提示,意思是说系统没有找到该服务。
好了,我们现在要解决的问题就是这个报错提示,让我们的解压安装版tomcat也可以支持yum安装方式的service tomcat start命令。
在/xxx/tomcat/bin/目录下新建一个tomcatd 文件,编辑内容如下:
#!/bin/bash
#
# tomcatd This shell script takes care of starting and stopping
# standalone tomcat
# chkconfig:
# description: tomcat service
# processname: tomcatd
# config file:
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
if [ "${NETWORKING}" = "no" ]; then
echo "Network is stoped! Please open the network!";
exit
fi #执行用户
executor=tomcat
prog=tomcatd
export JAVA_HOME=/usr/local/jdk7/
export CATALINA_HOME=/usr/local/tomcat/PATH=$PATH:$JAVA_HOME/binSTARTUP="$CATALINA_HOME/bin/catalina.sh start"
SHUTDOWN="$CATALINA_HOME/bin/catalina.sh stop"if [ ! -f $CATALINA_HOME/bin/startup.sh ]; then
echo "CATALINA_HOME for tomcatd not available"
exit
fistart() {
# Start daemons.
echo -e $"Startting tomcat service: "
su - $executor -c "$STARTUP"
status
RETVAL=$?
return $RETVAL
}status() {
ps ax --width= | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' | wc | awk '{print $2}' >/tmp/tomcat_process_count.txt
read line < /tmp/tomcat_process_count.txt
if [ $line -gt ]; then
echo -n "tomcatd ( pid "
ps ax --width= | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
echo ") is running..."
else
echo "Tomcat is stopped"
fi
}stop() {
# Stop daemons.
echo -e $"Stoping tomcat service:"
su - $executor -c "$SHUTDOWN"
RETVAL=$?
return $RETVAL
}# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
sleep
start
RETVAL=$?
;;
status)
status
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit
esac
exit $RETVAL
# chmod a+x /usr/local/tomcat/bin/tomcat //配置可执行权限
# ln -s /usr/local/tomcat/bin/tomcatd /etc/init.d/tomcatd //新建软链接
# chkconfig --level tomcatd on //设置为随机启动
# service tomcatd status //查看启动状态
好了,现在就可以使用可爱的 service 命令了,该死的 /xxx/tomcat/bin/startup.sh (/xxx/tomcat/bin/catalina.sh start) 命令丢一边去吧!
PS:
http://blog.csdn.net/cnfixit/article/details/7030666
http://www.jb51.net/article/34332.htm
http://www.cnblogs.com/panjun-Donet/archive/2010/08/10/1796873.html







