简体   繁体   中英

Tomcat: Configuring temp folder

I have some webservices running on tomcat that make tasks on a quite big repository. After a few days of run I realized that the tomcat temp folder ($CATALINA_HOME/temp) contains a huge amount of files which may affect the server behavior. Is there any way to configure the temp folder in order to delete files older then a certain amount of time or to disable the temp folder if it's not needed?

If your files' life-times are max "10" minutes then you can use below cron job to periodically clean your temp directory.

Let's say your tomcat's temp directory is "/usr/server/tomcat7/temp" :

Cron job notation:

0 1 * * * find /usr/server/tomcat7/temp -type f -mmin +10 -delete

Code description:

  • 0 1 * * * --> everyday at 1am
  • find /usr/server/tomcat7/temp --> find files in directory "/usr/server/tomcat7/temp"
  • -type f --> only the items whiches' types are "file"
  • -mmin +10 --> only the ones older than "10" minutes
  • -delete --> delete them



For the ones who are new to Cron:

How to set the Cron job (Centos version):

  • If not installed, install with sudo yum install cron
  • Open cron configuration file with crontab -e (this will open the config file with vim )
  • Press a letter to activate vim's "type" mode
  • Paste the "Cron job notation" given above
  • To save and exit, first press "esc" and then type " :x " and press enter
  • You must see " installing new crontab " on the command line

Now you are completely ready to go.

I think disabling the temp dir makes no sense as it is obvoiusly a requirement for the deployed app. File upload is usually implemented using temp files for example.

If I were you I would write a simple shell script for the cleanup and put it into the crontab for example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM