jetty 隔幾天凌晨定時出現404錯誤(linux /tmp/)

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:

  1. Try to use an explicit directory specifically for this webapp:
    • Iff webapp.getTempDirectory() is set, use it. Do NOT delete it on jvm exit.
    • Iff javax.servlet.context.tempdir context attribute is set for this webapp && exists && writeable, then use it. Do NOT delete on jvm exit.
  2. Create a directory based on global settings. The new directory will be called "Jetty_"host""port""context""+virtualhost :
    • Iff $(jetty.home)/work exists create the directory there. Do NOT delete on jvm exit. Do NOT delete contents if dir already exists.
    • Iff WEB-INF/work exists create the directory there. Do NOT delete on jvm exit. Do NOT delete contents if dir already exists.
    • Else create dir in $(java.io.tmpdir). Set delete on jvm exit. Delete contents if dir already exists.

It is important to note that a temporary directory will have its contents deleted when the webapp is stopped unless either:

  • it is called "work"
  • it pre-existed the deployment of the webapp

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")
相關文章
相關標籤/搜索