tomcat变量环境脚本setclasspath.sh分析
生活随笔
收集整理的這篇文章主要介紹了
tomcat变量环境脚本setclasspath.sh分析
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
????之所以分析setclasspath.sh腳本,是因為catalina.sh腳本會引用到這個腳本,如果不對其進行分析,之后看catalina.sh腳本就會不知道一些變量沒有申明和賦值怎么會跑出來,本篇文章是為下一篇“tomcat運行控制腳本catalina.sh分析”做鋪墊。
#!/bin/sh #?Licensed?to?the?Apache?Software?Foundation?(ASF)?under?one?or?more #?contributor?license?agreements.??See?the?NOTICE?file?distributed?with #?this?work?for?additional?information?regarding?copyright?ownership. #?The?ASF?licenses?this?file?to?You?under?the?Apache?License,?Version?2.0 #?(the?"License");?you?may?not?use?this?file?except?in?compliance?with #?the?License.??You?may?obtain?a?copy?of?the?License?at # #?????http://www.apache.org/licenses/LICENSE-2.0 # #?Unless?required?by?applicable?law?or?agreed?to?in?writing,?software #?distributed?under?the?License?is?distributed?on?an?"AS?IS"?BASIS, #?WITHOUT?WARRANTIES?OR?CONDITIONS?OF?ANY?KIND,?either?express?or?implied. #?See?the?License?for?the?specific?language?governing?permissions?and #?limitations?under?the?License. #?----------------------------------------------------------------------------- #??Set?CLASSPATH?and?Java?options # #??$Id:?setclasspath.sh?795037?2009-07-17?10:52:16Z?markt?$ #?----------------------------------------------------------------------------- #?Make?sure?prerequisite?environment?variables?are?set #因為setclasspath.sh腳本是被catalina.sh調用,所以可以繼承catalina.sh中的變量申明 if?[?-z?"$JAVA_HOME"?-a?-z?"$JRE_HOME"?];?then #判斷用戶有沒有提前做$JAVA_HOME和$JRE_HOME全局變量聲明,如果都沒進行申明#?Bugzilla?37284?(reviewed).if?$darwin;?then#要理解這個判斷,先看下startup.sh和shutdown.sh就會明白#這個是win仿真unix不用管下面兩個語句if?[?-d?"/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home"?];?thenexport?JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home"fielse#其他環(huán)境沒有申明,那么系統自己想辦法找這兩個變量的路徑JAVA_PATH=`which?java?2>/dev/null` #此語句可以把java命令位置找出來if?[?"x$JAVA_PATH"?!=?"x"?];?then #如果能找出java路徑,則可以定位到java命令的路徑,經過作者驗證不是java的裝路徑 #所以通過此處就可以看出,老鳥們?yōu)槭裁炊家约褐付ㄟ@兩個變量了JAVA_PATH=`dirname?$JAVA_PATH?2>/dev/null`JRE_HOME=`dirname?$JAVA_PATH?2>/dev/null`fiif?[?"x$JRE_HOME"?=?"x"?];?then #如果找不到java路徑,那么就看有沒有/usr/bin/java這個執(zhí)行文件,有的話就它了,沒有就算了#?XXX:?Should?we?try?other?locations?if?[?-x?/usr/bin/java?];?thenJRE_HOME=/usrfififiif?[?-z?"$JAVA_HOME"?-a?-z?"$JRE_HOME"?];?then#再驗證一邊,有沒有這兩個變量,沒有不好意思,我不執(zhí)行了,退出#這個exit?1?不但是結束setclasspath.sh,會徹底退出catalina.sh腳本的#對于在腳本中引用腳本的童鞋們,就需要注意了,小心使用exit。?echo?"Neither?the?JAVA_HOME?nor?the?JRE_HOME?environment?variable?is?defined"echo?"At?least?one?of?these?environment?variable?is?needed?to?run?this?program"exit?1fi fi if?[?-z?"$JAVA_HOME"?-a?"$1"?=?"debug"?];?thenecho?"JAVA_HOME?should?point?to?a?JDK?in?order?to?run?in?debug?mode."exit?1 fi if?[?-z?"$JRE_HOME"?];?thenJRE_HOME="$JAVA_HOME" fi #?If?we're?running?under?jdb,?we?need?a?full?jdk. if?[?"$1"?=?"debug"?]?;?thenif?[?"$os400"?=?"true"?];?thenif?[?!?-x?"$JAVA_HOME"/bin/java?-o?!?-x?"$JAVA_HOME"/bin/javac?];?thenecho?"The?JAVA_HOME?environment?variable?is?not?defined?correctly"echo?"This?environment?variable?is?needed?to?run?this?program"echo?"NB:?JAVA_HOME?should?point?to?a?JDK?not?a?JRE"exit?1fielseif?[?!?-x?"$JAVA_HOME"/bin/java?-o?!?-x?"$JAVA_HOME"/bin/jdb?-o?!?-x?"$JAVA_HOME"/bin/javac?];?thenecho?"The?JAVA_HOME?environment?variable?is?not?defined?correctly"echo?"This?environment?variable?is?needed?to?run?this?program"echo?"NB:?JAVA_HOME?should?point?to?a?JDK?not?a?JRE"exit?1fifi fi #上段的代碼都是在確認$JAVA_HOME和$JRE_HOME變量的申明情況及后續(xù)的解決過程 if?[?-z?"$BASEDIR"?];?then #對"$BASEDIR變量的檢查,木有的話就退出echo?"The?BASEDIR?environment?variable?is?not?defined"echo?"This?environment?variable?is?needed?to?run?this?program"exit?1 fi if?[?!?-x?"$BASEDIR"/bin/setclasspath.sh?];?then #確認"$BASEDIR"/bin/setclasspath.sh有木有,木有還是退出if?$os400;?then#?-x?will?Only?work?on?the?os400?if?the?files?are:#?1.?owned?by?the?user#?2.?owned?by?the?PRIMARY?group?of?the?user#?this?will?not?work?if?the?user?belongs?in?secondary?groupseval #eval不清楚嘛意思else?echo?"The?BASEDIR?environment?variable?is?not?defined?correctly"echo?"This?environment?variable?is?needed?to?run?this?program"exit?1fi fi #?Don't?override?the?endorsed?dir?if?the?user?has?set?it?previously #這個是確認JAVA_ENDORSED_DIRS的位置 if?[?-z?"$JAVA_ENDORSED_DIRS"?];?then#?Set?the?default?-Djava.endorsed.dirs?argumentJAVA_ENDORSED_DIRS="$BASEDIR"/endorsed fi #?OSX?hack?to?CLASSPATH JIKESPATH= if?[?`uname?-s`?=?"Darwin"?];?thenOSXHACK="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes"if?[?-d?"$OSXHACK"?];?thenfor?i?in?"$OSXHACK"/*.jar;?doJIKESPATH="$JIKESPATH":"$i"donefi fi #?Set?standard?commands?for?invoking?Java. #這句是響當當的重要,確定了$_RUNJAVA的值 _RUNJAVA="$JRE_HOME"/bin/java if?[?"$os400"?!=?"true"?];?then_RUNJDB="$JAVA_HOME"/bin/jdb fi????通過腳本分析,我們就看到,這個腳本就做了一件事情,檢查各種變量是否賦值,驗證tomcat啟動停止需要涉及到的文件,保障tomcat順利啟動停止。平時我們想要學習shell實例,但是網上卻很少,這是可以轉變下思路,我們linux系統里,充斥著大量的shell實例,雖然不能拿來直接用,但是這些shell的嚴謹代碼結構、邏輯思路、其中的亮點都可以借鑒來使用。
????需要補充的是,當參數選擇catalina.sh stop -force時,catalina.sh是先執(zhí)行catalina.sh stop,以正常的java命令stop掉tomcat,當加入-force時,如果正常關閉不起作用,則執(zhí)行強制關閉。
轉載于:https://blog.51cto.com/vekergu/1622244
總結
以上是生活随笔為你收集整理的tomcat变量环境脚本setclasspath.sh分析的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 信号量(一) 基础知识
- 下一篇: phpcms URL修改