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")
相关文章
相关标签/搜索