jetty 隔几天凌晨定时出现404错误(linux /tmp/)

一、问题及原因分析

最近一个老的应用被部署到jetty后定时出现404错误,

老应用的代码比较糟糕,也出过不少问题,本以为是程序问题、

查询负载、线程、dump文件、io都没有明显异常,挺奇怪一直没找到原因

查看了jetty启动是war解压目录/tmp/jetty-0.0.0.0-8100-hrs-web.war-_hrs-any-/webapp

因为在/tmp目录,应该是有问题,linux会清除/tmp目录。

至于/tmp目录多久清除一次,看

 /etc/cron.daily/tmpwatch


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


二、解决方法

问题找到了,那如何指定war解压目录? 在网上找到一份详细说明,如下:

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")



转载于:https://my.oschina.net/greki/blog/109154

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值