Clean Out Temporary Files

From WeBWorK_wiki
Jump to navigation Jump to search

The WeBWorK system creates and saves a large number of temporary files, e.g. png images of equations, pdf downloads, etc. If e.g. a png image of an equation already exists, it is faster for WeBWorK to locate and use that image than to create a new one. However, eventually the number of temporary files will become very large (especially for large installations) and over time only a very small number of them will be used. Thus it is a good idea, especially for large installations, to clean out temporary files say every semester. WeBWorK will recreate any temporary file it needs that does not already exist, so there is no harm in removing temporary files.

Removing temporary files when a wwtmp directory is set up

Removing temporary files is most important for large installations and I assume all large installations will set up WeBWorK so that all temporary files are places in a separate directory or partition (see Store WeBWorK's temporary files in a separate directory or partition). In this case, simply so the following:

cd to the wwtmp directory (e.g. cd /var/www/wwtmp)

and as root remove everything in that directory (Before doing this triple check that you are in the wwtmp directory!!!)

sudo rm -rf *

We still have to clean out the depths table in the MySQL database that saves information on the depths of the png images of equations so that they get displayed nicely. Fortunately this is very easy to do. Simply run the command

remove_stale_images --delete --days 0

That command will report

Removed 0 images.

since you have already removes all the temporary images (or on a very active server, it may remove a few that have just been created). The important thing is that it silently cleans out the depths table. In fact, the way remove_stale_images works is that it totally clears out the <depths> table and then adds the necessary information for any images that remain.

NOTE: There is bug in the file PGcore.pm prior to revision 7138 that prevents the temporary directory from being recreated with the correct permissions if the course name contains a dash (i.e. a -. To check the revision number of PGcore.pm, go to the directory containing PGcore.pm (usually /opt/webwork/pg/lib) and run the command svn status -u -v PGcore.pm. If you have an older copy, you can update it with the command svn update PGcore.pm.

Using the remove_stale_images script

If you have a small installation and do not have a wwtmp directory, you can still easily remove all or some of the temporary equations images by running the remove_stale_images command;

remove_stale_images --delete 

will moves all images older than 7 days.

remove_stale_images --delete --days 0

will remove all images.

remove_stale_images --help

will list all options.

How often should temporary files be removed

It would not be a good idea to do this on a daily basis since some of these files, especially the image files, are reused. Recreating them takes a lot more resources. The default for remove_stale_images --delete is to remove images over 7 days old since it assumed students will only be working on problems for 7 days. Running remove_stale_images --delete --days 14 every month would clean out the old image files over 14 days. There is a trade off between removing everything and the extra resources it takes to recreate files that are needed again. Totally cleaning out wwtmp every 3 or 6 months is probably sufficient.