[vhffs-dev] [2171] bye bye log_apachectl and log_apachelocal configuration directives, please welcome log_postrotate

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 2171
Author:   gradator
Date:     2012-05-03 01:11:57 +0200 (Thu, 03 May 2012)
Log Message:
-----------
bye bye log_apachectl and log_apachelocal configuration directives, please welcome log_postrotate

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Robots/Repository.pm
    trunk/vhffs-api/src/Vhffs/Robots/Web.pm
    trunk/vhffs-backend/conf/vhffs.conf.dist.in

Modified: trunk/vhffs-api/src/Vhffs/Robots/Repository.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Repository.pm	2012-05-02 21:46:41 UTC (rev 2170)
+++ trunk/vhffs-api/src/Vhffs/Robots/Repository.pm	2012-05-02 23:11:57 UTC (rev 2171)
@@ -190,10 +190,6 @@
 		print 'ERROR: cannot find the awstat sample at '.$repoconf->{'log_awstats_sample'}."\n";
 		return undef;
 	}
-	if( $repoconf->{'log_apachelocal'} and not -x $repoconf->{'log_apachectl'} ) {
-		print 'ERROR: cannot find the apache2ctl binary at '.$repoconf->{'log_apachectl'}."\n";
-		return undef;
-	}
 
 	my $repos = Vhffs::Services::Repository::getall( $vhffs, Vhffs::Constants::ACTIVATED );
 	return undef unless defined $repos;
@@ -227,24 +223,29 @@
 			Vhffs::Robots::rotate_log( $downloadserver->{path}.'/'.$_, $repoconf->{'log_incoming_rotations'}, $repoconf->{'log_incoming_compress'} );
 		}
 		closedir( $dirfd );
-
-		# put a file to tell downloadserver to restart (ugly signaling over nfs, I know I know... but IT WORKS, it is secure, and doesn't consume too much CPU !)
-		open( my $filecycle , '>', $downloadserver->{path}.'/cycleok' );
-		close( $filecycle );
 	}
 
-	# Restart locally or wait 180 seconds to be sure all apache are restarted (welcome to the land of pigs)
-	if( $repoconf->{'log_apachelocal'} ) {
-		my $childpid = open( my $output, '-|', $repoconf->{'log_apachectl'}, 'graceful' );
+	# Run the post rotate command
+	if( $repoconf->{'log_postrotate'} ) {
+		my $childpid = open( my $output, '-|', split( /\s+/, $repoconf->{'log_postrotate'} ) );
 		if($childpid) {
 			# read process output and discard
 			while(<$output>) {}
 
 			# wait for the child to finish
 			waitpid( $childpid, 0 );
+
+			# $? contains the return value, The high byte is the exit value of the process. The low 7 bits represent
+			# the number of the signal that killed the process, with the 8th bit indicating whether a core dump occurred.
+			# -- signal is 0 if no signal were sent to kill the process
+			# -- exit value is 0 if the process success
+			# -- core dump bit is 0 if no core dump were written to disk
+			# ---- so, $? contains 0 if everything went fine
+			if( $? ) {
+				print 'ERROR: failed to run the postrotate command line, aborting: '.$repoconf->{'log_postrotate'}."\n";
+				return;
+			}
 		}
-	} else {
-		sleep ( 180 );
 	}
 
 	# Deleting previous logs

Modified: trunk/vhffs-api/src/Vhffs/Robots/Web.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Web.pm	2012-05-02 21:46:41 UTC (rev 2170)
+++ trunk/vhffs-api/src/Vhffs/Robots/Web.pm	2012-05-02 23:11:57 UTC (rev 2171)
@@ -162,10 +162,6 @@
 		print 'ERROR: cannot find the awstat sample at '.$webconf->{'log_awstats_sample'}."\n";
 		return undef;
 	}
-	if( $webconf->{'log_apachelocal'} and not -x $webconf->{'log_apachectl'} ) {
-		print 'ERROR: cannot find the apache2ctl binary at '.$webconf->{'log_apachectl'}."\n";
-		return undef;
-	}
 
 	my $webs = Vhffs::Services::Web::getall( $vhffs, Vhffs::Constants::ACTIVATED );
 	return undef unless defined $webs;
@@ -199,24 +195,29 @@
 			Vhffs::Robots::rotate_log( $webserver->{path}.'/'.$_, $webconf->{'log_incoming_rotations'}, $webconf->{'log_incoming_compress'} );
 		}
 		closedir( $dirfd );
-
-		# put a file to tell webserver to restart (ugly signaling over nfs, I know I know... but IT WORKS, it is secure, and doesn't consume too much CPU !)
-		open( my $filecycle , '>', $webserver->{path}.'/cycleok' );
-		close( $filecycle );
 	}
 
-	# Restart locally or wait 180 seconds to be sure all apache are restarted (welcome to the land of pigs)
-	if( $webconf->{'log_apachelocal'} ) {
-		my $childpid = open( my $output, '-|', $webconf->{'log_apachectl'}, 'graceful' );
+	# Run the post rotate command
+	if( $webconf->{'log_postrotate'} ) {
+		my $childpid = open( my $output, '-|', split( /\s+/, $webconf->{'log_postrotate'} ) );
 		if($childpid) {
 			# read process output and discard
 			while(<$output>) {}
 
 			# wait for the child to finish
 			waitpid( $childpid, 0 );
+
+			# $? contains the return value, The high byte is the exit value of the process. The low 7 bits represent
+			# the number of the signal that killed the process, with the 8th bit indicating whether a core dump occurred.
+			# -- signal is 0 if no signal were sent to kill the process
+			# -- exit value is 0 if the process success
+			# -- core dump bit is 0 if no core dump were written to disk
+			# ---- so, $? contains 0 if everything went fine
+			if( $? ) {
+				print 'ERROR: failed to run the postrotate command line, aborting: '.$webconf->{'log_postrotate'}."\n";
+				return;
+			}
 		}
-	} else {
-		sleep ( 180 );
 	}
 
 	# Deleting previous logs

Modified: trunk/vhffs-backend/conf/vhffs.conf.dist.in
===================================================================
--- trunk/vhffs-backend/conf/vhffs.conf.dist.in	2012-05-02 21:46:41 UTC (rev 2170)
+++ trunk/vhffs-backend/conf/vhffs.conf.dist.in	2012-05-02 23:11:57 UTC (rev 2171)
@@ -229,18 +229,19 @@
 		log_parsed_rotation	=	7
 		log_parsed_compress	=	yes
 
-		# Where to find the awstat sampe file ?
+		# Where to find the awstat sample file ?
 		log_awstats_sample	=	/usr/lib/vhffs/bots/misc/awstats.sample
 
 		# Where to find awstat (caution, you must apply the vhffs patch on)
 		log_awstats		=	/data/logs/web/awstats.pl
 
-		# Is apache running locally or not ? (If not you should use the ugly remote restart of apaches over nfs)
-		log_apachelocal		=	yes
+		# Command to run just after log rotation. The command is not interpreted by sh.
+		#
+		#   Examples:
+		#     apache: /usr/sbin/apache2ctl graceful
+		#     rsyslog: /usr/sbin/invoke-rc.d rsyslog reload
+		log_postrotate		=	/usr/sbin/apache2ctl graceful
 
-		# If it runs locally, where is apache2ctl ?
-		log_apachectl		=	/usr/sbin/apache2ctl
-
 		# URL to the documentation (optional)
 		url_doc			=	http://help.myhoster.net/web
 
@@ -526,18 +527,19 @@
 		log_parsed_rotation	=	7
 		log_parsed_compress	=	yes
 
-		# Where to find the awstat sampe file ?
+		# Where to find the awstat sample file ?
 		log_awstats_sample	=	/usr/lib/vhffs/bots/misc/repository.awstats.sample
 
 		# Where to find awstat (caution, you must apply the vhffs patch on)
 		log_awstats		=	/data/logs/repository/awstats.pl
 
-		# Is apache running locally or not ? (If not you should use the ugly remote restart of apaches over nfs)
-		log_apachelocal		=	yes
+		# Command to run just after log rotation. The command is not interpreted by sh.
+		#
+		#   Examples:
+		#     apache: /usr/sbin/apache2ctl graceful
+		#     rsyslog: /usr/sbin/invoke-rc.d rsyslog reload
+		log_postrotate		=	/usr/sbin/apache2ctl graceful
 
-		# If it runs locally, where is apache2ctl ?
-		log_apachectl		=	/usr/sbin/apache2ctl
-
 		# URL to the documentation (optional)
 		url_doc			=	http://help.myhoster.net/repository
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/