1、問題及緣由分析 java
最近一個老的應用被部署到jetty後定時出現404錯誤, linux
老應用的代碼比較糟糕,也出過很多問題,本覺得是程序問題、 web
查詢負載、線程、dump文件、io都沒有明顯異常,挺奇怪一直沒找到緣由 shell
查看了jetty啓動是war解壓目錄/tmp/jetty-0.0.0.0-8100-hrs-web.war-_hrs-any-/webapp app
由於在/tmp目錄,應該是有問題,linux會清除/tmp目錄。 less
至於/tmp目錄多久清除一次,看 webapp
/etc/cron.daily/tmpwatch
jvm
flags=-umc /usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \ -x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \ -X '/tmp/hsperfdata_*' 720 /tmp /usr/sbin/tmpwatch "$flags" 720 /var/tmp for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do if [ -d "$d" ]; then /usr/sbin/tmpwatch "$flags" -f 720 "$d" fi done
2、解決方法 this
問題找到了,那如何指定war解壓目錄? 在網上找到一份詳細說明,以下: spa
http://docs.codehaus.org/display/JETTY/Temporary+Directories
Jetty itself has no temporary directories, but each web application can be assigned a directory into which the war is unpacked, JSPs compiled on-the-fly etc.
The algorithm for determining a webapp's temporary directory location is as follows:
It is important to note that a temporary directory will have its contents deleted when the webapp is stopped unless either:
Once a tempory directory has been allocated, a File instance for it is set and retrievable as the javax.servlet.context.tempdir attribute of the web application.
最後我選擇了在$(jetty.home)/work下創建一個統一的work目錄,這樣最方便部署,jetty 每臺機子統一安裝就能夠。
另外也能夠直接經過改變JAVA_OPTIONS指定臨時目錄:
jetty.sh
##################################################### # Add jetty properties to Java VM options. ##################################################### JAVA_OPTIONS+=("-Djetty.home=$JETTY_HOME" "-Djava.io.tmpdir=$TMPDIR")