Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 938
enrico.anello Avatar asked Nov 16 '25 15:11

enrico.anello


2 Answers

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.

like image 65
Bahadir Tasdemir Avatar answered Nov 18 '25 06:11

Bahadir Tasdemir


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.

like image 24
jabal Avatar answered Nov 18 '25 06:11

jabal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!