1:首先安裝自啟動管理工具
apt-get install sysv-rc-conf
2:追加Tomcat啟動腳本
比如A服務需要啟動三個Tomcat,則創建Tomcat-A的腳本文件,並放置到/etc/init.d/下,
注意文件權限設置為755。腳本內容如下:
export JAVA_HOME=/usr/lib/jvm/default-java
case $1 in
start)
sh /usr/local/tomcat/A/1/bin/startup.sh
sh /usr/local/tomcat/A/2/bin/startup.sh
sh /usr/local/tomcat/A/3/bin/startup.sh
;;
stop)
sh /usr/local/tomcat/A/1/bin/shutdown.sh
sh /usr/local/tomcat/A/2/bin/shutdown.sh
sh /usr/local/tomcat/A/3/bin/shutdown.sh
;;
restart)
sh /usr/local/tomcat/A/1/bin/shutdown.sh
sh /usr/local/tomcat/A/2/bin/shutdown.sh
sh /usr/local/tomcat/A/3/bin/shutdown.sh
sh /usr/local/tomcat/A/1/bin/startup.sh
sh /usr/local/tomcat/A/2/bin/startup.sh
sh /usr/local/tomcat/A/3/bin/startup.sh
;;
esac
exit 0
3: 執行自啟動命令
sysv-rc-conf tomcat-A on
4: 重新啟動