实现tomcat做服务器在windows/linux下开机自动运行

 tomcat做服务器在windows下开机自动运行

免安装版本的tomcat,要建立环境变量
要有JAVA_HOME变量就是你是JDK安装目录
要有JRE_HOME变量 就是你的JRE安装目录

新建变量:CATALINA_HOME=你的TOMCAT的目录

在PATH变量最后加上: ;%CATALINA_HOME%/bin

运行 CMD
在 CMD 下运行 service.bat install
然后运行 service.msc 找到Apache Tomcat..... 修改它的运行级别就行了

linux:设置tomcat开机自动启动



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
# Source function library.
. /etc/init.d/functions
# source networking configuration.
. /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
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
}
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
}

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@appsit init.d]# chmod u+x 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

[root@appsit init.d]# service tomcatd stop
 
删除:
[root@appsit init.d]# chkconfig --del tomcatd
 
写得也还不完善,比如tomcat 用户用个变量代替,用 RETVAL=$?来返回最后命令的退出状态,...
这些留待以后完善
也可参考这篇:
http://nio.infor96.com/archives/86

posted @ 2009-04-23 08:45  Defonds  阅读(22)  评论(0编辑  收藏  举报