[Pkg-awstats-commits] [SCM] awstats Debian packaging branch, master, updated. debian/7.0_dfsg-6-2-gc0482b4
Daniel Pocock
daniel at pocock.com.au
Mon May 21 20:50:09 UTC 2012
The following commit has been merged in the master branch:
commit c0482b4109176e057792884780248c5595e6f3c1
Author: Daniel Pocock <daniel at pocock.com.au>
Date: Mon May 21 22:49:33 2012 +0200
More precise script for post-rotation log scanning (Closes: #590074)
diff --git a/debian/README.Debian b/debian/README.Debian
index 3d70c82..fbd29cd 100644
--- a/debian/README.Debian
+++ b/debian/README.Debian
@@ -58,8 +58,9 @@ By default AWStats scans logfiles each 10 minutes. When Apache (and
other webservers) rotate their logfiles, the last entries in the old
logfile may not have been read by AWStats.
-Make sure to run AWStats right _before_ web logs are rotated. For
-example, insert the following lines in /etc/logrotate.d/apache2:
+Documentation has traditionally advised site administrators
+to run AWStats right _before_ web logs are rotated. For
+example, inserting the following lines in /etc/logrotate.d/apache2:
prerotate
if [ -x /usr/share/awstats/tools/update.sh ]; then
@@ -67,6 +68,42 @@ example, insert the following lines in /etc/logrotate.d/apache2:
fi
endscript
+This is a quick and easy way to capture the data just before rotation,
+but it can be ineffective when there are many logfiles (virtual hosting,
+for example). In such cases, logrotate may take a long time to do
+rotation/compression activity, and more data is logged (and never
+seen by awstats) in the period while such activities take place.
+
+A more precise solution is to run AWStats right _after_ web logs are
+rotated. In this case, the final data to be analyzed is now in
+a rotated file and the LogFile parameter from the
+/etc/awstats/awstats.vhost.conf is pointing at an empty file.
+Fortunately, logrotate can pass the rotated filename (typically
+/var/log/apache2/vhost.com/access.log.1 or similar) to the postrotate script:
+
+/var/log/apache2/*/*.log {
+ weekly
+ missingok
+ rotate 52
+ compress
+ delaycompress
+ notifempty
+ create 644 root adm
+ nosharedscripts
+ postrotate
+ /etc/init.d/apache2 reload > /dev/null
+ /usr/share/awstats/tools/post-logrotate.sh $1
+ endscript
+}
+
+Notice these items in particular:
+ * using the `nosharedscripts' parameter ensures the script is run
+ for each and every log file
+ * apache2 is reloaded _before_ running awstats, to ensure the LogFile
+ is truly finished writing
+ * the `$1' variable is passed to the script, giving it the filename
+ of the rotated logfile
+
Also consider enabling lock files in /etc/awstats/awstats.conf with
EnableLockForUpdate=1 so that only one AWStats update process is
running at a time. This will reduce system resources especially if
diff --git a/debian/awstats.install b/debian/awstats.install
index 9955a98..4326e4b 100644
--- a/debian/awstats.install
+++ b/debian/awstats.install
@@ -13,6 +13,7 @@ wwwroot/cgi-bin/lib/* usr/share/awstats/lib/
wwwroot/cgi-bin/plugins/*.pm usr/share/awstats/plugins/
wwwroot/icon/* usr/share/awstats/icon/
debian/update.sh usr/share/awstats/tools/
+debian/post-logrotate.sh usr/share/awstats/tools/
tools/logresolvemerge.pl usr/share/awstats/tools/
tools/awstats_buildstaticpages.pl usr/share/awstats/tools/
debian/buildstatic.sh usr/share/awstats/tools/
diff --git a/debian/copyright b/debian/copyright
index 503d8f8..31b2214 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -33,6 +33,7 @@ License: GPL
Files: debian/*
Copyright: 2003-2010, Jonas Smedegaard <dr at jones.dk>
2009-2012, Sergey B Kirpichev <skirpichev at gmail.com>
+ 2012, Daniel Pocock <daniel at pocock.com.au>
License: GPL-2+
License: GPL-2
diff --git a/debian/post-logrotate.sh b/debian/post-logrotate.sh
new file mode 100755
index 0000000..bedd683
--- /dev/null
+++ b/debian/post-logrotate.sh
@@ -0,0 +1,82 @@
+#!/bin/bash
+#
+# awstats-logrotate, Copyright 2012 Daniel Pocock <daniel at pocock.com.au>
+# based on
+# update.sh, written by Sergey B Kirpichev <skirpichev at gmail.com>
+#
+# Update an individual vhost postlogrotate
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+DEFAULT=/etc/default/awstats
+AWSTATS=/usr/lib/cgi-bin/awstats.pl
+ERRFILE=`mktemp --tmpdir awstats.XXXXXXXXXX`
+
+trap 'rm -f $ERRFILE' INT QUIT TERM EXIT
+
+[ -f $AWSTATS ] || exit 1
+
+# Set defaults.
+AWSTATS_NICE=10
+[ ! -r "$DEFAULT" ] || . "$DEFAULT"
+
+cd /etc/awstats
+
+VHOST_LOG="$1"
+
+if [ -z "$VHOST_LOG" ];
+then
+ # we must have a filename
+ # sometimes logrotate calls the script with an empty
+ # argument, we just ignore that and exit
+ exit 0
+fi
+
+if [ ! -f "$VHOST_LOG" ];
+then
+ echo "$0 invoked for a log that doesn't exist: $1"
+ exit 1
+fi
+
+VHOST=`echo $VHOST_LOG | cut -d/ -f5`
+FNAME=`echo $VHOST_LOG | cut -d/ -f6`
+
+if [ "$FNAME" != access.log.1 ];
+then
+ echo "Unexpected filename passed to $0: $1"
+ exit 0
+fi
+
+AWSTATS_CONF="/etc/awstats/awstats.${VHOST}.conf"
+
+if [ ! -f "${AWSTATS_CONF}" ];
+then
+ echo "Can't find ${AWSTATS_CONF}"
+ exit 0
+fi
+
+echo "$AWSTATS_CONF"
+
+if ! nice -n $AWSTATS_NICE \
+ ${AWSTATS} \
+ -config=${VHOST} \
+ -LogFile=${FNAME} \
+ -update \
+ >$ERRFILE 2>&1
+then
+ cat $ERRFILE >&2 # an error occurred
+fi
+
--
awstats Debian packaging
More information about the Pkg-awstats-commits
mailing list