linux自啟動tomcat
阿新 • • 發佈:2018-06-28
rip sys 保存 service AS urn java kcon home
第一種方式
1.修改腳本文件rc.local:vim /etc/rc.d/rc.local
這個腳本是使用者自定的開機啟動程序,可以在裏面添加想在系統啟動之後執行的腳本或者腳本執行命令
2.添加如下內容:
export JAVA_HOME=/usr/local/jdk1.8.0_171
/usr/local/apache-tomcat-7.0.88/bin/startup.sh start
3.esc 退出編輯,:wq 保存修改
4.將rc.local修改為可執行
chmod 777 /etc/rc.d/rc.local
第二種方式:
- vi /etc/init.d/tomcat
#!/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 export JAVA_HOME=/usr/local/jdk1.8.0_171
export JRE_HOME=/usr/local/jdk1.8.0_171/jre
export CATALINA_HOME=/usr/local/apache-tomcat-7.0.88 export CATALINA_BASE=/usr/local/apache-tomcat-7.0.88 start() { if [ -f $CATALINA_HOME/bin/startup.sh ]; then echo $"Starting Tomcat" $CATALINA_HOME/bin/startup.sh RETVAL=$? echo " OK" return$RETVAL fi } stop() { if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then echo $"Stopping Tomcat" $CATALINA_HOME/bin/shutdown.sh RETVAL=$? sleep 1 ps -fwwu root | grep 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
設置權限:
chmod 755 /etc/init.d/tomcat
設定開機啟動服務
- sudo chkconfig tomcat on
啟動,停止tomcat
- service tomcat start #或者 /etc/init.d/tomcat start
- service tomcat stop #或者 /etc/init.d/tomcat stop
linux自啟動tomcat