error.log file grown within hours, no disk space left

Discussion in 'Installation/Configuration' started by dmgeurts, Jan 30, 2016.

  1. dmgeurts

    dmgeurts Member

    https://www.howtoforge.com/community/threads/error-log-per-site.66600
    This (^^) post goes into details regarding error.log file rotation and turning it off completely for a site. However I'd rather not turn it off for all sites but I've currently got no other option but to do so to safeguard my servers.
    Problem at hand is a wordpress plugin that runs a backup once a day, it seems there's a problem with this plugin and it causes the error.log file to fill up very quickly. 119GB file anyone? logrotate does help here because the server dies before it gets run the next morning and without any disk space left there's not much logrotate can do anyway.
    I'm currently looking into the following options:
    • Script an alert on log files under /var/www/clients that is larger size X. Not ideal because it requires user intervention. Alternative path to monitor: "/var/log/ispconfig/httpd"
    • Script an alert as above, but add a specific logrotate for the offending file.
    • Modify apache log (only options are on and off). Best done through site options but carries a risk if it needs to be default for all client sites on the server.
    • Change logrotate to run hourly instead of daily.
    (Ubuntu 14.04.3 LTS (Trusty Tahr)) ISPConfig 3.0.5.4p8
     
    Last edited: Jan 30, 2016
  2. dmgeurts

    dmgeurts Member

    This seems to work nicely and can be added to cron at the desired interval.
    Code:
    #!/bin/bash
    logpath="/var/log/ispconfig/httpd/"
    logfile="error.log"
    logsize="10M"
    
    # Find $logfile files larger than $logsize
    files=$(find $logpath -name $logfile -type f -size +$logsize)
    
    # Rotate each found file
    for file in $files; do
        gzip -c $file > $file.1.gz
        cat /dev/null > $file
    done
    Rotation shamelessly taken from cron_daily.php. It follows the same principle and shouldn't interfere with anything as the error.log isn't used for statistics or by ispconfig (AFAIK).
     
    Last edited: Jan 31, 2016

Share This Page