linux:设置tomcat开机自动启动

网上转载

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

 

要启动scim(某一程序),我们首先要知道scim程序在哪里,用locate命令可以找到,scim在/usr/bin/scim这里,其中usr表 示是 属于用户的,bin在linux里表示可以执行的程序。这样,我就可以编写一个脚本程序,把它放到/etc/init.d里,然后在rc5.d里做一个相 应的软链接就可以了。 
这个脚本其实很简单,就两行: 

#!/bin/bash 
/usr/bin/scim 

linux:设置tomcat开机自动启动
    分公司的一台服务器,重新启动后,老是忘记启动tomcat, 开发的同事要求设置为开机自动启动,感觉很简单,但还是花了点时间修改才完成。


新建touch .tomcatd

复制 tomcatd 到 /etc/init.d

 参考了网上的几个帖子,但都不是很适合要求,还是要自己修改一下,大概如下:

[root@appsit init.d]# 
/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
 
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


执行chkconfig tomcat on。 自启动

service tomcatd stop/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 /etc/sysconfig/rc
#source $rc_functions

case "$1" in
    start)
          echo "Starting Apache daemon..."
          /root/nexus-oss-webapp-1.7.2-bundle/nexus-oss-webapp-1.7.2-bundle/nexus-oss-webapp-1.7.2/bin/jsw/linux-x86-32/nexus start
          ;;

    stop)
          echo "Stopping Apache daemon..."
         /root/nexus-oss-webapp-1.7.2-bundle/nexus-oss-webapp-1.7.2-bundle/nexus-oss-webapp-1.7.2/bin/jsw/linux-x86-32/nexus  stop
          ;;

    restart)
          echo "Restarting Apache daemon..."
         /root/nexus-oss-webapp-1.7.2-bundle/nexus-oss-webapp-1.7.2-bundle/nexus-oss-webapp-1.7.2/bin/jsw/linux-x86-32/nexus restart
         ;;
      
    *)
          echo "Usage: $0 {start|stop|restart|status}"
          exit 1
          ;;
esac


6. 关于开机程序的自动启动

系统脚本可以放置在/etc/rc.d/init.d中并建立/etc/rc.d/rc?.d链接,也可以直接放置在/etc/rc.d/rc.local中。

init.d脚本包含完整的start,stop,status,reload等参数,是标准做法,推荐使用。

为特定用户使用的程序(如有的用户需要使用中文输入法而有的不需要)放置在~/中的bash启动脚本中。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值