标签:stop get cas blog down 配置文件 需要 sudo style
rc.local是linux启动init之后执行的脚本。
sudo vi /etc/rc.local
添加如下一行
/home/myuser/software/apache-tomcat-7.0.29/bin/startup.sh(脚本绝对路径)
1、安装 sysv-rc-conf
sudo apt-get install sysv-rc-conf
2、 在 /etc/ini.d/ 目录下,新建 tomcatService
sudo vi /etc/init.d/tomcatControl
TOMCAT_HOME="/home/myuser/software/apache-tomcat-6.0.37/bin" export JAVA_HOME=/home/myuser/software/jdk1.7echo "$ --- 1 = $1" case $1 in startup) sh $TOMCAT_HOME/startup.sh ;; shutdown) sh $TOMCAT_HOME/shutdown.sh ;; restart) sh $TOMCAT_HOME/shutdown.sh sh $TOMCAT_HOME/startup.sh ;; *) sh $TOMCAT_HOME/startup.sh ;; esac exit 0
3、 启动tomcatService
sudo sysv-rc-conf tomcatService on
sudo sysv-rc-conf 查看启动的服务
设置tomcatService 的 2、3、4、5被勾选
如果停止 tomcatService 服务,输入: sudo sysv-rc-conf tomcatService off,则上图2、3、4、5勾选去掉了
1、把下面的代码保存为tomcat文件,并让它成为可执行文件 chmod 755 tomcat.
#!/bin/bash if [ -f /etc/init.d/functions ]; then . /etc/init.d/functions elif [ -f /etc/rc.d/init.d/functions ]; then . /etc/rc.d/init.d/functions else echo -e "\atomcat: unable to locate functions lib. Cannot continue." exit -1 fi RETVAL=$? CATALINA_HOME="/home/myuser/software/apache-tomcat-8.5.20" case "$1" in start) if [ -f $CATALINA_HOME/bin/startup.sh ]; then echo $"Starting Tomcat" $CATALINA_HOME/bin/startup.sh fi ;; stop) if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then echo $"Stopping Tomcat" $CATALINA_HOME/bin/shutdown.sh fi ;; *) echo $"Usage: $0 {start|stop}" exit 1 ;; esac exit $RETVAL
以上为tomcat开机启动的启动脚本代码
2、将tomcat文件拷贝到/etc/init.d/下,并在terminate运行:
chkconfig --add tomcat //这句的意思是添加tomcat服务 chkconfig tomcat on //这句设置tomcat服务自启动 chkconfig --list | grep tomcat //这句查看tomcat的启动状态
3、在tomcat/bin/catalina.sh文件中加入以下语句:
##设置环境变量,若在系统配置文件设置了,这里不需要再配置
export JAVA_HOME=/home/myuser/software/jdk1.7 export CATALINA_HOME=/home/myuser/software/apache-tomcat-8.5.20 export CATALINA_BASE=/home/myuser/software/apache-tomcat-8.5.20 export CATALINA_TMPDIR=/home/myuser/software/apache-tomcat-8.5.20/tmp
启动tomcat: service tomcat start
停止tomcat:tomcat: service tomcat stop
重启tomcat:service tomcat restart
至此tomcat开机启动全部配置完毕,下次linux重启的时候就会自动启动tomcat了
标签:stop get cas blog down 配置文件 需要 sudo style
原文地址:http://www.cnblogs.com/maokun/p/7500470.html