Tomcat Server creating Directories in tmp
Asked Answered
W

1

13

Everytime my embedded virtual tomcat server is ran (spring boot) it creates a directory structure in /tmp/ that is named tomcat.##########################.8080 (I am guessing 8080 is for port or something but the 8080 is consistent). This structure does not take up much space alone but after running the tomcat server often over time this can fill up. Can I prevent this from happening as a configurable option?

An example of the path created can look something like: /tmp/tomcat.1185139485157901.8080/work/Tomcat/localhost/_/ SESSIONS.ser WEB-INF/ etc. etc. etc.

Winthrop answered 9/1, 2015 at 16:42 Comment(1)
I've also noticed that org.apache.tomcat.embed 7.0.52 was leaving a whole lot more data in these temp directories than 8.0.23.Dove
P
8

Unfortunately, both embedded and non-embedded Tomcat needs to have a directory to store temporary files. This is not configurable, however, you can specify the directory in which Tomcat stores these temporary files using setBaseDir.

This should be the first method called public void setBaseDir(String basedir) and if it is not specified in your code it will look for it in

system properties - catalina.base, catalina.home - $HOME/tomcat.$PORT

By knowing the location I recommend writing a simple scheduled script that checks every so often and removes the files under that directory.

Paquito answered 1/7, 2015 at 14:29 Comment(2)
Thanks. This is an old question but I pretty much dealt with it like this. I created a cronjob that checked for the amount of directories in tmp and deleted after a certain threshold.Winthrop
This is a very old question, but generally /tmp should already be cleared by the O/S from time-to-time (see, e.g. serverfault.com/questions/377348/when-does-tmp-get-cleared). So, you should also consider the option of setting the O/S to do this as appropriate (i.e. configure enough space in /tmp. and a cleaning schedule that is frequent enough so it won't get close to filling up)Proudhon

© 2022 - 2024 — McMap. All rights reserved.