Skip to content

Excessive Nginx reloads triggered by per-website logrotate configurations #845

Backlog

Description

@amirsayonara

CloudPanel version(s) affected

6.0.8

Description

Summary

CloudPanel generates individual logrotate configuration files for each website. Each generated configuration contains a postrotate directive that executes a full Nginx reload:

/etc/init.d/nginx reload &> /dev/null || true

On servers hosting a large number of websites, this causes excessive Nginx reload operations during the daily logrotate process.

Environment

Component Version / Details
CloudPanel 6.0.8
Operating System Debian 12 (Bookworm)
Logrotate 3.21.0
Web Server Nginx
Number of websites 200+
Website-specific logrotate configurations 210

Actual Behavior

On my production server, this issue occurs during the daily logrotate event, at approximately 23:58.

I discovered that 210 website-specific logrotate configuration files contain the same Nginx reload command.

Example of a generated website logrotate configuration:

/home/USER/logs/*/*.log {
    su root root
    daily
    missingok
    rotate 7
    dateext
    dateformat -%Y-%m-%d
    create 0640 USER USER
    postrotate
        /etc/init.d/nginx reload &> /dev/null || true
    endscript
}

With 210 separate configurations, logrotate can trigger hundreds of Nginx reload operations during a single execution cycle.

The consequences on my production VPS have been severe:

  • Extremely high server load during log rotation.
  • Significant CPU and disk I/O consumption.
  • Repeated Nginx worker process restarts.
  • Websites become extremely slow or intermittently inaccessible.
  • In some cases, the server remains severely degraded until early morning or even during business hours.
  • On several occasions, I had to force-restart the VPS through my hosting provider's VNC console because the server became practically unresponsive.

Technical Evidence

I used the following command to identify the affected configurations:

grep -RniE 'nginx|reload|reopen' /etc/logrotate.conf /etc/logrotate.d/

The investigation identified 210 configuration files containing Nginx reload commands.

Interestingly, the default Debian Nginx logrotate configuration already uses a different mechanism:

/var/log/nginx/*.log {
    daily
    missingok
    rotate 14
    compress
    delaycompress
    notifempty
    create 0640 www-data adm
    sharedscripts
    prerotate
        if [ -d /etc/logrotate.d/httpd-prerotate ]; then
            run-parts /etc/logrotate.d/httpd-prerotate
        fi
    endscript
    postrotate
        invoke-rc.d nginx rotate >/dev/null 2>&1
    endscript
}

The Debian Nginx init script implements nginx rotate using SIGUSR1:

rotate_logs() {
    # Rotate log files
    start-stop-daemon --stop --signal USR1 --quiet --pidfile $PID --name $NAME
    return 0
}

This tells Nginx to reopen its log files without performing a full configuration reload.

Expected Behavior

Log rotation should not trigger a full Nginx configuration reload for every individual website.

A more efficient implementation should:

  1. Use Nginx's log-reopening mechanism (SIGUSR1) instead of a full Nginx reload.
  2. Avoid redundant Nginx signals for every individual website configuration.
  3. Ensure the log-reopening operation is executed only once per logrotate cycle, where appropriate.
  4. Preserve existing log ownership, permissions, retention policies, and rotation behavior.

How to reproduce

Steps to Reproduce

  1. Install CloudPanel 6.0.8 on Debian 12 with Nginx.

  2. Create multiple websites through the CloudPanel interface.

  3. CloudPanel automatically generates individual logrotate configuration files under /etc/logrotate.d/.

  4. Inspect one of the generated configuration files:

    cat /etc/logrotate.d/DOMAIN_CONFIG
    

Possible Solution

Proposed Solution

The website logrotate configuration template should be updated to avoid executing a full Nginx reload for every individual website.

Currently, each generated website configuration contains:

postrotate
    /etc/init.d/nginx reload &> /dev/null || true
endscript

I suggest replacing this approach with a centralized log-reopening mechanism using Nginx SIGUSR1, which allows Nginx to reopen its log files without reloading its configuration or recreating worker processes.

The proposed improvements are:

  1. Fix the default CloudPanel logrotate template so newly created websites no longer generate configurations that trigger full Nginx reloads.

  2. Use a centralized log-reopening mechanism so Nginx receives only one SIGUSR1 signal after all relevant website logs have been rotated, rather than receiving hundreds of redundant signals.

  3. Preserve existing logrotate behavior, including daily rotation, retention policies, date-based filenames, file ownership, and permissions.

  4. Provide a migration or regeneration mechanism for existing website logrotate configurations so installations with hundreds of existing websites can be corrected without manually editing every file.

  5. Ensure the fix persists across CloudPanel updates and applies automatically to all newly created websites.

The default Debian Nginx logrotate configuration already demonstrates an appropriate mechanism:

invoke-rc.d nginx rotate >/dev/null 2>&1

This uses the Nginx log-reopening mechanism instead of performing a full configuration reload.

The goal is to ensure that a server hosting hundreds of websites can complete its daily log rotation without triggering hundreds of unnecessary Nginx reload operations.

This would significantly improve CloudPanel scalability and prevent severe server performance degradation on installations hosting a large number of websites.

Additional Context

Additional Context

This issue was discovered on a production VPS hosting more than 200 websites managed through CloudPanel.

The problem was initially difficult to identify because the server performance degradation consistently occurred during the daily logrotate execution, at approximately 23:58.

After investigating the logrotate configurations, I found that 210 website-specific configuration files contained the same Nginx reload command.

This issue is particularly concerning for larger CloudPanel installations because the number of redundant Nginx reload operations increases as more websites are added.

Another important point is that manually correcting the existing logrotate configuration files is not a permanent solution. Newly created websites will receive the same problematic configuration from the CloudPanel template.

I am reporting this issue because it has caused serious production incidents, including prolonged server unresponsiveness and forced VPS restarts through the hosting provider's VNC console.

AI Assistance Disclosure

Please note that this bug report was prepared entirely with the assistance of AI, including the English writing, technical explanation, report structure, and proposed solutions.

I used AI assistance because my English writing skills are limited, and I wanted to communicate the issue clearly and accurately to the CloudPanel development team.

However, the actual problem, production incidents, server environment, command outputs, configuration examples, and technical evidence presented in this report are based on my own VPS and direct investigation.

I apologize if any technical explanation or proposed solution needs further clarification or correction. I would appreciate any feedback or guidance from the CloudPanel development team.

Thank you for maintaining and improving CloudPanel.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions