linux:設定tomcat開機自動啟動

來源:互聯網
上載者:User
 

2008/2/5linux:設定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/networkRETVAL=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=tomcatstart()
{
        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
        ;;
esacexit $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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.