Je fais un petit rappel pour le ménage (suppression) du répertoire /tmp/ sous Linux. A la suite de l’étude des logs de error.log de Apache j’ai pu voir que souvent le répertoire /tmp/ était complet.
grep "No space left on device" error.log.201701* | awk '{print $4 " " $3}' | sort -n | uniq -c 85 18 Jan 114 19 Jan
L’idéal est donc de modifier le paramètre de tmpwatch, par défaut on a :
# cat /etc/cron.daily/tmpwatch #! /bin/sh 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_*' 10d /tmp /usr/sbin/tmpwatch "$flags" 30d /var/tmp for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do if [ -d "$d" ]; then /usr/sbin/tmpwatch "$flags" -f 30d "$d" fi done
Par défaut le ménage se fait donc tous les 10 jours, le plus propre est donc de modifier le temps plutôt que d’ajouter une autre tache cron qui ne va pas tenir compte de la date de création du fichier.
Voici le man :
NAME
tmpwatch - removes files which haven't been accessed for a period of time
SYNOPSIS
tmpwatch [-u|-m|-c] [-MUXadfqstvx] [--verbose] [--force] [--all]
[--nodirs] [--nosymlinks] [--test] [--fuser] [--quiet]
[--atime|--mtime|--ctime] [--dirmtime] [--exclude path]
[--exclude-user user] [--exclude-pattern pattern]
time dirs
DESCRIPTION
tmpwatch recursively removes files which haven't been accessed for a given time. Normally, it's used to clean up directories which are used for temporary holding space such as /tmp.
When changing directories, tmpwatch is very sensitive to possible race conditions and will exit with an error if one is detected. It does not follow symbolic links in the directories it's
cleaning (even if a symbolic link is given as its argument), does not switch filesystems (including non-trivial bind mounts), skips lost+found directories owned by the root user, and only
removes empty directories, regular files, and symbolic links.
By default, tmpwatch dates files by their atime (access time), not their mtime (modification time). If files aren't being removed when ls -l implies they should be, use ls -u to examine
their atime to see if that explains the problem.
If the --atime, --ctime or --mtime options are used in combination, the decision about deleting a file will be based on the maximum of these times. The --dirmtime option implies ignoring
atime of directories, even if the --atime option is used.
The time parameter defines the threshold for removing files. If the file has not been accessed for time, the file is removed. The time argument is a number with an optional single-char‐
acter suffix specifying the units: m for minutes, h for hours, d for days. If no suffix is specified, time is in hours.
Following this, one or more directories may be given for tmpwatch to clean up.
Je pense que le mieux est de passer de 10 jours à 10 heures. Pour du site Web (Apache, MySQL, PHP), je pense que c’est largement suffisant 10h dans le répertoire /tmp/. Disons que PHP ne va faire un fichier qui va durer plus que le temps maximum dans php.ini , et une session ne devrait pas durer plus de 10h.