今天想让虚拟机的tomcat7自动启动,发现还是跟以前不一样的。
1. ubuntu使用updae-rc.d来管理启动程序
2. /etc/下面的rc0.d/rc1.d/rc2.d 等这些目录是不同runlever下的启动与关闭程序的链接,由updae-rc.d来管理
3 把tomcat7添加为启动项:
$
sudo cp -r /opt/tomcat7/bin/catalina.sh /etc/init.d
$
sudo mv catalina.sh tomcat7
#增加环境变量:/etc/profile
export JAVA_HOME=/opt/jdk1.7
export JRE_HOME=/opt/jdk1.7/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
export CATALINA_HOME=/opt/tomcat7 #tomcat程序目录
$ sudo update-rc.d tomcat7 defaults
update-rc.d: warning: /etc/init.d/tomcat7 missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
Adding system startup for /etc/init.d/tomcat7 …
/etc/rc0.d/K20tomcat7 -> ../init.d/tomcat7
/etc/rc1.d/K20tomcat7 -> ../init.d/tomcat7
/etc/rc6.d/K20tomcat7 -> ../init.d/tomcat7
/etc/rc2.d/S20tomcat7 -> ../init.d/tomcat7
/etc/rc3.d/S20tomcat7 -> ../init.d/tomcat7
/etc/rc4.d/S20tomcat7 -> ../init.d/tomcat7
/etc/rc5.d/S20tomcat7 -> ../init.d/tomcat7
上面的警告没事,不用管
4. 重启,发现tomcat7没有启动。
然后是一番上网找原因。。。。。。
5. 原来找到了。
查看启动日志:;/var/log/boot.log,发现这个一点关键信息。
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
* Starting automatic crash report generation[ OK ]
* Starting regular background program processing daemon[ OK ]
* Starting deferred execution scheduler[ OK ]
* Starting CPU interrupts balancing daemon[ OK ]
* Stopping save kernel messages[ OK ]
* Starting crash report submission daemon[ OK ]
* Stopping System V runlevel compatibility[ OK ]
先前在/etc/profile文件设置的变量没有生效,可以理解为tomcat7的启动在设置
/etc/profile环境变量之前。
这个时候将
/etc/profile中的环境变量:
export JAVA_HOME=/opt/jdk1.7
export JRE_HOME=/opt/jdk1.7/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
export CATALINA_HOME=/opt/tomcat7 #tomcat程序目录
加到/etc/init.d/tomcat7里。
重启tomcat7就启动了。