Access logs are not rotated on Plesk server: Rotation of files with multiple hard links is not allowed



This Plesk Obisidian issue was initially handled by Plesk Support, but the solution wasn’t ideal, as it applied changes to all configuration files, including those that didn’t require it. This resulted in duplicated options being added to the files.

Symptoms

  • Log rotation doesn’t rotate logs, resulting in no compressed .gz files being created.
  • Forcing log rotation for a specific domain results in the following error:
/usr/local/psa/logrotate/sbin/logrotate -v -f /usr/local/psa/etc/logrotate.d/example.com
(...)
considering log /var/www/vhosts/system/example.com/logs/access_log.processed log 
/var/www/vhosts/system/example.com/logs/access_log.processed has multiple (2) hard links. 
Rotation of files with multiple hard links is not allowed for 
/var/www/vhosts/system/example.com/logs/*.processed -- skipping.
(...)

Cause

This issue is due to product bugs, resolved in the following updates:

  • #PPPM-13562: “Fixed the issue where log rotation failed for files with two or more hard links.”
    Fixed in: Plesk Obsidian 18.0.60 (02 April 2024)
  • #PPPM-13473: “Log rotation now works correctly after updating to Plesk Obsidian 18.0.42.”
    Fixed in: Plesk Obsidian 18.0.43 (12 April 2022)
  • #PPPM-13519: “Log rotation now works correctly after updating to Plesk Obsidian 18.0.43 even if /usr/local/psa/etc/logrotate.conf was customized.”
    Fixed in: Plesk Obsidian 18.0.44 (24 May 2022)

Resolution

It is recommended to update your server to the latest Plesk version. For guidance, see: How to install Plesk updates.

Workaround

If updating is not possible, you can try adding the allowhardlink directive in the log rotation configuration files as a workaround.

If updating is not an option, you can manually add the allowhardlink directive to log rotation configuration files as a workaround. Follow these steps:

Before making any changes, it’s recommended to back up the existing configuration files. Run the following command:

cp -r /usr/local/psa/etc/logrotate.d/ /usr/local/psa/etc/logrotate.d_backup/

2. Create and Run a Script to Add the Directive

You can create a script that checks if the allowhardlink directive is missing in each log configuration file, and add it only if necessary.

    1. Open your terminal and create the script:
nano /root/add_allowhardlink.sh
    1. Paste the following script into the file:

#!/bin/bash

# Directory containing the logrotate configuration files
LOGROTATE_DIR="/usr/local/psa/etc/logrotate.d/"

# Loop through each configuration file in the directory
for config_file in "$LOGROTATE_DIR"/*; do
  # Check if the file contains "allowhardlink"
  if ! grep -q "allowhardlink" "$config_file"; then
    # If not, append "allowhardlink" after "copytruncate"
    sed -i '/copytruncate/a allowhardlink' "$config_file"
    echo "Added 'allowhardlink' to $config_file"
  else
    echo "'allowhardlink' already exists in $config_file"
  fi
done
  
    1. Save and exit the file by pressing CTRL + X, then Y, and Enter.
    2. Make the script executable by running:
chmod +x /root/add_allowhardlink.sh
    1. Run the script to apply the changes:
/root/add_allowhardlink.sh

3. Verify the Changes

Once the script has run, you can manually check some configuration files to ensure the allowhardlink directive has been correctly added. Run the following command to check a specific file:

cat /usr/local/psa/etc/logrotate.d/your-config-file

This solution ensures that the allowhardlink directive is only added to files where it’s missing, preventing duplicate entries.

Was this helpful?
Access logs are not rotated on Plesk server: Rotation of files with multiple hard links is not allowed written by UKC average rating 5/5 - 1 user ratings