Applicable to:
- Plesk 12.5 for Linux
- Plesk 12.0 for Linux
Symptoms
Log rotation settings for a subscription has
Maximum number of log files
parameter set to 5 in Plesk 12.0. The subscription has 5 log files below:
access_ssl_log.processed.1.gz
access_ssl_log.processed.2.gz
access_ssl_log.processed.3.gz
access_ssl_log.processed.4.gz
access_ssl_log.processed.5.gz
After changing the
Maximum number of log files
parameter to 2 via control panel, Plesk rotates the log files. The result is supposed to be as below:
access_ssl_log.processed.1.gz
access_ssl_log.processed.2.gz
However, the following one appears:
access_ssl_log.processed.1.gz
access_ssl_log.processed.2.gz
access_ssl_log.processed.4.gz
access_ssl_log.processed.5.gz
Cause
This behaviour is by design. When
Maximum number of log files
is set to 2, it means log files are rotated two times before being removed. So, logrotate cares only about two files.
Resolution
Older files can be removed either manually, or using a script.The script-based solution can be as follows:
-
Create
cleanup_old_logs.sh
with the following content:# Usage: cleanup_old_logs <folder> <days>
# Removes all log files in the directory older than a certain number of days
FOLDER=$1
N_DAYS=$2
# Validate
if [ "$FOLDER" == "" ] || [ "$N_DAYS" == "" ]
then
echo "Usage: $0 folder number_of_days"
exit 1
fi
if [ ! -d "$FOLDER" ]
then
echo "$FOLDER is not a directory"
exit 2
fi
# Remove
echo "Deleting files in $FOLDER older than $N_DAYS days"
find $FOLDER/* -mtime +$N_DAYS -exec rm {} \; -
Add the following sample entry to
/etc/cron.daily/50plesk-daily
to remove all logs older than 15 days:cleanup_old_logs.sh /var/www/vhosts/<domain_name>/logs/ 15 >/dev/null 2>&1
Comments
0 comments
Please sign in to leave a comment.