Changeset 1341 for trunk

Show
Ignore:
Timestamp:
09/04/08 23:56:58 (3 months ago)
Author:
scitech
Message:

apache logger problems

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/CHANGELOG

    r1340 r1341  
    11ispCP ω 1.0.0 Changelog 
    22~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3 008-08-16 Daniel Andreca 
     32008-09-05 Daniel Andreca 
     4        - ENGINE: 
     5                * Fixed #1526: apache logger problems 
     6 
     72008-09-03 Daniel Andreca 
    48        - SETUP: 
    59                * RC6 remote database support for upgrade script (thanks Standbye) 
  • trunk/engine/ispcp-apache-logger

    r1339 r1341  
    4646getopts( 'e', \%OPTS ); 
    4747 
    48 if ( !-d $main::cfg{'APACHE_LOG_DIR'}) { 
    49         print STDERR "[ispcp-apache-logger] target directory ".$main::cfg{'APACHE_LOG_DIR'}." does not exist - exiting.\n"; 
    50         exit; 
    51 } 
    52  
    5348my $MAXFILES = "33"; 
    5449if ( $main::cfg{'APACHE_MAX_OPEN_LOG'} ) { 
    5550        $MAXFILES = $main::cfg{'APACHE_MAX_OPEN_LOG'}; 
     51} 
     52 
     53my $MAXLOGFILESIZE = 10485760; # 10Mb 
     54if ( $main::cfg{'APACHE_MAX_LOG_FILE_SIZE'} ) { 
     55        $MAXLOGFILESIZE = $main::cfg{'APACHE_MAX_LOG_FILE_SIZE'}; 
    5656} 
    5757 
     
    6565sub DefaultLogs(); 
    6666sub ErrorLogs(); 
    67  
    68 open (STDERR, ">", "$main::cfg{'LOG_DIR'}/ispcp-apache-logger.stderr") or die ( "Can't redirect STDERR" );; 
    69 STDERR->autoflush(1); 
    70 open (STDOUT, ">", "$main::cfg{'LOG_DIR'}/ispcp-apache-logger.stdout") or die ( "Can't redirect STDOUT" );; 
    71 STDOUT->autoflush(1); 
    72  
    73 if ( $OPTS{'e'} ) { 
     67sub checkFileSize; 
     68 
     69## Creating log files if possible ## 
     70 
     71if ( !-d $main::cfg{'LOG_DIR'} ) { 
     72        print STDERR "[ispcp-apache-logger] target directory ".$main::cfg{'LOG_DIR'}." does not exist - logging on standard streams.\n"; 
     73} else { 
     74        checkFileSize("$main::cfg{'LOG_DIR'}/ispcp-apache-logger.stderr"); 
     75        checkFileSize("$main::cfg{'LOG_DIR'}/ispcp-apache-logger.stdout"); 
     76 
     77        my $res = open (STDERR, ">>", "$main::cfg{'LOG_DIR'}/ispcp-apache-logger.stderr"); 
     78        if (!defined($res)) { 
     79                print STDERR "[ispcp-apache-logger] Can't redirect STDERR\n"; 
     80        } else { 
     81                STDERR->autoflush(1); 
     82        } 
     83        $res = open (STDOUT, ">>", "$main::cfg{'LOG_DIR'}/ispcp-apache-logger.stdout"); 
     84        if (!defined($res)) { 
     85                print STDERR "[ispcp-apache-logger] Can't redirect STDOUT\n"; 
     86        } else { 
     87                STDOUT->autoflush(1); 
     88        } 
     89
     90 
     91if ( !-d $main::cfg{'APACHE_LOG_DIR'}) { 
     92        print STDERR "[ispcp-apache-logger] target directory ".$main::cfg{'APACHE_LOG_DIR'}." does not exist!!!\n"; 
     93} elsif ( !-d $main::cfg{'APACHE_USERS_LOG_DIR'}) { 
     94        print STDERR "[ispcp-apache-logger] target directory ".$main::cfg{'APACHE_USERS_LOG_DIR'}." does not exist!!!.\n"; 
     95} elsif ( $OPTS{'e'} ) { 
    7496        ErrorLogs(); 
    7597} else { 
     
    7799} 
    78100 
     101while ( my $log_line = <STDIN> ){} 
     102 
    79103sub ErrorLogs(){ 
     104        if (defined($main::engine_debug)){ 
     105                print STDOUT "[ispcp-apache-logger] Starting error log proccessing...\n"; 
     106        } 
    80107        while ( my $log_line = <STDIN> ) { 
    81108                my $vhost = 'default'; 
     
    108135        } 
    109136} 
     137 
    110138sub DefaultLogs(){ 
     139        if (defined($main::engine_debug)){ 
     140                print STDOUT "[ispcp-apache-logger] Starting default log proccessing...\n"; 
     141        } 
    111142        while ( my $log_line = <STDIN> ) { 
    112143                my ($vhost, $size, $line) = $log_line =~ m/^(\S+) (\d+|-) (.*)$/s; 
    113                 if(!defined($vhost)){print "Trouble line:\n\t$log_line\n"; return 0;} 
    114                 if(!defined($size)){print "Trouble line:\n\t$log_line\n"; return 0;} 
     144                 
     145                if( !defined($vhost) || !defined($size) ){ 
     146                        print STDERR "[ispcp-apache-logger] Trouble line:\n\t$log_line\n"; 
     147                } 
     148                 
    115149                $vhost = lc($vhost) || "default"; 
    116150                if ( $vhost =~ m#[/\\]# ) { $vhost = "default" } 
     
    156190exit; 
    157191 
     192sub checkFileSize(){ 
     193        my ($file)=@_; 
     194        if( -e $file && ((my $filesize = -s $file) > $MAXLOGFILESIZE)) { 
     195                unlink($file); 
     196        } 
     197} 
     198 
    158199sub checkFileExists(){ 
    159200        my ($local_vhost, $hash, $path, $postpend,$force)=@_; 
    160201        if (!(-e "$path/$local_vhost$postpend") || $force eq '1'){ 
    161                         open ($hash->{$local_vhost}, ">>", "$path/$local_vhost$postpend") or die ( "Can't open $path/$local_vhost$postpend" ); 
     202                my $res = open ($hash->{$local_vhost}, ">>", "$path/$local_vhost$postpend"); 
     203                if (!defined($res)) { 
     204                        print STDERR "[ispcp-apache-logger] Can't open $path/$local_vhost$postpend\n"; 
     205                } else { 
    162206                        $hash->{$local_vhost}->autoflush(1); 
    163         } 
    164         $timestamps{$local_vhost}=time(); 
     207                        $timestamps{$local_vhost}=time(); 
     208                } 
     209        } 
    165210} 
    166211 
     
    170215                        close $key; 
    171216                } 
    172         } 
    173         else { 
     217                if (defined($main::engine_debug)){ 
     218                        print STDOUT "[ispcp-apache-logger] Ending error log proccessing...\n"; 
     219                } 
     220        } else { 
    174221                foreach my $key ( keys %combined_logs ) { 
    175222                        close $key; 
     
    184231                } 
    185232                %access_logs = (); 
    186         } 
    187 
     233                if (defined($main::engine_debug)){ 
     234                        print STDOUT "[ispcp-apache-logger] Ending default log proccessing...\n"; 
     235                } 
     236        } 
     237